Skip to content

Commit b800f37

Browse files
Improve reporting of parse errors in test files (#168)
* Improve reporting of parse errors in test files * fixup! Improve reporting of parse errors in test files * fixup! fixup! Improve reporting of parse errors in test files * Bump version
1 parent 0ba8d6f commit b800f37

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ReTestItems"
22
uuid = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
3-
version = "1.24.0"
3+
version = "1.25.0"
44

55
[deps]
66
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

src/ReTestItems.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ end
653653
# i.e. Only `@testitem` and `@testsetup` calls are officially supported.
654654
checked_include(mod, filepath) = Base.include(check_retestitem_macrocall, mod, filepath)
655655
function check_retestitem_macrocall(expr)
656+
if Meta.isexpr(expr, :error)
657+
# If the expression failed to parse, most user-friendly to throw the ParseError,
658+
# rather than report an error about using only `@testitem` or `@testsetup`.
659+
Core.eval(Main, expr)
660+
end
656661
is_retestitem_macrocall(expr) || _throw_not_macrocall(expr)
657662
return expr
658663
end

test/integrationtests.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,4 +1141,15 @@ end
11411141
@test contains(c1.output, r"SKIP \(3/6\) test item \"skip true\"")
11421142
end
11431143

1144+
@testset "ParseError in test file" begin
1145+
file = joinpath(TEST_FILES_DIR, "_parse_error_test.jl")
1146+
# the actual error type will be a TaskFailedException, containing a LoadError,
1147+
# containing a ParseError, but what we care about is that ultimately the ParseError is
1148+
# displayed, so we just check for that.
1149+
# Only v1.10+ has the newer Parser with better error messages.
1150+
expected = VERSION < v"1.10" ? "syntax:" : ["ParseError:", "Expected `]`"]
1151+
@test_throws expected runtests(file; nworkers=0)
1152+
@test_throws expected runtests(file; nworkers=1)
1153+
end
1154+
11441155
end # integrationtests.jl testset
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Test case for https://github.com/JuliaTesting/ReTestItems.jl/issues/166
2+
@testitem "file_doesnt_parse" begin
3+
# Note the missing `]`
4+
@test ["a", "b"] == ["a", "b"
5+
end

0 commit comments

Comments
 (0)