Skip to content

Commit

Permalink
fix #46, providing eval and include for safe (context=nothing)
Browse files Browse the repository at this point in the history
  • Loading branch information
wookay committed Oct 1, 2021
1 parent caf433c commit 0b13515
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ keywords = ["distributed", "test"]
license = "MIT"
desc = "some useful steps in tests"
authors = ["WooKyoung Noh <[email protected]>"]
version = "0.2.19"
version = "0.2.20"

[deps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Expand Down
32 changes: 17 additions & 15 deletions src/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ function jive_briefing(io::IO, numbering::String, subpath::String, verbose::Bool
end
end

function include_test_file(context::Union{Nothing,Module}, filepath::String)
if isnothing(context)
m = Module()
# https://github.com/JuliaLang/julia/issues/40189#issuecomment-871250226
Core.eval(m, quote
eval(x) = Core.eval($m, x)
include(x) = Base.include($m, x)
end)
Base.include(m, filepath)
else
Base.include(context, filepath)
end
end

# code from https://github.com/JuliaLang/julia/blob/master/stdlib/Test/src/Test.jl
module CodeFromStdlibTest

Expand Down Expand Up @@ -324,21 +338,15 @@ end # module Jive.CodeFromStdlibTest
module CodeFromJuliaTest

using ..CodeFromStdlibTest: @jive_testset, get_test_counts
using ..Jive: slash_to_path_separator, report, jive_briefing
using ..Jive: slash_to_path_separator, report, jive_briefing, include_test_file
using Test.Random # RandomDevice
using Distributed # @everywhere remotecall_fetch

function runner(worker::Int, idx::Int, num_tests::Int, subpath::String, filepath::String, context::Union{Nothing,Module}, verbose::Bool)
numbering = string(idx, /, num_tests)
buf = IOBuffer()
io = IOContext(buf, :color => have_color())
(ts, cumulative_compile_time, elapsed_time) = @jive_testset io numbering subpath verbose " (worker: $worker)" "" begin
if isnothing(context)
Base.include(Module(), filepath)
else
Base.include(context, filepath)
end
end
(ts, cumulative_compile_time, elapsed_time) = @jive_testset io numbering subpath verbose " (worker: $worker)" "" include_test_file(context, filepath)
(ts, cumulative_compile_time, elapsed_time, buf)
end

Expand Down Expand Up @@ -492,13 +500,7 @@ function normal_run(dir::String, tests::Vector{String}, start_idx::Int, stop_on_
end
filepath = normpath(dir, slash_to_path_separator(subpath))
numbering = string(idx, /, length(tests))
(ts, cumulative_compile_time, elapsed_time) = @jive_testset io numbering subpath verbose "" "" begin
if isnothing(context)
Base.include(Module(), filepath)
else
Base.include(context, filepath)
end
end
(ts, cumulative_compile_time, elapsed_time) = @jive_testset io numbering subpath verbose "" "" include_test_file(context, filepath)
total_cumulative_compile_time += cumulative_compile_time
total_elapsed_time += elapsed_time
passes, fails, errors, broken, c_passes, c_fails, c_errors, c_broken = get_test_counts(ts)
Expand Down
5 changes: 5 additions & 0 deletions test/jive/runtests/context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ runtests(@__DIR__, targets=["target1"], enable_distributed=false, context=Main,
runtests(@__DIR__, targets=["target1"], enable_distributed=false, context=@__MODULE__, verbose=false)
@test context_variable == 3

include("target1.jl")
@test context_variable == eval(:(3+2))


module test_jive_runtests_context
Expand All @@ -38,6 +40,9 @@ runtests(@__DIR__, targets=["target1"], enable_distributed=false, context=Main,
runtests(@__DIR__, targets=["target1"], enable_distributed=false, context=@__MODULE__, verbose=false)
@test context_variable == 3

include("target1.jl")
@test context_variable == eval(:(3+2))

runtests(@__DIR__, targets=["target2"], enable_distributed=false, verbose=false)

end # module test_jive_runtests_context

0 comments on commit 0b13515

Please sign in to comment.