diff --git a/.gitignore b/.gitignore index 145cb1a..c8fa77a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store /Manifest.toml /dev/ +/test/*.log diff --git a/src/DaemonMode.jl b/src/DaemonMode.jl index 69ee10e..b9b6189 100644 --- a/src/DaemonMode.jl +++ b/src/DaemonMode.jl @@ -252,7 +252,7 @@ function serverRun(run, sock, shared, print_stack, fname, args, reviser) try reviser() - + if shared redirect_stdout(sock) do redirect_stderr(sock) do @@ -278,8 +278,7 @@ function serverRun(run, sock, shared, print_stack, fname, args, reviser) Base.eval(m, add_params) add_exit = Meta.parse("struct SystemExit <: Exception code::Int32 end; exit(x)=throw(SystemExit(x))") Base.eval(m, add_exit) - # Following code is not needed, the real problem was global ARGS, not - add_redirect = Meta.parse("const stdout=IOBuffer(); println(io, x...) = Base.println(io,x...); println(x)=Base.println(stdout, x); println(x...)=Base.println(stdout, x...); println(io, x...)=Base.println(io, x...); print(x...)=Base.print(stdout, x...); stdout") + add_redirect = Meta.parse("const stdout=IOBuffer(); stdout") out = Base.eval(m, add_redirect) add_redirect_err = Meta.parse("const stderr=IOBuffer(); stderr") err = Base.eval(m, add_redirect_err) @@ -379,7 +378,7 @@ Parse the argument string handling quoted arguments, and escaped quotes correctl # Parameters - shared: string of arguments separated by one or many spaces -""" +""" function parse_arguments(args_str::String) args_out = [] quotes = Set(['\'','"']) @@ -420,7 +419,7 @@ Run the source code of the filename push through the socket. - sock: socket in which is going to receive the dir, the filename, and args to run. - shared: Share the environment between calls. If it is false (default) each run has its own environment, so the variables/functions are not shared. -""" +""" function serverRunFile(sock, shared, print_stack, reviser) fname = "" @@ -444,9 +443,8 @@ function serverRunFile(sock, shared, print_stack, reviser) first_time[] = true cd(dir) do - content = read(fname, String) serverRun(sock, shared, print_stack, fname, args, reviser) do mod - include_string(mod, content) + Base.include(mod, fname) end end catch e diff --git a/test/fileandline.jl b/test/fileandline.jl new file mode 100644 index 0000000..d626798 --- /dev/null +++ b/test/fileandline.jl @@ -0,0 +1,7 @@ +println(@__FILE__) +#= + To truly test @__LINE__ + I add a couple comments + Seven is random +=# +println(@__LINE__) diff --git a/test/runtests.jl b/test/runtests.jl index a4a9466..b96b74e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -90,13 +90,13 @@ end output = String(take!(buffer)) @test output == "1\n2\n" - expr = "begin + expr = "begin x = 2 for i = 1:2 println(i) end end - + " runexpr(expr, output=buffer, port=port) @@ -177,3 +177,10 @@ end output = test_evalfile("eval.jl", port=3010) @test output == "3\n" end + +@testset "testCodeloc" begin + output = test_evalfile("fileandline.jl", port=3011) + l = split(output) + @test endswith(l[1], "/test/fileandline.jl") + @test l[2] == "7" +end