Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: add option to record passes and enable it for CI #57690

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const DISPLAY_FAILED = (

const FAIL_FAST = Ref{Bool}(false)

const record_passes = OncePerProcess{Bool}() do
return Base.get_bool_env("JULIA_TEST_RECORD_PASSES", false)
end

#-----------------------------------------------------------------------

# Backtrace utility functions
Expand Down Expand Up @@ -1101,7 +1105,11 @@ struct FailFastError <: Exception end
# For a broken result, simply store the result
record(ts::DefaultTestSet, t::Broken) = (push!(ts.results, t); t)
# For a passed result, do not store the result since it uses a lot of memory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# For a passed result, do not store the result since it uses a lot of memory

This comment should be removed/changed to mention that this only happens conditionally with this PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Yeah this is more of an investigation of the performance/test side effect implications currently.

record(ts::DefaultTestSet, t::Pass) = (ts.n_passed += 1; t)
function record(ts::DefaultTestSet, t::Pass)
ts.n_passed += 1
record_passes() && push!(ts.results, t)
return t
end

# For the other result types, immediately print the error message
# but do not terminate. Print a backtrace.
Expand Down
8 changes: 8 additions & 0 deletions test/testdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ using Test, Random

function runtests(name, path, isolate=true; seed=nothing)
old_print_setting = Test.TESTSET_PRINT_ENABLE[]
old_record_passes = get(ENV, "JULIA_TEST_RECORD_PASSES", nothing)
Test.TESTSET_PRINT_ENABLE[] = false
ENV["JULIA_TEST_RECORD_PASSES"] = Base.get_bool_env("CI", false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# remove all hint_handlers, so that errorshow tests are not changed by which packages have been loaded on this worker already
# packages that call register_error_hint should also call this again, and then re-add any hooks they want to test
empty!(Base.Experimental._hint_handlers)
Expand Down Expand Up @@ -97,6 +99,12 @@ function runtests(name, path, isolate=true; seed=nothing)
Test.TESTSET_PRINT_ENABLE[] = old_print_setting
ex isa TestSetException || rethrow()
return Any[ex]
finally
if old_record_passes === nothing
delete!(ENV, "JULIA_TEST_RECORD_PASSES")
else
ENV["JULIA_TEST_RECORD_PASSES"] = old_record_passes
end
end
end

Expand Down