Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we want a shorthand for registering tests? #454

Open
haved opened this issue Apr 25, 2024 · 3 comments
Open

Do we want a shorthand for registering tests? #454

haved opened this issue Apr 25, 2024 · 3 comments

Comments

@haved
Copy link
Collaborator

haved commented Apr 25, 2024

When registering tests individually, it currently looks like this:

static int
TestPair()
{
  // Actual test in here
  return 0;
}

JLM_UNIT_TEST_REGISTER("jlm/util/TestHashSet-TestPair", TestPair)

This leads to a lot of repeated "jlm/util/TestHashSet" and "TestPair", and clang format likes to put blank lines between the test and register macro.

I was wondering if we would like to add macros to enable something like

// Once per file
JLM_UNIT_TEST_FILE("jlm/util/TestHashSet")

JLM_UNIT_TEST(TestPair)
{
  // Actual test in here
  return 0;
}

JLM_UNIT_TEST(TestUniquePointer)
{
  // More test here
  return 0;
}

A possible implementation we could add to the bottom of test-registry.hpp would be:

#define JLM_UNIT_TEST_FILE(filename)                    \
  static const std::string & GetJlmUnitTestFileName()   \
  {                                                     \
    static std::string JlmUnitTestFileName{ filename }; \
    return JlmUnitTestFileName;                         \
  }

#define JLM_UNIT_TEST(name)                                          \
  static int name();                                                 \
  JLM_UNIT_TEST_REGISTER(GetJlmUnitTestFileName() + "-" #name, name) \
  static int name()

To avoid static constructor ordering conflicts, the filename must be placed in a function (saying static const std::string X = filename; as a global variable does not work).

@phate
Copy link
Owner

phate commented Apr 26, 2024

I am generally in favor of this suggestion. However, @caleridas planned to change the unit test setup up to google test. I am not sure whether this change will help or be detrimental for this. How far along are you with it @caleridas ? Should we do this?

@haved
Copy link
Collaborator Author

haved commented Apr 26, 2024

Ah, in that case Google tests probably has its own short syntax

@caleridas
Copy link
Collaborator

I had started converting to googletest but it is unfinished. I can pick it up to standardize the testing infrastructure, and it uses a syntax like this (plus a couple other useful tools).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants