Skip to content

Commit

Permalink
Improve reporting of parse errors in test files (#168)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nickrobinson251 authored Aug 5, 2024
1 parent 0ba8d6f commit b800f37
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ReTestItems"
uuid = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"
version = "1.24.0"
version = "1.25.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
5 changes: 5 additions & 0 deletions src/ReTestItems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ end
# i.e. Only `@testitem` and `@testsetup` calls are officially supported.
checked_include(mod, filepath) = Base.include(check_retestitem_macrocall, mod, filepath)
function check_retestitem_macrocall(expr)
if Meta.isexpr(expr, :error)
# If the expression failed to parse, most user-friendly to throw the ParseError,
# rather than report an error about using only `@testitem` or `@testsetup`.
Core.eval(Main, expr)
end
is_retestitem_macrocall(expr) || _throw_not_macrocall(expr)
return expr
end
Expand Down
11 changes: 11 additions & 0 deletions test/integrationtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1141,4 +1141,15 @@ end
@test contains(c1.output, r"SKIP \(3/6\) test item \"skip true\"")
end

@testset "ParseError in test file" begin
file = joinpath(TEST_FILES_DIR, "_parse_error_test.jl")
# the actual error type will be a TaskFailedException, containing a LoadError,
# containing a ParseError, but what we care about is that ultimately the ParseError is
# displayed, so we just check for that.
# Only v1.10+ has the newer Parser with better error messages.
expected = VERSION < v"1.10" ? "syntax:" : ["ParseError:", "Expected `]`"]
@test_throws expected runtests(file; nworkers=0)
@test_throws expected runtests(file; nworkers=1)
end

end # integrationtests.jl testset
5 changes: 5 additions & 0 deletions test/testfiles/_parse_error_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Test case for https://github.com/JuliaTesting/ReTestItems.jl/issues/166
@testitem "file_doesnt_parse" begin
# Note the missing `]`
@test ["a", "b"] == ["a", "b"
end

2 comments on commit b800f37

@nickrobinson251
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/112453

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.25.0 -m "<description of version>" b800f372132581a2f8937f50d5e195c3c298dc3a
git push origin v1.25.0

Please sign in to comment.