From 1b71eccb05ad46d270142822990b1aefcc222087 Mon Sep 17 00:00:00 2001 From: David Anthoff Date: Wed, 17 Jul 2024 23:58:46 +0200 Subject: [PATCH] Add name to test errors --- src/packagedef.jl | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/packagedef.jl b/src/packagedef.jl index 4029b28..579bae0 100644 --- a/src/packagedef.jl +++ b/src/packagedef.jl @@ -11,16 +11,16 @@ function find_test_detail!(node, testitems, testsetups, testerrors) # Check for various syntax errors if length(child_nodes)==1 - push!(testerrors, (message="Your @testitem is missing a name and code block.", range=testitem_range)) + push!(testerrors, (name = "Test definition error", message="Your @testitem is missing a name and code block.", range=testitem_range)) return elseif length(child_nodes)>1 && !(kind(child_nodes[2]) == K"string") - push!(testerrors, (message="Your @testitem must have a first argument that is of type String for the name.", range=testitem_range)) + push!(testerrors, (name = "Test definition error", message="Your @testitem must have a first argument that is of type String for the name.", range=testitem_range)) return elseif length(child_nodes)==2 - push!(testerrors, (message="Your @testitem is missing a code block argument.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="Your @testitem is missing a code block argument.", range=testitem_range)) return elseif !(kind(child_nodes[end]) == K"block") - push!(testerrors, (message="The final argument of a @testitem must be a begin end block.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The final argument of a @testitem must be a begin end block.", range=testitem_range)) return else option_tags = nothing @@ -30,18 +30,18 @@ function find_test_detail!(node, testitems, testsetups, testerrors) # Now check our keyword args for i in child_nodes[3:end-1] if kind(i) != K"=" - push!(testerrors, (message="The arguments to a @testitem must be in keyword format.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The arguments to a @testitem must be in keyword format.", range=testitem_range)) return elseif !(length(children(i))==2) error("This code path should not be possible.") elseif kind(i[1]) == K"Identifier" && i[1].val == :tags if option_tags!==nothing - push!(testerrors, (message="The keyword argument tags cannot be specified more than once.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The keyword argument tags cannot be specified more than once.", range=testitem_range)) return end if kind(i[2]) != K"vect" - push!(testerrors, (message="The keyword argument tags only accepts a vector of symbols.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The keyword argument tags only accepts a vector of symbols.", range=testitem_range)) return end @@ -49,7 +49,7 @@ function find_test_detail!(node, testitems, testsetups, testerrors) for j in children(i[2]) if kind(j) != K"quote" || length(children(j)) != 1 || kind(j[1]) != K"Identifier" - push!(testerrors, (message="The keyword argument tags only accepts a vector of symbols.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The keyword argument tags only accepts a vector of symbols.", range=testitem_range)) return end @@ -57,24 +57,24 @@ function find_test_detail!(node, testitems, testsetups, testerrors) end elseif kind(i[1]) == K"Identifier" && i[1].val == :default_imports if option_default_imports !== nothing - push!(testerrors, (message="The keyword argument default_imports cannot be specified more than once.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The keyword argument default_imports cannot be specified more than once.", range=testitem_range)) return end if !(i[2].val in (true, false)) - push!(testerrors, (message="The keyword argument default_imports only accepts bool values.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The keyword argument default_imports only accepts bool values.", range=testitem_range)) return end option_default_imports = i[2].val elseif kind(i[1]) == K"Identifier" && i[1].val == :setup if option_setup!==nothing - push!(testerrors, (message="The keyword argument setup cannot be specified more than once.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The keyword argument setup cannot be specified more than once.", range=testitem_range)) return end if kind(i[2]) != K"vect" - push!(testerrors, (message="The keyword argument `setup` only accepts a vector of `@testsetup module` names.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The keyword argument `setup` only accepts a vector of `@testsetup module` names.", range=testitem_range)) return end @@ -82,14 +82,14 @@ function find_test_detail!(node, testitems, testsetups, testerrors) for j in children(i[2]) if kind(j) != K"Identifier" - push!(testerrors, (message="The keyword argument `setup` only accepts a vector of `@testsetup module` names.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="The keyword argument `setup` only accepts a vector of `@testsetup module` names.", range=testitem_range)) return end push!(option_setup, j.val) end else - push!(testerrors, (message="Unknown keyword argument.", range=testitem_range)) + push!(testerrors, (name = node[2,1].val, message="Unknown keyword argument.", range=testitem_range)) return end end @@ -133,27 +133,27 @@ function find_test_detail!(node, testitems, testsetups, testerrors) # Check for various syntax errors if length(child_nodes)==1 - push!(testerrors, (message="Your $testkind is missing a name and code block.", range=testitem_range)) + push!(testerrors, (name = "Test definition error", message="Your $testkind is missing a name and code block.", range=testitem_range)) return elseif length(child_nodes)>1 && !(kind(child_nodes[2]) == K"Identifier") - push!(testerrors, (message="Your $testkind must have a first argument that is an identifier for the name.", range=testitem_range)) + push!(testerrors, (name = "Test definition error", message="Your $testkind must have a first argument that is an identifier for the name.", range=testitem_range)) return elseif length(child_nodes)==2 - push!(testerrors, (message="Your $testkind is missing a code block argument.", range=testitem_range)) + push!(testerrors, (name = child_nodes[2].val, message="Your $testkind is missing a code block argument.", range=testitem_range)) return elseif !(kind(child_nodes[end]) == K"block") - push!(testerrors, (message="The final argument of a $testkind must be a begin end block.", range=testitem_range)) + push!(testerrors, (name = child_nodes[2].val, message="The final argument of a $testkind must be a begin end block.", range=testitem_range)) return else # Now check our keyword args for i in child_nodes[3:end-1] if kind(i) != K"=" - push!(testerrors, (message="The arguments to a $testkind must be in keyword format.", range=testitem_range)) + push!(testerrors, (name = child_nodes[2].val, message="The arguments to a $testkind must be in keyword format.", range=testitem_range)) return elseif !(length(children(i))==2) error("This code path should not be possible.") else - push!(testerrors, (message="Unknown keyword argument.", range=testitem_range)) + push!(testerrors, (name = child_nodes[2].val, message="Unknown keyword argument.", range=testitem_range)) return end end