I’m writing a module to test the code of a project I’m working on. I though of using multiple files containing the input data and then combine them to obtain all the test cases I need.
To better explain what I want to do consider the following 3 files:
module Test export @run c = 10.0 macro run(f1, f2) code = quote include(@eval $f1) include(@eval $f2) d = 1.1 a+b+c+d end return :($code) end end
The files a.jl and b.jl define the data (with variable names which are fixed), while Test.jl contains the module for testing. When I use this code I get the following output:
julia> include("Test.jl") Main.Test julia> Test.@run("a.jl", "b.jl") 74.1 julia> Test.a 61 julia> Test.b 2 julia> Test.c 10.0 julia> Test.d ERROR: UndefVarError: d not defined
As expected the variables a and b are added to Test by the includes, while d is available only in the macro.
What I would like to achieve is that after running the macro @run the module stays “clean” from the variables defined in the included files. For example, in the example above I would like a and b to be not define in the module Test after calling @run.
Is this possible?