Skip to content

Commit 05609c6

Browse files
Skip reference tests on windows (#208)
* Normalize newlines in reference tests * Revert "Normalize newlines in reference tests" This reverts commit 331f8de. * Skip reference tests on windows * fixup! Skip reference tests on windows * fixup paths * fixup! fixup paths * fixup! fixup! fixup paths * fixup! fixup! fixup! fixup paths * Window-proof more tests * fixup! Window-proof more tests * fixup! fixup! Window-proof more tests * fixup! fixup! fixup! Window-proof more tests * fixup! fixup! fixup! fixup! Window-proof more tests * fixup! fixup! fixup! fixup! fixup! Window-proof more tests * fixup! fixup! fixup! fixup! fixup! fixup! Window-proof more tests
1 parent b1077e8 commit 05609c6

File tree

5 files changed

+137
-101
lines changed

5 files changed

+137
-101
lines changed

test/integrationtests.jl

+74-48
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ end
9090

9191
# warn if the path does not exist
9292
dne = joinpath(pkg, "does_not_exist")
93-
dne_msg = "No such path \"$dne\""
93+
dne_msg = "No such path $(repr(dne))"
9494
@test_logs (:warn, dne_msg) match_mode=:any begin
9595
runtests(dne)
9696
end
@@ -104,7 +104,7 @@ end
104104
# warn if the file is not a test file
105105
file = joinpath(pkg, "src", "foo.jl")
106106
@assert isfile(file)
107-
file_msg = "\"$file\" is not a test file"
107+
file_msg = "$(repr(file)) is not a test file"
108108
@test_logs (:warn, file_msg) match_mode=:any begin
109109
runtests(file)
110110
end
@@ -122,7 +122,7 @@ end
122122
# Warn for each invalid path and still run valid ones
123123
test_file = joinpath(pkg, "src", "foo_test.jl")
124124
@assert isfile(test_file)
125-
results = @test_logs (:warn, "No such path \"$dne\"") (:warn, "\"$file\" is not a test file") match_mode=:any begin
125+
results = @test_logs (:warn, "No such path $(repr(dne))") (:warn, "$(repr(file)) is not a test file") match_mode=:any begin
126126
encased_testset() do
127127
runtests(test_file, dne, file)
128128
end
@@ -400,6 +400,7 @@ end
400400
Test.print_test_results(testset)
401401
end
402402
# Test with `contains` rather than `match` so failure print an informative message.
403+
if !Base.Sys.iswindows() # so we can hardcode filepaths to keep the test readable
403404
@test contains(
404405
c.output,
405406
r"""
@@ -427,6 +428,7 @@ end
427428
foo \| 2 2 \s*\d*.\ds
428429
"""
429430
)
431+
end
430432
# verbose_results=false
431433
testset = with_test_package("TestsInSrc.jl") do
432434
runtests(verbose_results=false)
@@ -621,29 +623,38 @@ end
621623
end
622624

623625
@testset "Warn on empty test set -- integration test" begin
626+
fullpath = joinpath(TEST_FILES_DIR, "_empty_testsets_tests.jl")
627+
relfpath = relpath(fullpath, pkgdir(ReTestItems))
624628
@test_logs (:warn, """
625-
Test item "Warn on empty test set -- integration test" at test/testfiles/_empty_testsets_tests.jl:1 contains test sets without tests:
629+
Test item "Warn on empty test set -- integration test" at $relfpath:1 contains test sets without tests:
626630
"Empty testset"
627631
"Inner empty testset"
628632
""") match_mode=:any begin
629-
ReTestItems.runtests(joinpath(TEST_FILES_DIR, "_empty_testsets_tests.jl"))
633+
ReTestItems.runtests(fullpath)
630634
end
631635
end
632636

633637
@testset "log capture for an errored TestSetup" begin
638+
path = joinpath("test", "error_in_setup_test.jl")
634639
c = IOCapture.capture() do
635640
results = with_test_package("DontPass.jl") do
636-
runtests("test/error_in_setup_test.jl"; nworkers=1)
641+
runtests(path; nworkers=1)
637642
end
638643
end
644+
if Base.Sys.iswindows()
645+
@test occursin(
646+
"\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, good test\") at",
647+
replace(c.output, r" on worker \d+" => "")
648+
)
649+
else
639650
@test occursin("""
640-
\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, good test\") at \e[39m\e[1mtest/error_in_setup_test.jl:1\e[22m
651+
\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, good test\") at \e[39m\e[1m$(path):1\e[22m
641652
SetupThatErrors msg
642653
""",
643654
replace(c.output, r" on worker \d+" => ""))
644655

645656
@test occursin("""
646-
\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, bad test\") at \e[39m\e[1mtest/error_in_setup_test.jl:1\e[22m
657+
\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, bad test\") at \e[39m\e[1m$(path):1\e[22m
647658
SetupThatErrors msg
648659
""",
649660
replace(c.output, r" on worker \d+" => ""))
@@ -652,19 +663,20 @@ end
652663
# that we don't accumulate logs from all previous failed attempts (which would get
653664
# really spammy if the test setup is used by 100 test items).
654665
@test !occursin("""
655-
\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, good test\") at \e[39m\e[1mtest/error_in_setup_test.jl:1\e[22m
666+
\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, good test\") at \e[39m\e[1m$(path):1\e[22m
656667
SetupThatErrors msg
657668
SetupThatErrors msg
658669
""",
659670
replace(c.output, r" on worker \d+" => "")
660671
)
661672
@test !occursin("""
662-
\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, bad test\") at \e[39m\e[1mtest/error_in_setup_test.jl:1\e[22m
673+
\e[36m\e[1mCaptured logs\e[22m\e[39m for test setup \"SetupThatErrors\" (dependency of \"bad setup, bad test\") at \e[39m\e[1m$(path):1\e[22m
663674
SetupThatErrors msg
664675
SetupThatErrors msg
665676
""",
666677
replace(c.output, r" on worker \d+" => "")
667678
)
679+
end # iswindows
668680
end
669681

670682
@testset "test crashing testitem" begin
@@ -685,7 +697,8 @@ end
685697
# Test the error is as expected
686698
err = only(non_passes(results))
687699
@test err.test_type == :nontest_error
688-
@test err.value == string(ErrorException("Worker process aborted (signal=6) running test item \"Abort\" (run=1)"))
700+
sig = Base.Sys.iswindows() ? 0 : 6
701+
@test err.value == string(ErrorException("Worker process aborted (signal=$(sig)) running test item \"Abort\" (run=1)"))
689702
end
690703

691704
@testset "test retrying failing testitem" begin
@@ -908,7 +921,12 @@ end
908921

909922
@testset "Duplicate names in same file throws" begin
910923
file = joinpath(TEST_FILES_DIR, "_duplicate_names_test.jl")
911-
expected_msg = Regex("Duplicate test item name `dup` in file `test/testfiles/_duplicate_names_test.jl` at line 4")
924+
relfpath = relpath(file, pkgdir(ReTestItems))
925+
expected_msg = if Base.Sys.iswindows()
926+
Regex("Duplicate test item name `dup` in file")
927+
else
928+
Regex("Duplicate test item name `dup` in file `$(relfpath)` at line 4")
929+
end
912930
@test_throws expected_msg runtests(file; nworkers=0)
913931
@test_throws expected_msg runtests(file; nworkers=1)
914932
end
@@ -967,51 +985,58 @@ end
967985
return logs
968986
end
969987

970-
@testset "timeout_profile_wait=0 means no CPU profile" begin
971-
capture_timeout_profile(0) do logs
972-
@test !occursin("Information request received", logs)
988+
if Base.Sys.iswindows()
989+
@testset "Windows not supported" begin
990+
capture_timeout_profile(1) do logs
991+
@test occursin("CPU profiles on timeout is not supported on Windows, ignoring `timeout_profile_wait`", logs)
992+
end
993+
end
994+
else
995+
@testset "timeout_profile_wait=0 means no CPU profile" begin
996+
capture_timeout_profile(0) do logs
997+
@test !occursin("Information request received", logs)
998+
end
973999
end
974-
end
975-
9761000

977-
default_peektime = Profile.get_peek_duration()
978-
@testset "non-zero timeout_profile_wait means we collect a CPU profile" begin
979-
capture_timeout_profile(5) do logs
980-
@test occursin("Information request received. A stacktrace will print followed by a $(default_peektime) second profile", logs)
981-
@test count(r"pthread_cond_wait|__psych_cvwait", logs) > 0 # the stacktrace was printed (will fail on Windows)
982-
@test occursin("Profile collected.", logs)
1001+
default_peektime = Profile.get_peek_duration()
1002+
@testset "non-zero timeout_profile_wait means we collect a CPU profile" begin
1003+
capture_timeout_profile(5) do logs
1004+
@test occursin("Information request received. A stacktrace will print followed by a $(default_peektime) second profile", logs)
1005+
@test count(r"pthread_cond_wait|__psych_cvwait", logs) > 0 # the stacktrace was printed (will fail on Windows)
1006+
@test occursin("Profile collected.", logs)
1007+
end
9831008
end
984-
end
9851009

9861010

987-
@testset "`set_peek_duration` is respected in `worker_init_expr`" begin
988-
capture_timeout_profile(5, worker_init_expr=:(using Profile; Profile.set_peek_duration($default_peektime + 1.0))) do logs
989-
@test occursin("Information request received. A stacktrace will print followed by a $(default_peektime + 1.0) second profile", logs)
990-
@test count(r"pthread_cond_wait|__psych_cvwait", logs) > 0 # the stacktrace was printed (will fail on Windows)
991-
@test occursin("Profile collected.", logs)
1011+
@testset "`set_peek_duration` is respected in `worker_init_expr`" begin
1012+
capture_timeout_profile(5, worker_init_expr=:(using Profile; Profile.set_peek_duration($default_peektime + 1.0))) do logs
1013+
@test occursin("Information request received. A stacktrace will print followed by a $(default_peektime + 1.0) second profile", logs)
1014+
@test count(r"pthread_cond_wait|__psych_cvwait", logs) > 0 # the stacktrace was printed (will fail on Windows)
1015+
@test occursin("Profile collected.", logs)
1016+
end
9921017
end
993-
end
9941018

9951019

996-
# The RETESTITEMS_TIMEOUT_PROFILE_WAIT environment variable can be used to set the timeout_profile_wait.
997-
@testset "RETESTITEMS_TIMEOUT_PROFILE_WAIT environment variable" begin
998-
withenv("RETESTITEMS_TIMEOUT_PROFILE_WAIT" => "5") do
999-
capture_timeout_profile(nothing) do logs
1000-
@test occursin("Information request received", logs)
1001-
@test count(r"pthread_cond_wait|__psych_cvwait", logs) > 0 # the stacktrace was printed (will fail on Windows)
1002-
@test occursin("Profile collected.", logs)
1020+
# The RETESTITEMS_TIMEOUT_PROFILE_WAIT environment variable can be used to set the timeout_profile_wait.
1021+
@testset "RETESTITEMS_TIMEOUT_PROFILE_WAIT environment variable" begin
1022+
withenv("RETESTITEMS_TIMEOUT_PROFILE_WAIT" => "5") do
1023+
capture_timeout_profile(nothing) do logs
1024+
@test occursin("Information request received", logs)
1025+
@test count(r"pthread_cond_wait|__psych_cvwait", logs) > 0 # the stacktrace was printed (will fail on Windows)
1026+
@test occursin("Profile collected.", logs)
1027+
end
10031028
end
10041029
end
1005-
end
10061030

1007-
# The profile is collected for each worker thread.
1008-
@testset "CPU profile with $(repr(log_capture))" for log_capture in (:eager, :batched)
1009-
capture_timeout_profile(5, nworker_threads=VERSION >= v"1.9" ? "3,2" : "3", logs=log_capture) do logs
1010-
@test occursin("Information request received", logs)
1011-
@test count(r"pthread_cond_wait|__psych_cvwait", logs) > 0 # the stacktrace was printed (will fail on Windows)
1012-
@test occursin("Profile collected.", logs)
1031+
# The profile is collected for each worker thread.
1032+
@testset "CPU profile with $(repr(log_capture))" for log_capture in (:eager, :batched)
1033+
capture_timeout_profile(5, nworker_threads=VERSION >= v"1.9" ? "3,2" : "3", logs=log_capture) do logs
1034+
@test occursin("Information request received", logs)
1035+
@test count(r"pthread_cond_wait|__psych_cvwait", logs) > 0 # the stacktrace was printed (will fail on Windows)
1036+
@test occursin("Profile collected.", logs)
1037+
end
10131038
end
1014-
end
1039+
end # iswindows
10151040
end
10161041

10171042
@testset "worker always crashes immediately" begin
@@ -1334,7 +1359,8 @@ end
13341359
:crash => "_failfast_crash_tests.jl",
13351360
)
13361361
testitem_timeout = 5
1337-
file = joinpath(TEST_FILES_DIR, filename)
1362+
fullpath = joinpath(TEST_FILES_DIR, filename)
1363+
relfpath = relpath(fullpath, pkgdir(ReTestItems))
13381364
# For 0 or 1 workers, we expect to fail on the second testitem out of 3.
13391365
# If running with 3 workers, then all 3 testitems will be running in parallel,
13401366
# so we expect to see all 3 testitems run, even though one fails.
@@ -1346,7 +1372,7 @@ end
13461372
continue
13471373
end
13481374
c = IOCapture.capture() do
1349-
encased_testset(() -> runtests(file; nworkers, testitem_timeout, retries=1, failfast=true))
1375+
encased_testset(() -> runtests(fullpath; nworkers, testitem_timeout, retries=1, failfast=true))
13501376
end
13511377
results = c.value
13521378
if nworkers == 3
@@ -1359,7 +1385,7 @@ end
13591385
# @show c.output
13601386
@test contains(c.output, "Retrying") # check retries are happening
13611387
@test count(r"\[ Fail Fast:", c.output) == 2
1362-
msg = "[ Fail Fast: Test item \"bad\" at test/testfiles/$filename:4 failed. Cancelling tests."
1388+
msg = "[ Fail Fast: Test item \"bad\" at $relfpath:4 failed. Cancelling tests."
13631389
@test contains(c.output, msg)
13641390
if nworkers == 3
13651391
@test contains(c.output, "[ Fail Fast: 3/3 test items were run.")

