# Unit testing macros with gensyms

**URL:** <https://discourse.julialang.org/t/unit-testing-macros-with-gensyms/1284>\
**Category:** Internals & Design\
**Tags:** question\
**Created:** [January 4, 2017, 3:44pm UTC](https://discourse.julialang.org/t/unit-testing-macros-with-gensyms/1284 "2017-01-04T15:44:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 4, 2017, 3:44pm UTC](https://discourse.julialang.org/t/unit-testing-macros-with-gensyms/1284/1 "2017-01-04T15:44:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 4, 2017, 9:01pm UTC](https://discourse.julialang.org/t/unit-testing-macros-with-gensyms/1284/2 "2017-01-04T21:01:56Z")

</div>

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)
