I have a macro, which creates / defines useful constants for the user. I would like to test if the macro created the correct constants and if they function as expected. How can I get something like the following to work?
@testset "Set 1" begin
const A = 1
@test A == 1
end
@testset "Set 2" begin
const A = 2
@test A == 2
end
Edit: depending on the argument, the macro creates different constants.
ERROR: LoadError: syntax: unsupported `const` declaration on local variable around
I thought about wrapping everything in modules. The only problem is that you can’t define modules within testsets. It’ll complain that the module isn’t being defined at toplevel. This means you’d have to define a bunch modules at the beginning and then test them separately, but this quickly becomes unwieldy.
You cannot have const variables below global scope (i.e., inside function definitions, for loops, etc…). If your macro did this then it just generated invalid code, and there is not reason to test the macro, you should discard it.
If you will always call the macro always at top level, and you want to check if its behaviour is working in this situation, then you probably should do as you pointed out: “have to define a bunch modules at the beginning and then test them separately”, or you can call the macro for the global scope of all the tests, or yet you can put the tests inside the modules where you call the macro and in the testsets you just call these test functions.