test/internals.jl

+27-24
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ end # `include_testfiles!` testset
169169
@testset "report_empty_testsets" begin
170170
using ReTestItems: TestItem, report_empty_testsets, PerfStats, ScheduledForEvaluation
171171
using Test: DefaultTestSet, Fail, Error
172-
ti = TestItem(Ref(42), "Dummy TestItem", "DummyID", [], false, [], 0, nothing, false, nothing, "source/path", 42, ".", nothing)
172+
path = joinpath("source", "path")
173+
ti = TestItem(Ref(42), "Dummy TestItem", "DummyID", [], false, [], 0, nothing, false, nothing, path, 42, ".", nothing)
173174

174175
ts = DefaultTestSet("Empty testset")
175176
report_empty_testsets(ti, ts)
@@ -179,7 +180,7 @@ end # `include_testfiles!` testset
179180
push!(ts.results, DefaultTestSet("Empty testset"))
180181
# Only the inner testset is considered empty
181182
@test_logs (:warn, """
182-
Test item "Dummy TestItem" at source/path:42 contains test sets without tests:
183+
Test item "Dummy TestItem" at $(path):42 contains test sets without tests:
183184
"Empty testset"
184185
""") begin
185186
report_empty_testsets(ti, ts)
@@ -190,7 +191,7 @@ end # `include_testfiles!` testset
190191
push!(ts.results, DefaultTestSet("Empty testset 2"))
191192
# Only the inner testsets are considered empty
192193
@test_logs (:warn, """
193-
Test item "Dummy TestItem" at source/path:42 contains test sets without tests:
194+
Test item "Dummy TestItem" at $(path):42 contains test sets without tests:
194195
"Empty testset 1"
195196
"Empty testset 2"
196197
""") begin
@@ -277,8 +278,8 @@ end
277278
@assert !ReTestItems.is_test_file(nontest_file)
278279
@assert !ReTestItems.is_testsetup_file(nontest_file)
279280
@test _validated_paths((nontest_file,), false) == ()
280-
@test_logs (:warn, "\"$nontest_file\" is not a test file") _validated_paths((nontest_file,), false)
281-
@test_throws ArgumentError("\"$nontest_file\" is not a test file") _validated_paths((nontest_file,), true)
281+
@test_logs (:warn, "$(repr(nontest_file)) is not a test file") _validated_paths((nontest_file,), false)
282+
@test_throws ArgumentError("$(repr(nontest_file)) is not a test file") _validated_paths((nontest_file,), true)
282283
end
283284

