Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions src/packagedef.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ function find_test_detail!(node, testitems, testsetups, testerrors)
child_nodes = children(node)

# Check for various syntax errors
if length(child_nodes)==1
push!(testerrors, (name = "Test definition error", message="Your @testitem is missing a name and code block.", range=testitem_range))
if length(child_nodes) == 1
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, (name = "Test definition error", message="Your @testitem must have a first argument that is of type String for the name.", range=testitem_range))
elseif length(child_nodes) > 1 && !(kind(child_nodes[2]) == K"string")
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, (name = node[2,1].val, message="Your @testitem is missing a code block argument.", range=testitem_range))
elseif length(child_nodes) == 2
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, (name = node[2,1].val, 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,79 +30,79 @@ 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, (name = node[2,1].val, 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)
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, (name = node[2,1].val, message="The keyword argument tags cannot be specified more than once.", range=testitem_range))
if option_tags !== nothing
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, (name = node[2,1].val, 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, (name = node[2,1].val, 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, (name = node[2,1].val, 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, (name = node[2,1].val, 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, (name = node[2,1].val, message="The keyword argument setup cannot be specified more than once.", range=testitem_range))
if option_setup !== nothing
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, (name = node[2,1].val, 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, (name = node[2,1].val, 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, (name = node[2,1].val, message="Unknown keyword argument.", range=testitem_range))
push!(testerrors, (name=node[2, 1].val, message="Unknown keyword argument.", range=testitem_range))
return
end
end

if option_tags===nothing
if option_tags === nothing
option_tags = Symbol[]
end

if option_default_imports===nothing
if option_default_imports === nothing
option_default_imports = true
end

if option_setup===nothing
if option_setup === nothing
option_setup = Symbol[]
end

Expand All @@ -114,8 +114,8 @@ function find_test_detail!(node, testitems, testsetups, testerrors)
end

push!(testitems,
(
name=node[2,1].val,
(
name=node[2, 1].val,
range=testitem_range,
code_range=code_range,
option_default_imports=option_default_imports,
Expand All @@ -132,28 +132,28 @@ function find_test_detail!(node, testitems, testsetups, testerrors)
child_nodes = children(node)

# Check for various syntax errors
if length(child_nodes)==1
push!(testerrors, (name = "Test definition error", message="Your $testkind is missing a name and code block.", range=testitem_range))
if length(child_nodes) == 1
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, (name = "Test definition error", message="Your $testkind must have a first argument that is an identifier for the name.", range=testitem_range))
elseif length(child_nodes) > 1 && !(kind(child_nodes[2]) == K"Identifier")
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, (name = child_nodes[2].val, message="Your $testkind is missing a code block argument.", range=testitem_range))
elseif length(child_nodes) == 2
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, (name = child_nodes[2].val, 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, (name = child_nodes[2].val, 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)
elseif !(length(children(i)) == 2)
error("This code path should not be possible.")
else
push!(testerrors, (name = child_nodes[2].val, 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 All @@ -166,9 +166,9 @@ function find_test_detail!(node, testitems, testsetups, testerrors)
(first(our_range(code_block))+5):(last(our_range(code_block))-3)
end

testkind2 = if testkind==Symbol("@testmodule")
testkind2 = if testkind == Symbol("@testmodule")
:module
elseif testkind==Symbol("@testsnippet")
elseif testkind == Symbol("@testsnippet")
:snippet
else
error("Unknown testkind")
Expand Down