Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
at-testset for modules
using Test
macro moduletestset(ex)
@assert ex.head === :module
modulename = string("module ", ex.args[2])
modulecontents = ex.args[3]
# Add `using Test` as the first expression in the module so that the user could
# use @test etc. without having to have `using Test` all over the place.
pushfirst!(modulecontents.args, :(using Test))
# Just having `using Test` as the very first element in does not work for some
# reason ("not in top-level"), but by adding this LineNumberNode before the first
# expression makes it work somehow.
pushfirst!(modulecontents.args, LineNumberNode(0, "macro moduletestset"))
return quote
@testset $(modulename) begin
$(Expr(:toplevel, esc(ex)))
end
end
end
@moduletestset module Foo
x = 2
@test 2 == x
@test 3 == 4
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.