Skip to content

Commit

Permalink
Merge pull request #68 from gustaphe/scriptfileawareness
Browse files Browse the repository at this point in the history
Make DaemonMode aware of which script file is currently running
  • Loading branch information
dmolina authored Jul 13, 2024
2 parents a1942e2 + e3d3496 commit 132c557
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
/Manifest.toml
/dev/
/test/*.log
12 changes: 5 additions & 7 deletions src/DaemonMode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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(['\'','"'])
Expand Down Expand Up @@ -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 = ""

Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions test/fileandline.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
println(@__FILE__)
#=
To truly test @__LINE__
I add a couple comments
Seven is random
=#
println(@__LINE__)
11 changes: 9 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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], joinpath("test", "fileandline.jl"))
@test l[2] == "7"
end

0 comments on commit 132c557

Please sign in to comment.