Created
July 31, 2018 12:58
-
-
Save mortenpi/59a07b747bd17c4daa79840fa50b47c4 to your computer and use it in GitHub Desktop.
at-testset for modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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