Skip to content

Commit

Permalink
Add name to test errors
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff committed Jul 17, 2024
1 parent a176c01 commit 1b71ecc
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,66 +30,66 @@ 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

option_tags = Symbol[]

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

push!(option_tags, j[1].val)
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

option_setup = Symbol[]

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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1b71ecc

Please # to comment.