284285
@testset "skiptestitem" begin
@@ -383,25 +384,27 @@ end
383384

384385
@testset "nestedrelpath" begin
385386
using ReTestItems: nestedrelpath
386-
@assert Base.Filesystem.path_separator == "/"
387-
path = "test/dir/foo_test.jl"
388-
@test nestedrelpath(path, "test") == relpath(path, "test") == "dir/foo_test.jl"
389-
@test nestedrelpath(path, "test/") == relpath(path, "test/") == "dir/foo_test.jl"
390-
@test nestedrelpath(path, "test/dir") == relpath(path, "test/dir") == "foo_test.jl"
391-
@test nestedrelpath(path, "test/dir/") == relpath(path, "test/dir/") == "foo_test.jl"
392-
@test nestedrelpath(path, "test/dir/foo_test.jl") == relpath(path, "test/dir/foo_test.jl") == "."
393-
394-
# unlike `relpath`: if `startdir` is not a prefix of `path`, the assumption is violated,
395-
# and `path` is just returned as-is
396-
@test nestedrelpath(path, "test/dir/foo_") == "test/dir/foo_test.jl"
397-
@test nestedrelpath(path, "test/dir/other") == "test/dir/foo_test.jl"
398-
@test nestedrelpath(path, "test/dir/other/bar_test.jl") == "test/dir/foo_test.jl"
399-
400-
# leading '/' doesn't get ignored or stripped
401-
@test nestedrelpath("/a/b/c", "/a/b") == "c"
402-
@test nestedrelpath("/a/b/c", "a/b") == "/a/b/c"
403-
@test nestedrelpath("/a/b", "/a/b/c") == "/a/b"
404-
@test nestedrelpath("/a/b", "c") == "/a/b"
387+
if !Base.Sys.iswindows()
388+
@assert Base.Filesystem.path_separator == "/"
389+
path = "test/dir/foo_test.jl"
390+
@test nestedrelpath(path, "test") == relpath(path, "test") == "dir/foo_test.jl"
391+
@test nestedrelpath(path, "test/") == relpath(path, "test/") == "dir/foo_test.jl"
392+
@test nestedrelpath(path, "test/dir") == relpath(path, "test/dir") == "foo_test.jl"
393+
@test nestedrelpath(path, "test/dir/") == relpath(path, "test/dir/") == "foo_test.jl"
394+
@test nestedrelpath(path, "test/dir/foo_test.jl") == relpath(path, "test/dir/foo_test.jl") == "."
395+
396+
# unlike `relpath`: if `startdir` is not a prefix of `path`, the assumption is violated,
397+
# and `path` is just returned as-is
398+
@test nestedrelpath(path, "test/dir/foo_") == "test/dir/foo_test.jl"
399+
@test nestedrelpath(path, "test/dir/other") == "test/dir/foo_test.jl"
400+
@test nestedrelpath(path, "test/dir/other/bar_test.jl") == "test/dir/foo_test.jl"
401+
402+
# leading '/' doesn't get ignored or stripped
403+
@test nestedrelpath("/a/b/c", "/a/b") == "c"
404+
@test nestedrelpath("/a/b/c", "a/b") == "/a/b/c"
405+
@test nestedrelpath("/a/b", "/a/b/c") == "/a/b"
406+
@test nestedrelpath("/a/b", "c") == "/a/b"
407+
end
405408
end
406409

