Skip to content

Commit

Permalink
Define constant to reporttests.jl (#112)
Browse files Browse the repository at this point in the history
* Define constant to `reporttests.jl`

* Documentation refactor
  • Loading branch information
omus authored May 22, 2024
1 parent 2294ea3 commit 9e9b0a6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
3 changes: 2 additions & 1 deletion docs/src/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Documentation for `TestReports.jl`'s public interface.

```@docs
TestReports.test
TestReports.RUNNER_SCRIPT
record_testset_property
record_test_property
ReportingTestSet
Expand All @@ -29,7 +30,7 @@ Package internals documentation.
Modules = [TestReports]
Pages = ["runner.jl"]
Public = false
Filter = t -> t != TestReports.test
Filter = t -> !(t in (TestReports.test, TestReports.RUNNER_SCRIPT))
```

### TestSets
Expand Down
13 changes: 13 additions & 0 deletions src/runner.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
"""
The path to the test runner script provided by TestReports. Similar to running
[`TestReports.test`](@ref) but allows the user to specify any test file to run and not just
`test/runtests.jl`.
## Example
```julia
run(`\$(TestReports.RUNNER_SCRIPT) mytests.jl --output=junit-report.xml`)
```
"""
const RUNNER_SCRIPT = abspath(joinpath(@__DIR__(), "..", "bin", "reporttests.jl"))

"Exit code for runner when tests fail"
const TESTS_FAILED = 3

Expand Down
38 changes: 19 additions & 19 deletions test/reporttests_script.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
script_runner = if VERSION >= v"1.7"
joinpath(pkgdir(TestReports), "bin", "reporttests.jl")
@testset "runner script" begin
@test isdefined(TestReports, :RUNNER_SCRIPT)
@test isfile(TestReports.RUNNER_SCRIPT)

if Sys.islinux()
@test uperm(TestReports.RUNNER_SCRIPT) & 0x01 != 0
@test gperm(TestReports.RUNNER_SCRIPT) & 0x01 != 0
@test operm(TestReports.RUNNER_SCRIPT) & 0x01 != 0
end
end

runner_cmd = if Sys.iswindows()
`julia $(TestReports.RUNNER_SCRIPT) --`
else
joinpath(@__DIR__(), "..", "bin", "reporttests.jl")
`$(TestReports.RUNNER_SCRIPT)`
end
script_runner_cmd = Sys.iswindows() ? `julia $script_runner --` : `$script_runner`
test_script = "reporttests_testsets.jl"
reference_suffix = VERSION >= v"1.7" ? "" : "_pre_1_7"

@testset "parse_args" begin
include(script_runner)
include(TestReports.RUNNER_SCRIPT)
@test parse_args([]) === nothing # Shows help
@test_throws ArgumentError parse_args(["--"])

Expand Down Expand Up @@ -45,25 +55,15 @@ reference_suffix = VERSION >= v"1.7" ? "" : "_pre_1_7"
end
end

@testset "executable" begin
@test isfile(script_runner)

if Sys.islinux()
@test uperm(script_runner) & 0x01 != 0
@test gperm(script_runner) & 0x01 != 0
@test operm(script_runner) & 0x01 != 0
end
end

@testset "no specified test script" begin
p = run(ignorestatus(`$script_runner_cmd`))
p = run(ignorestatus(`$runner_cmd`))
@test !success(p)
end

@testset "default output file" begin
reference_file = "references/reporttests_pass$reference_suffix.xml"
output_file = "testlog.xml"
p = run(ignorestatus(`$script_runner_cmd $test_script`))
p = run(ignorestatus(`$runner_cmd $test_script`))
try
@test success(p)
@test isfile(output_file)
Expand All @@ -76,7 +76,7 @@ end
@testset "specify output file" begin
reference_file = "references/reporttests_pass$reference_suffix.xml"
output_file = "junit-report.xml"
p = run(ignorestatus(`$script_runner_cmd $test_script --output=$output_file`))
p = run(ignorestatus(`$runner_cmd $test_script --output=$output_file`))
try
@test success(p)
@test isfile(output_file)
Expand All @@ -89,7 +89,7 @@ end
@testset "test args" begin
reference_file = "references/reporttests_fail$reference_suffix.xml"
output_file = "testlog.xml"
p = run(ignorestatus(`$script_runner_cmd $test_script -- foo -e bar`))
p = run(ignorestatus(`$runner_cmd $test_script -- foo -e bar`))
try
@test !success(p)
@test isfile(output_file)
Expand Down

0 comments on commit 9e9b0a6

Please sign in to comment.