Unit testing macros with gensyms

What are the best practices for unit testing compicated macros that use gensym, preferably with Base.Test? Since gensym always returns different results, I cannot simply test for expression equality.

Is there a way to “reset” the global gensym counter, similarly to srand for random numbers? Or should I use some other trick?

All the libraries I looked at that use macros heavily rely on testing the application of the macro, which is a bit indirect, so I could not find an example.

1 Like

Figured out a partial solution: using MacroTools.@match,

  1. make a template of what the result should look like,
  2. with wildcards (a_ etc) in place for gensyms,
  3. test each for more or less looking like a gensym (is a Symbol, starts with ##).
  4. test them for equality when applicable (eg a1_, a2_ should be = if they are the same var)