407410
end # internals.jl testset

test/macros.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ end
230230
@testset "testitem `_id` keyword" begin
231231
# Should default to `repr(hash(name, hash(file)))` where `file` is relative to the root
232232
# of the project being tested.
233-
file = "test/macros.jl" # this file
233+
file = joinpath("test, macros.jl") # this file
234234
# set the source to be this file, so that the test is valid even when run in the REPL.
235235
ti1 = @testitem "one" _run=false _source=LineNumberNode(@__LINE__, file) begin; end;
236236
@test ti1.id == repr(hash("one", hash(file)))
@@ -247,7 +247,7 @@ end
247247
expected = VERSION < v"1.8" ? LoadError : "must be passed a string"
248248
@test_throws expected (@eval @testitem("four", _id=1, _run=false, begin end))
249249
# Cannot detect type of `id` at macro-expansion time, so throws run-time error
250-
expected = VERSION < v"1.8" ? MethodError : "MethodError: Cannot `convert` an object of type UInt64 to an object of type String"
250+
expected = VERSION < v"1.8" ? MethodError : "MethodError: Cannot `convert` an object of type $(UInt) to an object of type String"
251251
@test_throws expected (@eval @testitem("five", _id=hash("five"), _run=false, begin end))
252252
end
253253

test/runtests.jl

+11-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ end
2020
include("macros.jl")
2121
include("integrationtests.jl")
2222
include("log_capture.jl")
23-
# junit_xml reference tests are very sensitive to changes in text output which is not
24-
# stable across minor Julia versions, i.e. we expect these to fail on upcoming Julia
25-
# releases so we may as well skip them (so PkgEval doesn't always fail for us).
26-
if isempty(VERSION.prerelease)
27-
include("junit_xml.jl")
23+
@static if Base.Sys.iswindows()
24+
# https://github.com/JuliaTesting/ReTestItems.jl/issues/209
25+
@warn "Skipping JUnit XML reference tests on windows"
2826
else
29-
@warn "Skipping JUnit XML reference tests on unrelease Julia version" VERSION
27+
# junit_xml reference tests are very sensitive to changes in text output which is not
28+
# stable across minor Julia versions, i.e. we expect these to fail on upcoming Julia
29+
# releases so we may as well skip them (so PkgEval doesn't always fail for us).
30+
if !isempty(VERSION.prerelease)
31+
@warn "Skipping JUnit XML reference tests on unrelease Julia version" VERSION
32+
else
33+
include("junit_xml.jl")
34+
end
3035
end
3136
end
3237

0 commit comments

Comments
 (0)