Skip to content

Instantly share code, notes, and snippets.

@paulo-ferraz-oliveira
Created August 23, 2023 18:40
Show Gist options
  • Save paulo-ferraz-oliveira/c809fbda9beba9711fdecd1a9e2ac031 to your computer and use it in GitHub Desktop.
Save paulo-ferraz-oliveira/c809fbda9beba9711fdecd1a9e2ac031 to your computer and use it in GitHub Desktop.
Filling your Erlang/OTP's Common Test suites' `:all/0` automatically

Common Test trickery

We can define an Erlang/OTP Common Test suite with

-module(...).

-compile([export_all, nowarn_export_all]).

all() ->
    [Fun || {Fun, 1} <- ?MODULE:module_info(exports),
            re:run(atom_to_binary(Fun), <<"^test_">>) =/= nomatch].
            
...

and then have our tests start with test_ to have them all (and only them) exported.

Something similar could be done for test groups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment