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

Multiple-inputs test case macro #358

Closed
den-mentiei opened this issue Dec 14, 2014 · 4 comments
Closed

Multiple-inputs test case macro #358

den-mentiei opened this issue Dec 14, 2014 · 4 comments

Comments

@den-mentiei
Copy link

Hello.

I've started to use Catch lately and came up with an idea of some useful test case macroses. Something similiar to GoogleTest value-parameterized tests, but much more lightweight (as Catch is, compared to GoogleTest, too).

These macros can be used to declare test cases, which should be run multiple times - once per each item of some input array (or two arrays in an all matches combination).

To allow something like that:

struct TokenCase {
  std::string input;
  Token::Type type;
};

static const TokenCase NUMBER_TOKEN_CASES[] = {
  { "0x123", Token::NUMBER },
  { "0b101", Token::NUMBER },
  { "0o723", Token::NUMBER },
  { "0123", Token::NUMBER },
  { "123", Token::NUMBER },
};

// Variable test_case should be available within test case scope from the 1D macro expansion.
TESTCASE_1D("Numbers lexing", "[lexer]", NUMBER_TOKEN_CASES) {
  // To provide more info on this case on failed assertion.
  INFO("Testing: " << test_case.input);

  // Some sample code to use a test case value.
  Lexer lexer(test_case.input);
  lexer.next();

  REQUIRE(lexer.current().type == test_case.type);
}

I've already implemented this and can work up on the docs (also, on any changes/imporevements yoi can think of) and make a pull request if you are interested.

References:

@philsquared
Copy link
Collaborator

This essentially what Generators are (which are an unfinished, undocumented, feature in Catch - so I'm not suggested you should use them - or even know about them!).

I have some work on a local branch that moves Generators forward a bit but they are still a little way off an official inclusion.

For now take a look at https://github.com/philsquared/Catch/blob/master/projects/SelfTest/GeneratorTests.cpp to get an idea of the direction I'm going with it.

@den-mentiei
Copy link
Author

Any ETAs/progress status on this feature in your branch? I need this and have time to help :)

@philsquared
Copy link
Collaborator

I don't have an ETA, I'm afraid.
And it's one of those things that's mostly design work - rather than raw implementation - so I'm iterating the design. Difficult to share that out - but as I get back to it I'll see if there's anything I can pass on - thanks for the offer!

@philsquared
Copy link
Collaborator

I'm closing this issue in favour of a dedicated generators/ property based testing ticket, #850.
Be sure to watch that issue for notifications if you're interested,

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

No branches or pull requests

2 participants