Parameterized tests feature.

65 views
Skip to first unread message

Denys Mentiei

unread,
Dec 14, 2014, 3:39:00 PM12/14/14
to catch...@googlegroups.com

Hello.

I've started to use Catch lately and came up with an idea of some useful test cas 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.

PS. I've crossposted to https://github.com/philsquared/Catch/issues/358

References:

 
Reply all
Reply to author
Forward
0 new messages