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

Add should_test_module hook #3

Merged
merged 2 commits into from
Aug 1, 2021
Merged
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: 10 additions & 0 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,17 @@ function prepare_local(m::Module)
LoadAllPackages.loadall(projectfile(m))
end

function should_test(m::Module)
f = try
m.should_test_module
catch
return true
end
return f()::Bool
end

function runtests(m::Module; recursive::Bool = true)
should_test(m) || return
@debug "Testing module: `$m`"
@testset "$f" for f in test_functions(m)
@debug "Testing function: `$m.$f`"
Expand Down
15 changes: 13 additions & 2 deletions test/TestFunctionRunnerTests/src/test_mockedtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,22 @@ function test_runtests_fail()
@test runtests_process(SCRIPT; env = env) ⊜ false
end

function test_should_test_module()
env = cleanenv()
env["SampleMockedTests.TestShouldTest.test"] = "false"
@test runtests_process(SCRIPT; env = env) ⊜ false
env["SampleMockedTests.TestShouldTest.should_test_module"] = "false"
@test runtests_process(SCRIPT; env = env) ⊜ true
end

function test_discovery()
@test test_functions(SampleMockedTests) ==
[SampleMockedTests.test, SampleMockedTests.test_2]
@test test_modules(SampleMockedTests) ==
[SampleMockedTests.TestNested, SampleMockedTests.TestNested2]
@test test_modules(SampleMockedTests) == [
SampleMockedTests.TestNested,
SampleMockedTests.TestNested2,
SampleMockedTests.TestShouldTest,
]
end

end # module
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ using ...Utils: @defmock
end # module TestNested3
end # module TestNested2

module TestShouldTest
using ..Utils: @defmock
should_test_module() =
lowercase(get(ENV, "$(@__MODULE__).should_test_module", "true")) == "true"
@defmock test
end # module TestShouldTest

module NotATestModule
test() = error("this should not be executed")
end # module NotATestModule
Expand Down