From 085089ce8d459e1a94451161b42b6b7a3a8eb2db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bonnet?= Date: Fri, 6 Mar 2020 21:36:18 +0100 Subject: [PATCH] Release 1.3.0 --- CHANGELOG.md | 27 ++++++++++++++-- README.md | 52 +++++++++++++++++++++++-------- docs/html/index.html | 12 +++++-- docs/html/picotest_8h_source.html | 2 +- docs/xml/_r_e_a_d_m_e_8md.xml | 52 +++++++++++++++++++++++-------- docs/xml/indexpage.xml | 20 ++++++++++-- docs/xml/picotest_8h.xml | 6 ++-- include/picotest.h | 6 ++-- 8 files changed, 138 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ed458e..2802ca0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.3.0] - 2020-03-06 + +### Added + +- Add test suite +- Make default logger/filter/hooks public: + + - `PICOTEST_FILTER_DEFAULT` + - `PICOTEST_FAILURE_LOGGER_DEFAULT` + - `PICOTEST_CASE_ENTER_DEFAULT` + - `PICOTEST_CASE_LEAVE_DEFAULT` + - `PICOTEST_ASSERT_BEFORE_DEFAULT` + - `PICOTEST_ASSERT_AFTER_DEFAULT` + - `PICOTEST_FIXTURE_BEFORE_SETUP_DEFAULT` + - `PICOTEST_FIXTURE_AFTER_SETUP_DEFAULT` + - `PICOTEST_FIXTURE_BEFORE_TEARDOWN_DEFAULT` + - `PICOTEST_FIXTURE_AFTER_TEARDOWN_DEFAULT` + - `PICOTEST_SUITE_ENTER_DEFAULT` + - `PICOTEST_SUITE_LEAVE_DEFAULT` + - `PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT` + - `PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT` + ## [1.2.1] - 2020-03-02 ### Fixed @@ -29,7 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Add PICOTEST_FAILURE +- Add `PICOTEST_FAILURE` ### Fixed @@ -41,7 +63,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - First release. -[unreleased]: https://github.com/fredericbonnet/picotest/compare/v1.2.1...HEAD +[unreleased]: https://github.com/fredericbonnet/picotest/compare/v1.3.0...HEAD +[1.3.0]: https://github.com/fredericbonnet/picotest/compare/v1.2.1...v1.3.0 [1.2.1]: https://github.com/fredericbonnet/picotest/compare/v1.2.0...v1.2.1 [1.2.0]: https://github.com/fredericbonnet/picotest/compare/v1.1.0...v1.2.0 [1.1.0]: https://github.com/fredericbonnet/picotest/compare/v1.0.0...v1.1.0 diff --git a/README.md b/README.md index f5e703e..b457cb8 100644 --- a/README.md +++ b/README.md @@ -5,21 +5,18 @@ the xUnit principles: https://en.wikipedia.org/wiki/XUnit - ## License PicoTest is released under the terms of the The 3-Clause BSD License: https://opensource.org/licenses/BSD-3-Clause - ## Installation PicoTest is a single-file package, everything is defined in the header file `picotest.h`. So you can either install this file in a standard location, or copy it within your project source tree. - ## Usage Simply include the file in your source file, then start writing your tests! @@ -42,7 +39,6 @@ http://www.stack.nl/~dimitri/doxygen/ You can rebuild the documentation from scratch using the provided `Doxyfile` file. - ## Examples The `examples` subdirectory contains several example source files that @@ -54,10 +50,38 @@ toolchain: https://cmake.org/ +## Tests + +PicoTest is self-tested and comes with a complete test suite that covers all +aspects of the framework. This guarantees that PicoTest is production-ready. + +The test suite itself is a good real-world example of PicoTest in action. + +Building and running the test suite requires CMake (see next section for more +information). To build the suite: + +```sh +cd tests +cmake -S . -B build +cmake --build build +``` + +The build process makes use of the test discovery mechanism described in the +next section. + +To run the suite using CTest: + +```sh +cd tests/build +ctest +``` + +You can also run the suite executable `test_picotest` directly from the CMake +output directory. ## Integration with CMake -PicoTest provides a CMake module definition for easier integration with +PicoTest provides a CMake module definition for easier integration with other CMake projects. In particular, it comes with an auto-discovery script for CTest that makes use of the test traversal features of PicoTest. @@ -66,7 +90,7 @@ The file `FindPicoTest.cmake` is the module definition. Add this file to your ```cmake find_package(PicoTest) -``` +``` You can then add the `PicoTest` dependency to your targets, e.g.: @@ -75,9 +99,10 @@ add_executable(my_test_runner) target_link_libraries(my_test_runner PRIVATE PicoTest ) -``` +``` -If you also use CTest for test automation with `enable_testing()`, you can also call the provided `picotest_discover_tests` macro to integrate PicoTest test +If you also use CTest for test automation with `enable_testing()`, you can also +call the provided `picotest_discover_tests` macro to integrate PicoTest test cases in your build process automatically. For example, assuming that the `my_test_runner` executable: @@ -86,7 +111,8 @@ cases in your build process automatically. For example, assuming that the - when passed ``, will execute the matching test case. Then the following lines will: -1. execute `my_test_runner -l` as a post-build command to `my_test_runner`, + +1. execute `my_test_runner -l` as a post-build command to `my_test_runner`, 2. add each discovered test case using `add_test()`, 3. when invoking the `test` rule, execute each test unitarily with `my_test_runner `. @@ -96,8 +122,7 @@ enable_testing() picotest_discover_tests(my_test_runner TEST_LIST_OPTION "-l" ) -``` - +``` ## Development @@ -105,11 +130,12 @@ PicoTest was developed on Windows 10 and Linux Ubuntu 16.04 using the following tools: - IDE: Visual Studio Code -- Build tool: CMake 3.11.0 +- Build tool: CMake 3.15.2 - Windows toolchain: Microsoft Visual C++ Build Tools 14 - Linux toolchain: GCC 5.4.0 -It should work with any reasonably modern C compiler that supports variadic macros. +It should work with any reasonably modern C compiler that supports variadic +macros. The assertion mechanism relies on `setjmp()` / `longjmp()`. While these functions are discouraged for production code, their usage is acceptable in the diff --git a/docs/html/index.html b/docs/html/index.html index 6ccb075..d819b48 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -85,6 +85,13 @@

Examples

The examples subdirectory contains several example source files that demonstrate the various features of PicoTest. These examples are also integrated in the documentation.

Building the examples requires the CMake build tool along with your favorite toolchain:

https://cmake.org/

+

Tests

+

PicoTest is self-tested and comes with a complete test suite that covers all aspects of the framework. This guarantees that PicoTest is production-ready.

+

The test suite itself is a good real-world example of PicoTest in action.

+

Building and running the test suite requires CMake (see next section for more information). To build the suite:

+
cd tests
cmake -S . -B build
cmake --build build

The build process makes use of the test discovery mechanism described in the next section.

+

To run the suite using CTest:

+
cd tests/build
ctest

You can also run the suite executable test_picotest directly from the CMake output directory.

Integration with CMake

PicoTest provides a CMake module definition for easier integration with other CMake projects. In particular, it comes with an auto-discovery script for CTest that makes use of the test traversal features of PicoTest.

The file FindPicoTest.cmake is the module definition. Add this file to your CMAKE_MODULE_PATH, and add the following line to your CMake project:

@@ -94,7 +101,8 @@

Integration with CMake

  • when passed the -l option, will list all its test cases using the PICOTEST_TRAVERSE feature.
  • when passed <test_name>, will execute the matching test case.
  • -

    Then the following lines will:

      +

      Then the following lines will:

      +
      1. execute my_test_runner -l as a post-build command to my_test_runner,
      2. add each discovered test case using add_test(<test_name>),
      3. when invoking the test rule, execute each test unitarily with my_test_runner <test_name>.
      4. @@ -103,7 +111,7 @@

        Integration with CMake

        PicoTest was developed on Windows 10 and Linux Ubuntu 16.04 using the following tools:

        • IDE: Visual Studio Code
        • -
        • Build tool: CMake 3.11.0
        • +
        • Build tool: CMake 3.15.2
        • Windows toolchain: Microsoft Visual C++ Build Tools 14
        • Linux toolchain: GCC 5.4.0
        diff --git a/docs/html/picotest_8h_source.html b/docs/html/picotest_8h_source.html index 7f722c8..d7061a0 100644 --- a/docs/html/picotest_8h_source.html +++ b/docs/html/picotest_8h_source.html @@ -70,7 +70,7 @@
        picotest.h
        -Go to the documentation of this file.
        1 
        48 #ifndef _PICOTEST
        49 #define _PICOTEST
        50 
        51 #include <setjmp.h>
        52 #include <stdarg.h>
        53 #include <string.h>
        54 
        55 #if defined(_MSC_VER)
        56 
        62 #define _PICOTEST_PARENS
        63 #endif /* defined(_MSC_VER) */
        64 
        78 #define PICOTEST_VERSION "1.2.0"
        79 #define PICOTEST_VERSION_MAJOR 1
        80 #define PICOTEST_VERSION_MINOR 2
        81 #define PICOTEST_VERSION_PATCH 1
        82 
        104 typedef int(PicoTestProc)(const char *cond);
        105 
        125 typedef enum PicoTestFilterResult {
        129 
        132 
        136 
        140 
        166  const char *testName,
        167  const char *cond);
        168 
        179 static PicoTestFilterResult _picoTest_filterByName(PicoTestProc *test,
        180  const char *testName,
        181  const char *cond) {
        182  return (strcmp(testName, cond) == 0 ? PICOTEST_FILTER_PASS
        184 }
        185 
        195 #define PICOTEST_FILTER_DEFAULT _picoTest_filterByName
        196 
        221 #define PICOTEST_FILTER PICOTEST_FILTER_DEFAULT
        222 
        249 typedef void(PicoTestTraverseProc)(const char *name, int nb);
        250 
        263 #define PICOTEST_TRAVERSE(_testName, _proc) _testName##_traverse(_proc)
        264 
        295 typedef void(PicoTestFailureLoggerProc)(const char *file, int line,
        296  const char *type, const char *test,
        297  const char *msg, va_list args);
        298 
        306 static void _picoTest_logFailure(const char *file, int line, const char *type,
        307  const char *test, const char *msg,
        308  va_list args) {}
        309 
        316 #define PICOTEST_FAILURE_LOGGER_DEFAULT _picoTest_logFailure
        317 
        337 #define PICOTEST_FAILURE_LOGGER PICOTEST_FAILURE_LOGGER_DEFAULT
        338 
        376 #if defined(_PICOTEST_PARENS)
        377 #define PICOTEST_CASE(...) \
        378  _PICOTEST_CONCATENATE(_PICOTEST_CASE_, _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        379  _PICOTEST_PARENS(__VA_ARGS__)
        380 #else
        381 #define PICOTEST_CASE(...) \
        382  _PICOTEST_CONCATENATE(_PICOTEST_CASE_, _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        383  (__VA_ARGS__)
        384 #endif /* defined(_PICOTEST_PARENS) */
        385 
        387 #define _PICOTEST_CASE_DECLARE(_testName) \
        388  int _testName##_testCaseRunner(void); \
        389  void _testName##_traverse(PicoTestTraverseProc *proc) { \
        390  proc(_PICOTEST_STRINGIZE(_testName), 0); \
        391  } \
        392  int _testName(const char *cond) { \
        393  int fail = 0; \
        394  PicoTestFilterResult filterResult = \
        395  (cond == NULL) \
        396  ? PICOTEST_FILTER_PASS \
        397  : PICOTEST_FILTER(_testName, _PICOTEST_STRINGIZE(_testName), \
        398  cond); \
        399  switch (filterResult) { \
        400  case PICOTEST_FILTER_PASS: \
        401  case PICOTEST_FILTER_PASS_PROPAGATE: \
        402  fail += _testName##_testCaseRunner(); \
        403  break; \
        404  } \
        405  return fail; \
        406  }
        407 
        408 #define _PICOTEST_CASE_RUNNER_BEGIN(_testName) \
        409  int _testName##_testCaseRunner() { \
        410  int abort; \
        411  jmp_buf failureEnv; \
        412  jmp_buf *oldEnv = _picoTest_failureEnv; \
        413  int fail, oldFail = _picoTest_fail; \
        414  _picoTest_failureEnv = &failureEnv; \
        415  _picoTest_fail = 0; \
        416  PICOTEST_CASE_ENTER(_PICOTEST_STRINGIZE(_testName)); \
        417  abort = setjmp(failureEnv);
        418 
        419 #define _PICOTEST_CASE_RUNNER_END(_testName) \
        420  fail = _picoTest_fail; \
        421  PICOTEST_CASE_LEAVE(_PICOTEST_STRINGIZE(_testName), fail); \
        422  _picoTest_failureEnv = oldEnv; \
        423  _picoTest_fail = oldFail; \
        424  return fail; \
        425  }
        426 
        427 #define _PICOTEST_CASE_1(_testName) \
        428  _PICOTEST_CASE_DECLARE(_testName) \
        429  static void _testName##_testCase(void); \
        430  _PICOTEST_CASE_RUNNER_BEGIN(_testName) \
        431  if (!abort) { \
        432  _testName##_testCase(); \
        433  } \
        434  _PICOTEST_CASE_RUNNER_END(_testName) \
        435  static void _testName##_testCase(void)
        436 
        437 #define _PICOTEST_CASE_2(_testName, _fixtureName) \
        438  _PICOTEST_CASE_DECLARE(_testName) \
        439  static void _testName##_testCase(void); \
        440  _PICOTEST_CASE_RUNNER_BEGIN(_testName) \
        441  if (!abort) { \
        442  _PICOTEST_FIXTURE_CALL_SETUP(_fixtureName, _testName, NULL); \
        443  _testName##_testCase(); \
        444  } \
        445  _PICOTEST_FIXTURE_CALL_TEARDOWN(_fixtureName, _testName, NULL, \
        446  _picoTest_fail); \
        447  _PICOTEST_CASE_RUNNER_END(_testName) \
        448  static void _testName##_testCase()
        449 
        450 #define _PICOTEST_CASE_3(_testName, _fixtureName, _context) \
        451  _PICOTEST_CASE_DECLARE(_testName) \
        452  static void _testName##_testCase(struct _fixtureName##_Context *); \
        453  _PICOTEST_CASE_RUNNER_BEGIN(_testName) { \
        454  struct _fixtureName##_Context context; \
        455  if (!abort) { \
        456  _PICOTEST_FIXTURE_CALL_SETUP(_fixtureName, _testName, &context); \
        457  _testName##_testCase(&context); \
        458  } \
        459  _PICOTEST_FIXTURE_CALL_TEARDOWN(_fixtureName, _testName, &context, \
        460  _picoTest_fail); \
        461  } \
        462  _PICOTEST_CASE_RUNNER_END(_testName) \
        463  static void _testName##_testCase(struct _fixtureName##_Context *_context)
        464 
        491 typedef void(PicoTestCaseEnterProc)(const char *testName);
        492 
        499 #define PICOTEST_CASE_ENTER_DEFAULT(testName)
        500 
        521 #define PICOTEST_CASE_ENTER PICOTEST_CASE_ENTER_DEFAULT
        522 
        539 typedef void(PicoTestCaseLeaveProc)(const char *testName, int fail);
        540 
        547 #define PICOTEST_CASE_LEAVE_DEFAULT(testName, fail)
        548 
        569 #define PICOTEST_CASE_LEAVE PICOTEST_CASE_LEAVE_DEFAULT
        570 
        609 #define PICOTEST_ASSERT(x, /* msg, */...) \
        610  { _PICOTEST_ASSERT(x, #x, ##__VA_ARGS__); }
        611 
        613 #define _PICOTEST_ASSERT(x, ...) \
        614  PICOTEST_ASSERT_BEFORE("ASSERT", #x); \
        615  { \
        616  int _PICOTEST_FAIL = !(x); \
        617  PICOTEST_ASSERT_AFTER("ASSERT", #x, _PICOTEST_FAIL); \
        618  if (_PICOTEST_FAIL) { \
        619  PICOTEST_FAILURE("ASSERT", ##__VA_ARGS__); \
        620  PICOTEST_ABORT(); \
        621  } \
        622  }
        623 
        646 #define PICOTEST_VERIFY(x, /* msg, */...) \
        647  { _PICOTEST_VERIFY(x, #x, ##__VA_ARGS__); }
        648 
        650 #define _PICOTEST_VERIFY(x, ...) \
        651  PICOTEST_ASSERT_BEFORE("VERIFY", #x); \
        652  { \
        653  int _PICOTEST_FAIL = !(x); \
        654  PICOTEST_ASSERT_AFTER("VERIFY", #x, _PICOTEST_FAIL); \
        655  if (_PICOTEST_FAIL) { \
        656  PICOTEST_FAILURE("VERIFY", ##__VA_ARGS__); \
        657  } \
        658  }
        659 
        674 #define PICOTEST_FAILURE(type, test, /* msg, */...) \
        675  _PICOTEST_FAILURE(type, test, ##__VA_ARGS__)
        676 
        678 #define _PICOTEST_FAILURE(type, ...) \
        679  _picoTest_fail++; \
        680  _picoTest_assertFailed(PICOTEST_FAILURE_LOGGER, __FILE__, __LINE__, type, \
        681  _PICOTEST_ARGCOUNT(__VA_ARGS__), __VA_ARGS__); \
        682 
        689 static int _picoTest_fail = 0;
        690 
        697 static jmp_buf *_picoTest_failureEnv = NULL;
        698 
        706 #define PICOTEST_ABORT() longjmp(*_picoTest_failureEnv, 1)
        707 
        723 static void _picoTest_assertFailed(PicoTestFailureLoggerProc *proc,
        724  const char *file, int line, const char *type,
        725  int count, const char *test, ...) {
        726  if (count > 1) {
        727  /* Extra args after **test** */
        728  va_list args;
        729  const char *msg;
        730  va_start(args, test);
        731  msg = va_arg(args, const char *);
        732  proc(file, line, type, test, msg, args);
        733  } else {
        734  proc(file, line, type, test, NULL, NULL);
        735  }
        736 }
        737 
        764 typedef void(PicoTestAssertBeforeProc)(const char *type, const char *test);
        765 
        772 #define PICOTEST_ASSERT_BEFORE_DEFAULT(type, test)
        773 
        794 #define PICOTEST_ASSERT_BEFORE PICOTEST_ASSERT_BEFORE_DEFAULT
        795 
        813 typedef void(PicoTestAssertAfterProc)(const char *type, const char *test,
        814  int fail);
        815 
        822 #define PICOTEST_ASSERT_AFTER_DEFAULT(type, test, fail)
        823 
        844 #define PICOTEST_ASSERT_AFTER PICOTEST_ASSERT_AFTER_DEFAULT
        845 
        883 #define PICOTEST_FIXTURE_CONTEXT(_fixtureName) struct _fixtureName##_Context
        884 
        913 #if defined(_PICOTEST_PARENS)
        914 #define PICOTEST_FIXTURE_SETUP(...) \
        915  _PICOTEST_CONCATENATE(_PICOTEST_FIXTURE_SETUP_, \
        916  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        917  _PICOTEST_PARENS(__VA_ARGS__)
        918 #else
        919 #define PICOTEST_FIXTURE_SETUP(...) \
        920  _PICOTEST_CONCATENATE(_PICOTEST_FIXTURE_SETUP_, \
        921  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        922  (__VA_ARGS__)
        923 #endif /* defined(_PICOTEST_PARENS) */
        924 
        926 #define _PICOTEST_FIXTURE_SETUP_1(_fixtureName) \
        927  static void _fixtureName##_setup(void *_fixtureName##_DUMMY)
        928 
        929 #define _PICOTEST_FIXTURE_SETUP_2(_fixtureName, _context) \
        930  static void _fixtureName##_setup(struct _fixtureName##_Context *_context)
        931 
        932 #define _PICOTEST_FIXTURE_CALL_SETUP(_fixtureName, _testName, context) \
        933  PICOTEST_FIXTURE_BEFORE_SETUP(_PICOTEST_STRINGIZE(_fixtureName), \
        934  _PICOTEST_STRINGIZE(_testName)); \
        935  _fixtureName##_setup(context); \
        936  PICOTEST_FIXTURE_AFTER_SETUP(_PICOTEST_STRINGIZE(_fixtureName), \
        937  _PICOTEST_STRINGIZE(_testName));
        938 
        968 #if defined(_PICOTEST_PARENS)
        969 #define PICOTEST_FIXTURE_TEARDOWN(...) \
        970  _PICOTEST_CONCATENATE(_PICOTEST_FIXTURE_TEARDOWN_, \
        971  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        972  _PICOTEST_PARENS(__VA_ARGS__)
        973 #else
        974 #define PICOTEST_FIXTURE_TEARDOWN(...) \
        975  _PICOTEST_CONCATENATE(_PICOTEST_FIXTURE_TEARDOWN_, \
        976  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        977  (__VA_ARGS__)
        978 #endif /* defined(_PICOTEST_PARENS) */
        979 
        981 #define _PICOTEST_FIXTURE_TEARDOWN_1(_fixtureName) \
        982  static void _fixtureName##_teardown(int PICOTEST_FAIL, \
        983  void *_fixtureName##_DUMMY)
        984 
        985 #define _PICOTEST_FIXTURE_TEARDOWN_2(_fixtureName, _context) \
        986  static void _fixtureName##_teardown( \
        987  int PICOTEST_FAIL, struct _fixtureName##_Context *_context)
        988 
        989 #define _PICOTEST_FIXTURE_CALL_TEARDOWN(_fixtureName, _testName, context, \
        990  fail) \
        991  PICOTEST_FIXTURE_BEFORE_TEARDOWN(_PICOTEST_STRINGIZE(_fixtureName), \
        992  _PICOTEST_STRINGIZE(_testName), fail); \
        993  _fixtureName##_teardown(fail, context); \
        994  PICOTEST_FIXTURE_AFTER_TEARDOWN(_PICOTEST_STRINGIZE(_fixtureName), \
        995  _PICOTEST_STRINGIZE(_testName), fail); \
        996 
        1024 typedef void(PicoTestFixtureBeforeSetupProc)(const char *fixtureName,
        1025  const char *testName);
        1026 
        1033 #define PICOTEST_FIXTURE_BEFORE_SETUP_DEFAULT(fixtureName, testName)
        1034 
        1055 #define PICOTEST_FIXTURE_BEFORE_SETUP PICOTEST_FIXTURE_BEFORE_SETUP_DEFAULT
        1056 
        1073 typedef void(PicoTestFixtureAfterSetupProc)(const char *fixtureName,
        1074  const char *testName);
        1075 
        1082 #define PICOTEST_FIXTURE_AFTER_SETUP_DEFAULT(fixtureName, testName)
        1083 
        1104 #define PICOTEST_FIXTURE_AFTER_SETUP PICOTEST_FIXTURE_AFTER_SETUP_DEFAULT
        1105 
        1123 typedef void(PicoTestFixtureBeforeTeardownProc)(const char *fixtureName,
        1124  const char *testName, int fail);
        1125 
        1132 #define PICOTEST_FIXTURE_BEFORE_TEARDOWN_DEFAULT(fixtureName, testName, fail)
        1133 
        1154 #define PICOTEST_FIXTURE_BEFORE_TEARDOWN \
        1155  PICOTEST_FIXTURE_BEFORE_TEARDOWN_DEFAULT
        1156 
        1174 typedef void(PicoTestFixtureAfterTeardownProc)(const char *fixtureName,
        1175  const char *testName, int fail);
        1176 
        1183 #define PICOTEST_FIXTURE_AFTER_TEARDOWN_DEFAULT(fixtureName, testName, fail)
        1184 
        1205 #define PICOTEST_FIXTURE_AFTER_TEARDOWN PICOTEST_FIXTURE_AFTER_TEARDOWN_DEFAULT
        1206 
        1246 #define PICOTEST_SUITE(_suiteName, ...) \
        1247  _PICOTEST_FOR_EACH(_PICOTEST_SUITE_DECLARE_TEST, __VA_ARGS__) \
        1248  static PicoTestDescr _suiteName##_tests[] = {_PICOTEST_FOR_EACH( \
        1249  _PICOTEST_SUITE_DECLARE_TEST_CASE, __VA_ARGS__){NULL, NULL, NULL}}; \
        1250  void _suiteName##_traverse(PicoTestTraverseProc *proc) { \
        1251  const int nb = \
        1252  sizeof(_suiteName##_tests) / sizeof(*_suiteName##_tests) - 1; \
        1253  PicoTestDescr *test = _suiteName##_tests; \
        1254  proc(_PICOTEST_STRINGIZE(_suiteName), nb); \
        1255  for (; test->name; test++) { \
        1256  test->traverse(proc); \
        1257  } \
        1258  } \
        1259  int _suiteName##_testCaseRunner(const char *cond) { \
        1260  const int nb = \
        1261  sizeof(_suiteName##_tests) / sizeof(*_suiteName##_tests) - 1; \
        1262  PicoTestDescr *test = _suiteName##_tests; \
        1263  int fail = 0; \
        1264  PICOTEST_SUITE_ENTER(_PICOTEST_STRINGIZE(_suiteName), nb); \
        1265  for (; test->name; test++) { \
        1266  const int index = (int)(test - _suiteName##_tests); \
        1267  int sfail = 0; \
        1268  PICOTEST_SUITE_BEFORE_SUBTEST(_PICOTEST_STRINGIZE(_suiteName), nb, \
        1269  fail, index, test->name); \
        1270  sfail = test->test(cond); \
        1271  fail += sfail; \
        1272  PICOTEST_SUITE_AFTER_SUBTEST(_PICOTEST_STRINGIZE(_suiteName), nb, \
        1273  fail, index, test->name, sfail); \
        1274  } \
        1275  PICOTEST_SUITE_LEAVE(_PICOTEST_STRINGIZE(_suiteName), nb, fail); \
        1276  return fail; \
        1277  } \
        1278  int _suiteName(const char *cond) { \
        1279  int fail = 0; \
        1280  PicoTestFilterResult filterResult = \
        1281  (cond == NULL) \
        1282  ? PICOTEST_FILTER_PASS \
        1283  : PICOTEST_FILTER(_suiteName, _PICOTEST_STRINGIZE(_suiteName), \
        1284  cond); \
        1285  switch (filterResult) { \
        1286  case PICOTEST_FILTER_PASS: \
        1287  cond = NULL; \
        1288  case PICOTEST_FILTER_PASS_PROPAGATE: \
        1289  fail += _suiteName##_testCaseRunner(cond); \
        1290  break; \
        1291  case PICOTEST_FILTER_SKIP: \
        1292  break; \
        1293  case PICOTEST_FILTER_SKIP_PROPAGATE: { \
        1294  PicoTestDescr *test = _suiteName##_tests; \
        1295  for (; test->name; test++) { \
        1296  fail += test->test(cond); \
        1297  } \
        1298  } break; \
        1299  } \
        1300  return fail; \
        1301  }
        1302 
        1304 #define _PICOTEST_SUITE_DECLARE_TEST_CASE(_testName) \
        1305  {_PICOTEST_STRINGIZE(_testName), _testName, _testName##_traverse},
        1306 #define _PICOTEST_SUITE_DECLARE_TEST(_testName) \
        1307  int _testName(const char *); \
        1308  void _testName##_traverse(PicoTestTraverseProc *);
        1309 
        1311 typedef struct PicoTestDescr {
        1312  const char *name;
        1313  PicoTestProc *test;
        1314  void (*traverse)(PicoTestTraverseProc *);
        1315 } PicoTestDescr;
        1345 typedef void(PicoTestSuiteEnterProc)(const char *suiteName, int nb);
        1346 
        1353 #define PICOTEST_SUITE_ENTER_DEFAULT(suiteName, nb)
        1354 
        1375 #define PICOTEST_SUITE_ENTER PICOTEST_SUITE_ENTER_DEFAULT
        1376 
        1393 typedef void(PicoTestSuiteLeaveProc)(const char *suiteName, int nb, int fail);
        1394 
        1401 #define PICOTEST_SUITE_LEAVE_DEFAULT(suiteName, nb, fail)
        1402 
        1425 #define PICOTEST_SUITE_LEAVE PICOTEST_SUITE_LEAVE_DEFAULT
        1426 
        1447 typedef void(PicoTestSuiteBeforeSubtestProc)(const char *suiteName, int nb,
        1448  int fail, int index,
        1449  const char *testName);
        1450 
        1457 #define PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT(suiteName, nb, fail, index, \
        1458  testName)
        1459 
        1480 #define PICOTEST_SUITE_BEFORE_SUBTEST PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT
        1481 
        1504 typedef void(PicoTestSuiteAfterSubtestProc)(const char *suiteName, int nb,
        1505  int fail, int index,
        1506  const char *testName, int sfail);
        1507 
        1514 #define PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT(suiteName, nb, fail, index, \
        1515  testName, sfail)
        1516 
        1537 #define PICOTEST_SUITE_AFTER_SUBTEST PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT
        1538 
        1560 #define _PICOTEST_STRINGIZE(arg) #arg
        1561 
        1565 #define _PICOTEST_CONCATENATE(arg1, arg2) _PICOTEST_CONCATENATE1(arg1, arg2)
        1566 
        1568 #define _PICOTEST_CONCATENATE1(arg1, arg2) _PICOTEST_CONCATENATE2(arg1, arg2)
        1569 #define _PICOTEST_CONCATENATE2(arg1, arg2) arg1##arg2
        1570 
        1592 #if defined(_PICOTEST_PARENS)
        1593 #define _PICOTEST_ARGCOUNT(...) \
        1594  _PICOTEST_LASTARG _PICOTEST_PARENS( \
        1595  __VA_ARGS__, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
        1596  49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, \
        1597  32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, \
        1598  15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
        1599 #else
        1600 #define _PICOTEST_ARGCOUNT(...) \
        1601  _PICOTEST_LASTARG(__VA_ARGS__, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, \
        1602  52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, \
        1603  38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, \
        1604  24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
        1605  10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
        1606 #endif /* defined(_PICOTEST_PARENS) */
        1607 
        1609 #define _PICOTEST_LASTARG( \
        1610  _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, \
        1611  _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, \
        1612  _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, \
        1613  _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, \
        1614  _62, _63, N, ...) \
        1615  N
        1616 
        1628 #if defined(_PICOTEST_PARENS)
        1629 #define _PICOTEST_FOR_EACH(what, ...) \
        1630  _PICOTEST_CONCATENATE(_PICOTEST_FOR_EACH_, \
        1631  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        1632  _PICOTEST_PARENS(what, __VA_ARGS__)
        1633 #else
        1634 #define _PICOTEST_FOR_EACH(what, ...) \
        1635  _PICOTEST_CONCATENATE(_PICOTEST_FOR_EACH_, \
        1636  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        1637  (what, __VA_ARGS__)
        1638 #endif /* defined(_PICOTEST_PARENS) */
        1639 
        1641 #if defined(_PICOTEST_PARENS)
        1642 #define _PICOTEST_FOR_EACH_1(what, x) what(x)
        1643 #define _PICOTEST_FOR_EACH_2(what, x, ...) \
        1644  what(x) _PICOTEST_FOR_EACH_1 _PICOTEST_PARENS(what, __VA_ARGS__)
        1645 #define _PICOTEST_FOR_EACH_3(what, x, ...) \
        1646  what(x) _PICOTEST_FOR_EACH_2 _PICOTEST_PARENS(what, __VA_ARGS__)
        1647 #define _PICOTEST_FOR_EACH_4(what, x, ...) \
        1648  what(x) _PICOTEST_FOR_EACH_3 _PICOTEST_PARENS(what, __VA_ARGS__)
        1649 #define _PICOTEST_FOR_EACH_5(what, x, ...) \
        1650  what(x) _PICOTEST_FOR_EACH_4 _PICOTEST_PARENS(what, __VA_ARGS__)
        1651 #define _PICOTEST_FOR_EACH_6(what, x, ...) \
        1652  what(x) _PICOTEST_FOR_EACH_5 _PICOTEST_PARENS(what, __VA_ARGS__)
        1653 #define _PICOTEST_FOR_EACH_7(what, x, ...) \
        1654  what(x) _PICOTEST_FOR_EACH_6 _PICOTEST_PARENS(what, __VA_ARGS__)
        1655 #define _PICOTEST_FOR_EACH_8(what, x, ...) \
        1656  what(x) _PICOTEST_FOR_EACH_7 _PICOTEST_PARENS(what, __VA_ARGS__)
        1657 #define _PICOTEST_FOR_EACH_9(what, x, ...) \
        1658  what(x) _PICOTEST_FOR_EACH_8 _PICOTEST_PARENS(what, __VA_ARGS__)
        1659 #define _PICOTEST_FOR_EACH_10(what, x, ...) \
        1660  what(x) _PICOTEST_FOR_EACH_9 _PICOTEST_PARENS(what, __VA_ARGS__)
        1661 #define _PICOTEST_FOR_EACH_11(what, x, ...) \
        1662  what(x) _PICOTEST_FOR_EACH_10 _PICOTEST_PARENS(what, __VA_ARGS__)
        1663 #define _PICOTEST_FOR_EACH_12(what, x, ...) \
        1664  what(x) _PICOTEST_FOR_EACH_11 _PICOTEST_PARENS(what, __VA_ARGS__)
        1665 #define _PICOTEST_FOR_EACH_13(what, x, ...) \
        1666  what(x) _PICOTEST_FOR_EACH_12 _PICOTEST_PARENS(what, __VA_ARGS__)
        1667 #define _PICOTEST_FOR_EACH_14(what, x, ...) \
        1668  what(x) _PICOTEST_FOR_EACH_13 _PICOTEST_PARENS(what, __VA_ARGS__)
        1669 #define _PICOTEST_FOR_EACH_15(what, x, ...) \
        1670  what(x) _PICOTEST_FOR_EACH_14 _PICOTEST_PARENS(what, __VA_ARGS__)
        1671 #define _PICOTEST_FOR_EACH_16(what, x, ...) \
        1672  what(x) _PICOTEST_FOR_EACH_15 _PICOTEST_PARENS(what, __VA_ARGS__)
        1673 #define _PICOTEST_FOR_EACH_17(what, x, ...) \
        1674  what(x) _PICOTEST_FOR_EACH_16 _PICOTEST_PARENS(what, __VA_ARGS__)
        1675 #define _PICOTEST_FOR_EACH_18(what, x, ...) \
        1676  what(x) _PICOTEST_FOR_EACH_17 _PICOTEST_PARENS(what, __VA_ARGS__)
        1677 #define _PICOTEST_FOR_EACH_19(what, x, ...) \
        1678  what(x) _PICOTEST_FOR_EACH_18 _PICOTEST_PARENS(what, __VA_ARGS__)
        1679 #define _PICOTEST_FOR_EACH_20(what, x, ...) \
        1680  what(x) _PICOTEST_FOR_EACH_19 _PICOTEST_PARENS(what, __VA_ARGS__)
        1681 #define _PICOTEST_FOR_EACH_21(what, x, ...) \
        1682  what(x) _PICOTEST_FOR_EACH_20 _PICOTEST_PARENS(what, __VA_ARGS__)
        1683 #define _PICOTEST_FOR_EACH_22(what, x, ...) \
        1684  what(x) _PICOTEST_FOR_EACH_21 _PICOTEST_PARENS(what, __VA_ARGS__)
        1685 #define _PICOTEST_FOR_EACH_23(what, x, ...) \
        1686  what(x) _PICOTEST_FOR_EACH_22 _PICOTEST_PARENS(what, __VA_ARGS__)
        1687 #define _PICOTEST_FOR_EACH_24(what, x, ...) \
        1688  what(x) _PICOTEST_FOR_EACH_23 _PICOTEST_PARENS(what, __VA_ARGS__)
        1689 #define _PICOTEST_FOR_EACH_25(what, x, ...) \
        1690  what(x) _PICOTEST_FOR_EACH_24 _PICOTEST_PARENS(what, __VA_ARGS__)
        1691 #define _PICOTEST_FOR_EACH_26(what, x, ...) \
        1692  what(x) _PICOTEST_FOR_EACH_25 _PICOTEST_PARENS(what, __VA_ARGS__)
        1693 #define _PICOTEST_FOR_EACH_27(what, x, ...) \
        1694  what(x) _PICOTEST_FOR_EACH_26 _PICOTEST_PARENS(what, __VA_ARGS__)
        1695 #define _PICOTEST_FOR_EACH_28(what, x, ...) \
        1696  what(x) _PICOTEST_FOR_EACH_27 _PICOTEST_PARENS(what, __VA_ARGS__)
        1697 #define _PICOTEST_FOR_EACH_29(what, x, ...) \
        1698  what(x) _PICOTEST_FOR_EACH_28 _PICOTEST_PARENS(what, __VA_ARGS__)
        1699 #define _PICOTEST_FOR_EACH_30(what, x, ...) \
        1700  what(x) _PICOTEST_FOR_EACH_29 _PICOTEST_PARENS(what, __VA_ARGS__)
        1701 #define _PICOTEST_FOR_EACH_31(what, x, ...) \
        1702  what(x) _PICOTEST_FOR_EACH_30 _PICOTEST_PARENS(what, __VA_ARGS__)
        1703 #define _PICOTEST_FOR_EACH_32(what, x, ...) \
        1704  what(x) _PICOTEST_FOR_EACH_31 _PICOTEST_PARENS(what, __VA_ARGS__)
        1705 #define _PICOTEST_FOR_EACH_33(what, x, ...) \
        1706  what(x) _PICOTEST_FOR_EACH_32 _PICOTEST_PARENS(what, __VA_ARGS__)
        1707 #define _PICOTEST_FOR_EACH_34(what, x, ...) \
        1708  what(x) _PICOTEST_FOR_EACH_33 _PICOTEST_PARENS(what, __VA_ARGS__)
        1709 #define _PICOTEST_FOR_EACH_35(what, x, ...) \
        1710  what(x) _PICOTEST_FOR_EACH_34 _PICOTEST_PARENS(what, __VA_ARGS__)
        1711 #define _PICOTEST_FOR_EACH_36(what, x, ...) \
        1712  what(x) _PICOTEST_FOR_EACH_35 _PICOTEST_PARENS(what, __VA_ARGS__)
        1713 #define _PICOTEST_FOR_EACH_37(what, x, ...) \
        1714  what(x) _PICOTEST_FOR_EACH_36 _PICOTEST_PARENS(what, __VA_ARGS__)
        1715 #define _PICOTEST_FOR_EACH_38(what, x, ...) \
        1716  what(x) _PICOTEST_FOR_EACH_37 _PICOTEST_PARENS(what, __VA_ARGS__)
        1717 #define _PICOTEST_FOR_EACH_39(what, x, ...) \
        1718  what(x) _PICOTEST_FOR_EACH_38 _PICOTEST_PARENS(what, __VA_ARGS__)
        1719 #define _PICOTEST_FOR_EACH_40(what, x, ...) \
        1720  what(x) _PICOTEST_FOR_EACH_39 _PICOTEST_PARENS(what, __VA_ARGS__)
        1721 #define _PICOTEST_FOR_EACH_41(what, x, ...) \
        1722  what(x) _PICOTEST_FOR_EACH_40 _PICOTEST_PARENS(what, __VA_ARGS__)
        1723 #define _PICOTEST_FOR_EACH_42(what, x, ...) \
        1724  what(x) _PICOTEST_FOR_EACH_41 _PICOTEST_PARENS(what, __VA_ARGS__)
        1725 #define _PICOTEST_FOR_EACH_43(what, x, ...) \
        1726  what(x) _PICOTEST_FOR_EACH_42 _PICOTEST_PARENS(what, __VA_ARGS__)
        1727 #define _PICOTEST_FOR_EACH_44(what, x, ...) \
        1728  what(x) _PICOTEST_FOR_EACH_43 _PICOTEST_PARENS(what, __VA_ARGS__)
        1729 #define _PICOTEST_FOR_EACH_45(what, x, ...) \
        1730  what(x) _PICOTEST_FOR_EACH_44 _PICOTEST_PARENS(what, __VA_ARGS__)
        1731 #define _PICOTEST_FOR_EACH_46(what, x, ...) \
        1732  what(x) _PICOTEST_FOR_EACH_45 _PICOTEST_PARENS(what, __VA_ARGS__)
        1733 #define _PICOTEST_FOR_EACH_47(what, x, ...) \
        1734  what(x) _PICOTEST_FOR_EACH_46 _PICOTEST_PARENS(what, __VA_ARGS__)
        1735 #define _PICOTEST_FOR_EACH_48(what, x, ...) \
        1736  what(x) _PICOTEST_FOR_EACH_47 _PICOTEST_PARENS(what, __VA_ARGS__)
        1737 #define _PICOTEST_FOR_EACH_49(what, x, ...) \
        1738  what(x) _PICOTEST_FOR_EACH_48 _PICOTEST_PARENS(what, __VA_ARGS__)
        1739 #define _PICOTEST_FOR_EACH_50(what, x, ...) \
        1740  what(x) _PICOTEST_FOR_EACH_49 _PICOTEST_PARENS(what, __VA_ARGS__)
        1741 #define _PICOTEST_FOR_EACH_51(what, x, ...) \
        1742  what(x) _PICOTEST_FOR_EACH_50 _PICOTEST_PARENS(what, __VA_ARGS__)
        1743 #define _PICOTEST_FOR_EACH_52(what, x, ...) \
        1744  what(x) _PICOTEST_FOR_EACH_51 _PICOTEST_PARENS(what, __VA_ARGS__)
        1745 #define _PICOTEST_FOR_EACH_53(what, x, ...) \
        1746  what(x) _PICOTEST_FOR_EACH_52 _PICOTEST_PARENS(what, __VA_ARGS__)
        1747 #define _PICOTEST_FOR_EACH_54(what, x, ...) \
        1748  what(x) _PICOTEST_FOR_EACH_53 _PICOTEST_PARENS(what, __VA_ARGS__)
        1749 #define _PICOTEST_FOR_EACH_55(what, x, ...) \
        1750  what(x) _PICOTEST_FOR_EACH_54 _PICOTEST_PARENS(what, __VA_ARGS__)
        1751 #define _PICOTEST_FOR_EACH_56(what, x, ...) \
        1752  what(x) _PICOTEST_FOR_EACH_55 _PICOTEST_PARENS(what, __VA_ARGS__)
        1753 #define _PICOTEST_FOR_EACH_57(what, x, ...) \
        1754  what(x) _PICOTEST_FOR_EACH_56 _PICOTEST_PARENS(what, __VA_ARGS__)
        1755 #define _PICOTEST_FOR_EACH_58(what, x, ...) \
        1756  what(x) _PICOTEST_FOR_EACH_57 _PICOTEST_PARENS(what, __VA_ARGS__)
        1757 #define _PICOTEST_FOR_EACH_59(what, x, ...) \
        1758  what(x) _PICOTEST_FOR_EACH_58 _PICOTEST_PARENS(what, __VA_ARGS__)
        1759 #define _PICOTEST_FOR_EACH_60(what, x, ...) \
        1760  what(x) _PICOTEST_FOR_EACH_59 _PICOTEST_PARENS(what, __VA_ARGS__)
        1761 #define _PICOTEST_FOR_EACH_61(what, x, ...) \
        1762  what(x) _PICOTEST_FOR_EACH_60 _PICOTEST_PARENS(what, __VA_ARGS__)
        1763 #define _PICOTEST_FOR_EACH_62(what, x, ...) \
        1764  what(x) _PICOTEST_FOR_EACH_61 _PICOTEST_PARENS(what, __VA_ARGS__)
        1765 #define _PICOTEST_FOR_EACH_63(what, x, ...) \
        1766  what(x) _PICOTEST_FOR_EACH_62 _PICOTEST_PARENS(what, __VA_ARGS__)
        1767 #else
        1768 #define _PICOTEST_FOR_EACH_1(what, x) what(x)
        1769 #define _PICOTEST_FOR_EACH_2(what, x, ...) \
        1770  what(x) _PICOTEST_FOR_EACH_1(what, __VA_ARGS__)
        1771 #define _PICOTEST_FOR_EACH_3(what, x, ...) \
        1772  what(x) _PICOTEST_FOR_EACH_2(what, __VA_ARGS__)
        1773 #define _PICOTEST_FOR_EACH_4(what, x, ...) \
        1774  what(x) _PICOTEST_FOR_EACH_3(what, __VA_ARGS__)
        1775 #define _PICOTEST_FOR_EACH_5(what, x, ...) \
        1776  what(x) _PICOTEST_FOR_EACH_4(what, __VA_ARGS__)
        1777 #define _PICOTEST_FOR_EACH_6(what, x, ...) \
        1778  what(x) _PICOTEST_FOR_EACH_5(what, __VA_ARGS__)
        1779 #define _PICOTEST_FOR_EACH_7(what, x, ...) \
        1780  what(x) _PICOTEST_FOR_EACH_6(what, __VA_ARGS__)
        1781 #define _PICOTEST_FOR_EACH_8(what, x, ...) \
        1782  what(x) _PICOTEST_FOR_EACH_7(what, __VA_ARGS__)
        1783 #define _PICOTEST_FOR_EACH_9(what, x, ...) \
        1784  what(x) _PICOTEST_FOR_EACH_8(what, __VA_ARGS__)
        1785 #define _PICOTEST_FOR_EACH_10(what, x, ...) \
        1786  what(x) _PICOTEST_FOR_EACH_9(what, __VA_ARGS__)
        1787 #define _PICOTEST_FOR_EACH_11(what, x, ...) \
        1788  what(x) _PICOTEST_FOR_EACH_10(what, __VA_ARGS__)
        1789 #define _PICOTEST_FOR_EACH_12(what, x, ...) \
        1790  what(x) _PICOTEST_FOR_EACH_11(what, __VA_ARGS__)
        1791 #define _PICOTEST_FOR_EACH_13(what, x, ...) \
        1792  what(x) _PICOTEST_FOR_EACH_12(what, __VA_ARGS__)
        1793 #define _PICOTEST_FOR_EACH_14(what, x, ...) \
        1794  what(x) _PICOTEST_FOR_EACH_13(what, __VA_ARGS__)
        1795 #define _PICOTEST_FOR_EACH_15(what, x, ...) \
        1796  what(x) _PICOTEST_FOR_EACH_14(what, __VA_ARGS__)
        1797 #define _PICOTEST_FOR_EACH_16(what, x, ...) \
        1798  what(x) _PICOTEST_FOR_EACH_15(what, __VA_ARGS__)
        1799 #define _PICOTEST_FOR_EACH_17(what, x, ...) \
        1800  what(x) _PICOTEST_FOR_EACH_16(what, __VA_ARGS__)
        1801 #define _PICOTEST_FOR_EACH_18(what, x, ...) \
        1802  what(x) _PICOTEST_FOR_EACH_17(what, __VA_ARGS__)
        1803 #define _PICOTEST_FOR_EACH_19(what, x, ...) \
        1804  what(x) _PICOTEST_FOR_EACH_18(what, __VA_ARGS__)
        1805 #define _PICOTEST_FOR_EACH_20(what, x, ...) \
        1806  what(x) _PICOTEST_FOR_EACH_19(what, __VA_ARGS__)
        1807 #define _PICOTEST_FOR_EACH_21(what, x, ...) \
        1808  what(x) _PICOTEST_FOR_EACH_20(what, __VA_ARGS__)
        1809 #define _PICOTEST_FOR_EACH_22(what, x, ...) \
        1810  what(x) _PICOTEST_FOR_EACH_21(what, __VA_ARGS__)
        1811 #define _PICOTEST_FOR_EACH_23(what, x, ...) \
        1812  what(x) _PICOTEST_FOR_EACH_22(what, __VA_ARGS__)
        1813 #define _PICOTEST_FOR_EACH_24(what, x, ...) \
        1814  what(x) _PICOTEST_FOR_EACH_23(what, __VA_ARGS__)
        1815 #define _PICOTEST_FOR_EACH_25(what, x, ...) \
        1816  what(x) _PICOTEST_FOR_EACH_24(what, __VA_ARGS__)
        1817 #define _PICOTEST_FOR_EACH_26(what, x, ...) \
        1818  what(x) _PICOTEST_FOR_EACH_25(what, __VA_ARGS__)
        1819 #define _PICOTEST_FOR_EACH_27(what, x, ...) \
        1820  what(x) _PICOTEST_FOR_EACH_26(what, __VA_ARGS__)
        1821 #define _PICOTEST_FOR_EACH_28(what, x, ...) \
        1822  what(x) _PICOTEST_FOR_EACH_27(what, __VA_ARGS__)
        1823 #define _PICOTEST_FOR_EACH_29(what, x, ...) \
        1824  what(x) _PICOTEST_FOR_EACH_28(what, __VA_ARGS__)
        1825 #define _PICOTEST_FOR_EACH_30(what, x, ...) \
        1826  what(x) _PICOTEST_FOR_EACH_29(what, __VA_ARGS__)
        1827 #define _PICOTEST_FOR_EACH_31(what, x, ...) \
        1828  what(x) _PICOTEST_FOR_EACH_30(what, __VA_ARGS__)
        1829 #define _PICOTEST_FOR_EACH_32(what, x, ...) \
        1830  what(x) _PICOTEST_FOR_EACH_31(what, __VA_ARGS__)
        1831 #define _PICOTEST_FOR_EACH_33(what, x, ...) \
        1832  what(x) _PICOTEST_FOR_EACH_32(what, __VA_ARGS__)
        1833 #define _PICOTEST_FOR_EACH_34(what, x, ...) \
        1834  what(x) _PICOTEST_FOR_EACH_33(what, __VA_ARGS__)
        1835 #define _PICOTEST_FOR_EACH_35(what, x, ...) \
        1836  what(x) _PICOTEST_FOR_EACH_34(what, __VA_ARGS__)
        1837 #define _PICOTEST_FOR_EACH_36(what, x, ...) \
        1838  what(x) _PICOTEST_FOR_EACH_35(what, __VA_ARGS__)
        1839 #define _PICOTEST_FOR_EACH_37(what, x, ...) \
        1840  what(x) _PICOTEST_FOR_EACH_36(what, __VA_ARGS__)
        1841 #define _PICOTEST_FOR_EACH_38(what, x, ...) \
        1842  what(x) _PICOTEST_FOR_EACH_37(what, __VA_ARGS__)
        1843 #define _PICOTEST_FOR_EACH_39(what, x, ...) \
        1844  what(x) _PICOTEST_FOR_EACH_38(what, __VA_ARGS__)
        1845 #define _PICOTEST_FOR_EACH_40(what, x, ...) \
        1846  what(x) _PICOTEST_FOR_EACH_39(what, __VA_ARGS__)
        1847 #define _PICOTEST_FOR_EACH_41(what, x, ...) \
        1848  what(x) _PICOTEST_FOR_EACH_40(what, __VA_ARGS__)
        1849 #define _PICOTEST_FOR_EACH_42(what, x, ...) \
        1850  what(x) _PICOTEST_FOR_EACH_41(what, __VA_ARGS__)
        1851 #define _PICOTEST_FOR_EACH_43(what, x, ...) \
        1852  what(x) _PICOTEST_FOR_EACH_42(what, __VA_ARGS__)
        1853 #define _PICOTEST_FOR_EACH_44(what, x, ...) \
        1854  what(x) _PICOTEST_FOR_EACH_43(what, __VA_ARGS__)
        1855 #define _PICOTEST_FOR_EACH_45(what, x, ...) \
        1856  what(x) _PICOTEST_FOR_EACH_44(what, __VA_ARGS__)
        1857 #define _PICOTEST_FOR_EACH_46(what, x, ...) \
        1858  what(x) _PICOTEST_FOR_EACH_45(what, __VA_ARGS__)
        1859 #define _PICOTEST_FOR_EACH_47(what, x, ...) \
        1860  what(x) _PICOTEST_FOR_EACH_46(what, __VA_ARGS__)
        1861 #define _PICOTEST_FOR_EACH_48(what, x, ...) \
        1862  what(x) _PICOTEST_FOR_EACH_47(what, __VA_ARGS__)
        1863 #define _PICOTEST_FOR_EACH_49(what, x, ...) \
        1864  what(x) _PICOTEST_FOR_EACH_48(what, __VA_ARGS__)
        1865 #define _PICOTEST_FOR_EACH_50(what, x, ...) \
        1866  what(x) _PICOTEST_FOR_EACH_49(what, __VA_ARGS__)
        1867 #define _PICOTEST_FOR_EACH_51(what, x, ...) \
        1868  what(x) _PICOTEST_FOR_EACH_50(what, __VA_ARGS__)
        1869 #define _PICOTEST_FOR_EACH_52(what, x, ...) \
        1870  what(x) _PICOTEST_FOR_EACH_51(what, __VA_ARGS__)
        1871 #define _PICOTEST_FOR_EACH_53(what, x, ...) \
        1872  what(x) _PICOTEST_FOR_EACH_52(what, __VA_ARGS__)
        1873 #define _PICOTEST_FOR_EACH_54(what, x, ...) \
        1874  what(x) _PICOTEST_FOR_EACH_53(what, __VA_ARGS__)
        1875 #define _PICOTEST_FOR_EACH_55(what, x, ...) \
        1876  what(x) _PICOTEST_FOR_EACH_54(what, __VA_ARGS__)
        1877 #define _PICOTEST_FOR_EACH_56(what, x, ...) \
        1878  what(x) _PICOTEST_FOR_EACH_55(what, __VA_ARGS__)
        1879 #define _PICOTEST_FOR_EACH_57(what, x, ...) \
        1880  what(x) _PICOTEST_FOR_EACH_56(what, __VA_ARGS__)
        1881 #define _PICOTEST_FOR_EACH_58(what, x, ...) \
        1882  what(x) _PICOTEST_FOR_EACH_57(what, __VA_ARGS__)
        1883 #define _PICOTEST_FOR_EACH_59(what, x, ...) \
        1884  what(x) _PICOTEST_FOR_EACH_58(what, __VA_ARGS__)
        1885 #define _PICOTEST_FOR_EACH_60(what, x, ...) \
        1886  what(x) _PICOTEST_FOR_EACH_59(what, __VA_ARGS__)
        1887 #define _PICOTEST_FOR_EACH_61(what, x, ...) \
        1888  what(x) _PICOTEST_FOR_EACH_60(what, __VA_ARGS__)
        1889 #define _PICOTEST_FOR_EACH_62(what, x, ...) \
        1890  what(x) _PICOTEST_FOR_EACH_61(what, __VA_ARGS__)
        1891 #define _PICOTEST_FOR_EACH_63(what, x, ...) \
        1892  what(x) _PICOTEST_FOR_EACH_62(what, __VA_ARGS__)
        1893 #endif /* defined(_PICOTEST_PARENS) */
        1894 
        1900 #endif /* _PICOTEST */
        Test matches the condition, run this test and all its subtests.
        Definition: picotest.h:131
        +Go to the documentation of this file.
        1 
        48 #ifndef _PICOTEST
        49 #define _PICOTEST
        50 
        51 #include <setjmp.h>
        52 #include <stdarg.h>
        53 #include <string.h>
        54 
        55 #if defined(_MSC_VER)
        56 
        62 #define _PICOTEST_PARENS
        63 #endif /* defined(_MSC_VER) */
        64 
        78 #define PICOTEST_VERSION "1.3.0"
        79 #define PICOTEST_VERSION_MAJOR 1
        80 #define PICOTEST_VERSION_MINOR 3
        81 #define PICOTEST_VERSION_PATCH 0
        82 
        104 typedef int(PicoTestProc)(const char *cond);
        105 
        125 typedef enum PicoTestFilterResult {
        129 
        132 
        136 
        140 
        166  const char *testName,
        167  const char *cond);
        168 
        179 static PicoTestFilterResult _picoTest_filterByName(PicoTestProc *test,
        180  const char *testName,
        181  const char *cond) {
        182  return (strcmp(testName, cond) == 0 ? PICOTEST_FILTER_PASS
        184 }
        185 
        195 #define PICOTEST_FILTER_DEFAULT _picoTest_filterByName
        196 
        221 #define PICOTEST_FILTER PICOTEST_FILTER_DEFAULT
        222 
        249 typedef void(PicoTestTraverseProc)(const char *name, int nb);
        250 
        263 #define PICOTEST_TRAVERSE(_testName, _proc) _testName##_traverse(_proc)
        264 
        295 typedef void(PicoTestFailureLoggerProc)(const char *file, int line,
        296  const char *type, const char *test,
        297  const char *msg, va_list args);
        298 
        306 static void _picoTest_logFailure(const char *file, int line, const char *type,
        307  const char *test, const char *msg,
        308  va_list args) {}
        309 
        316 #define PICOTEST_FAILURE_LOGGER_DEFAULT _picoTest_logFailure
        317 
        337 #define PICOTEST_FAILURE_LOGGER PICOTEST_FAILURE_LOGGER_DEFAULT
        338 
        376 #if defined(_PICOTEST_PARENS)
        377 #define PICOTEST_CASE(...) \
        378  _PICOTEST_CONCATENATE(_PICOTEST_CASE_, _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        379  _PICOTEST_PARENS(__VA_ARGS__)
        380 #else
        381 #define PICOTEST_CASE(...) \
        382  _PICOTEST_CONCATENATE(_PICOTEST_CASE_, _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        383  (__VA_ARGS__)
        384 #endif /* defined(_PICOTEST_PARENS) */
        385 
        387 #define _PICOTEST_CASE_DECLARE(_testName) \
        388  int _testName##_testCaseRunner(void); \
        389  void _testName##_traverse(PicoTestTraverseProc *proc) { \
        390  proc(_PICOTEST_STRINGIZE(_testName), 0); \
        391  } \
        392  int _testName(const char *cond) { \
        393  int fail = 0; \
        394  PicoTestFilterResult filterResult = \
        395  (cond == NULL) \
        396  ? PICOTEST_FILTER_PASS \
        397  : PICOTEST_FILTER(_testName, _PICOTEST_STRINGIZE(_testName), \
        398  cond); \
        399  switch (filterResult) { \
        400  case PICOTEST_FILTER_PASS: \
        401  case PICOTEST_FILTER_PASS_PROPAGATE: \
        402  fail += _testName##_testCaseRunner(); \
        403  break; \
        404  } \
        405  return fail; \
        406  }
        407 
        408 #define _PICOTEST_CASE_RUNNER_BEGIN(_testName) \
        409  int _testName##_testCaseRunner() { \
        410  int abort; \
        411  jmp_buf failureEnv; \
        412  jmp_buf *oldEnv = _picoTest_failureEnv; \
        413  int fail, oldFail = _picoTest_fail; \
        414  _picoTest_failureEnv = &failureEnv; \
        415  _picoTest_fail = 0; \
        416  PICOTEST_CASE_ENTER(_PICOTEST_STRINGIZE(_testName)); \
        417  abort = setjmp(failureEnv);
        418 
        419 #define _PICOTEST_CASE_RUNNER_END(_testName) \
        420  fail = _picoTest_fail; \
        421  PICOTEST_CASE_LEAVE(_PICOTEST_STRINGIZE(_testName), fail); \
        422  _picoTest_failureEnv = oldEnv; \
        423  _picoTest_fail = oldFail; \
        424  return fail; \
        425  }
        426 
        427 #define _PICOTEST_CASE_1(_testName) \
        428  _PICOTEST_CASE_DECLARE(_testName) \
        429  static void _testName##_testCase(void); \
        430  _PICOTEST_CASE_RUNNER_BEGIN(_testName) \
        431  if (!abort) { \
        432  _testName##_testCase(); \
        433  } \
        434  _PICOTEST_CASE_RUNNER_END(_testName) \
        435  static void _testName##_testCase(void)
        436 
        437 #define _PICOTEST_CASE_2(_testName, _fixtureName) \
        438  _PICOTEST_CASE_DECLARE(_testName) \
        439  static void _testName##_testCase(void); \
        440  _PICOTEST_CASE_RUNNER_BEGIN(_testName) \
        441  if (!abort) { \
        442  _PICOTEST_FIXTURE_CALL_SETUP(_fixtureName, _testName, NULL); \
        443  _testName##_testCase(); \
        444  } \
        445  _PICOTEST_FIXTURE_CALL_TEARDOWN(_fixtureName, _testName, NULL, \
        446  _picoTest_fail); \
        447  _PICOTEST_CASE_RUNNER_END(_testName) \
        448  static void _testName##_testCase()
        449 
        450 #define _PICOTEST_CASE_3(_testName, _fixtureName, _context) \
        451  _PICOTEST_CASE_DECLARE(_testName) \
        452  static void _testName##_testCase(struct _fixtureName##_Context *); \
        453  _PICOTEST_CASE_RUNNER_BEGIN(_testName) { \
        454  struct _fixtureName##_Context context; \
        455  if (!abort) { \
        456  _PICOTEST_FIXTURE_CALL_SETUP(_fixtureName, _testName, &context); \
        457  _testName##_testCase(&context); \
        458  } \
        459  _PICOTEST_FIXTURE_CALL_TEARDOWN(_fixtureName, _testName, &context, \
        460  _picoTest_fail); \
        461  } \
        462  _PICOTEST_CASE_RUNNER_END(_testName) \
        463  static void _testName##_testCase(struct _fixtureName##_Context *_context)
        464 
        491 typedef void(PicoTestCaseEnterProc)(const char *testName);
        492 
        499 #define PICOTEST_CASE_ENTER_DEFAULT(testName)
        500 
        521 #define PICOTEST_CASE_ENTER PICOTEST_CASE_ENTER_DEFAULT
        522 
        539 typedef void(PicoTestCaseLeaveProc)(const char *testName, int fail);
        540 
        547 #define PICOTEST_CASE_LEAVE_DEFAULT(testName, fail)
        548 
        569 #define PICOTEST_CASE_LEAVE PICOTEST_CASE_LEAVE_DEFAULT
        570 
        609 #define PICOTEST_ASSERT(x, /* msg, */...) \
        610  { _PICOTEST_ASSERT(x, #x, ##__VA_ARGS__); }
        611 
        613 #define _PICOTEST_ASSERT(x, ...) \
        614  PICOTEST_ASSERT_BEFORE("ASSERT", #x); \
        615  { \
        616  int _PICOTEST_FAIL = !(x); \
        617  PICOTEST_ASSERT_AFTER("ASSERT", #x, _PICOTEST_FAIL); \
        618  if (_PICOTEST_FAIL) { \
        619  PICOTEST_FAILURE("ASSERT", ##__VA_ARGS__); \
        620  PICOTEST_ABORT(); \
        621  } \
        622  }
        623 
        646 #define PICOTEST_VERIFY(x, /* msg, */...) \
        647  { _PICOTEST_VERIFY(x, #x, ##__VA_ARGS__); }
        648 
        650 #define _PICOTEST_VERIFY(x, ...) \
        651  PICOTEST_ASSERT_BEFORE("VERIFY", #x); \
        652  { \
        653  int _PICOTEST_FAIL = !(x); \
        654  PICOTEST_ASSERT_AFTER("VERIFY", #x, _PICOTEST_FAIL); \
        655  if (_PICOTEST_FAIL) { \
        656  PICOTEST_FAILURE("VERIFY", ##__VA_ARGS__); \
        657  } \
        658  }
        659 
        674 #define PICOTEST_FAILURE(type, test, /* msg, */...) \
        675  _PICOTEST_FAILURE(type, test, ##__VA_ARGS__)
        676 
        678 #define _PICOTEST_FAILURE(type, ...) \
        679  _picoTest_fail++; \
        680  _picoTest_assertFailed(PICOTEST_FAILURE_LOGGER, __FILE__, __LINE__, type, \
        681  _PICOTEST_ARGCOUNT(__VA_ARGS__), __VA_ARGS__); \
        682 
        689 static int _picoTest_fail = 0;
        690 
        697 static jmp_buf *_picoTest_failureEnv = NULL;
        698 
        706 #define PICOTEST_ABORT() longjmp(*_picoTest_failureEnv, 1)
        707 
        723 static void _picoTest_assertFailed(PicoTestFailureLoggerProc *proc,
        724  const char *file, int line, const char *type,
        725  int count, const char *test, ...) {
        726  if (count > 1) {
        727  /* Extra args after **test** */
        728  va_list args;
        729  const char *msg;
        730  va_start(args, test);
        731  msg = va_arg(args, const char *);
        732  proc(file, line, type, test, msg, args);
        733  } else {
        734  proc(file, line, type, test, NULL, NULL);
        735  }
        736 }
        737 
        764 typedef void(PicoTestAssertBeforeProc)(const char *type, const char *test);
        765 
        772 #define PICOTEST_ASSERT_BEFORE_DEFAULT(type, test)
        773 
        794 #define PICOTEST_ASSERT_BEFORE PICOTEST_ASSERT_BEFORE_DEFAULT
        795 
        813 typedef void(PicoTestAssertAfterProc)(const char *type, const char *test,
        814  int fail);
        815 
        822 #define PICOTEST_ASSERT_AFTER_DEFAULT(type, test, fail)
        823 
        844 #define PICOTEST_ASSERT_AFTER PICOTEST_ASSERT_AFTER_DEFAULT
        845 
        883 #define PICOTEST_FIXTURE_CONTEXT(_fixtureName) struct _fixtureName##_Context
        884 
        913 #if defined(_PICOTEST_PARENS)
        914 #define PICOTEST_FIXTURE_SETUP(...) \
        915  _PICOTEST_CONCATENATE(_PICOTEST_FIXTURE_SETUP_, \
        916  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        917  _PICOTEST_PARENS(__VA_ARGS__)
        918 #else
        919 #define PICOTEST_FIXTURE_SETUP(...) \
        920  _PICOTEST_CONCATENATE(_PICOTEST_FIXTURE_SETUP_, \
        921  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        922  (__VA_ARGS__)
        923 #endif /* defined(_PICOTEST_PARENS) */
        924 
        926 #define _PICOTEST_FIXTURE_SETUP_1(_fixtureName) \
        927  static void _fixtureName##_setup(void *_fixtureName##_DUMMY)
        928 
        929 #define _PICOTEST_FIXTURE_SETUP_2(_fixtureName, _context) \
        930  static void _fixtureName##_setup(struct _fixtureName##_Context *_context)
        931 
        932 #define _PICOTEST_FIXTURE_CALL_SETUP(_fixtureName, _testName, context) \
        933  PICOTEST_FIXTURE_BEFORE_SETUP(_PICOTEST_STRINGIZE(_fixtureName), \
        934  _PICOTEST_STRINGIZE(_testName)); \
        935  _fixtureName##_setup(context); \
        936  PICOTEST_FIXTURE_AFTER_SETUP(_PICOTEST_STRINGIZE(_fixtureName), \
        937  _PICOTEST_STRINGIZE(_testName));
        938 
        968 #if defined(_PICOTEST_PARENS)
        969 #define PICOTEST_FIXTURE_TEARDOWN(...) \
        970  _PICOTEST_CONCATENATE(_PICOTEST_FIXTURE_TEARDOWN_, \
        971  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        972  _PICOTEST_PARENS(__VA_ARGS__)
        973 #else
        974 #define PICOTEST_FIXTURE_TEARDOWN(...) \
        975  _PICOTEST_CONCATENATE(_PICOTEST_FIXTURE_TEARDOWN_, \
        976  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        977  (__VA_ARGS__)
        978 #endif /* defined(_PICOTEST_PARENS) */
        979 
        981 #define _PICOTEST_FIXTURE_TEARDOWN_1(_fixtureName) \
        982  static void _fixtureName##_teardown(int PICOTEST_FAIL, \
        983  void *_fixtureName##_DUMMY)
        984 
        985 #define _PICOTEST_FIXTURE_TEARDOWN_2(_fixtureName, _context) \
        986  static void _fixtureName##_teardown( \
        987  int PICOTEST_FAIL, struct _fixtureName##_Context *_context)
        988 
        989 #define _PICOTEST_FIXTURE_CALL_TEARDOWN(_fixtureName, _testName, context, \
        990  fail) \
        991  PICOTEST_FIXTURE_BEFORE_TEARDOWN(_PICOTEST_STRINGIZE(_fixtureName), \
        992  _PICOTEST_STRINGIZE(_testName), fail); \
        993  _fixtureName##_teardown(fail, context); \
        994  PICOTEST_FIXTURE_AFTER_TEARDOWN(_PICOTEST_STRINGIZE(_fixtureName), \
        995  _PICOTEST_STRINGIZE(_testName), fail); \
        996 
        1024 typedef void(PicoTestFixtureBeforeSetupProc)(const char *fixtureName,
        1025  const char *testName);
        1026 
        1033 #define PICOTEST_FIXTURE_BEFORE_SETUP_DEFAULT(fixtureName, testName)
        1034 
        1055 #define PICOTEST_FIXTURE_BEFORE_SETUP PICOTEST_FIXTURE_BEFORE_SETUP_DEFAULT
        1056 
        1073 typedef void(PicoTestFixtureAfterSetupProc)(const char *fixtureName,
        1074  const char *testName);
        1075 
        1082 #define PICOTEST_FIXTURE_AFTER_SETUP_DEFAULT(fixtureName, testName)
        1083 
        1104 #define PICOTEST_FIXTURE_AFTER_SETUP PICOTEST_FIXTURE_AFTER_SETUP_DEFAULT
        1105 
        1123 typedef void(PicoTestFixtureBeforeTeardownProc)(const char *fixtureName,
        1124  const char *testName, int fail);
        1125 
        1132 #define PICOTEST_FIXTURE_BEFORE_TEARDOWN_DEFAULT(fixtureName, testName, fail)
        1133 
        1154 #define PICOTEST_FIXTURE_BEFORE_TEARDOWN \
        1155  PICOTEST_FIXTURE_BEFORE_TEARDOWN_DEFAULT
        1156 
        1174 typedef void(PicoTestFixtureAfterTeardownProc)(const char *fixtureName,
        1175  const char *testName, int fail);
        1176 
        1183 #define PICOTEST_FIXTURE_AFTER_TEARDOWN_DEFAULT(fixtureName, testName, fail)
        1184 
        1205 #define PICOTEST_FIXTURE_AFTER_TEARDOWN PICOTEST_FIXTURE_AFTER_TEARDOWN_DEFAULT
        1206 
        1246 #define PICOTEST_SUITE(_suiteName, ...) \
        1247  _PICOTEST_FOR_EACH(_PICOTEST_SUITE_DECLARE_TEST, __VA_ARGS__) \
        1248  static PicoTestDescr _suiteName##_tests[] = {_PICOTEST_FOR_EACH( \
        1249  _PICOTEST_SUITE_DECLARE_TEST_CASE, __VA_ARGS__){NULL, NULL, NULL}}; \
        1250  void _suiteName##_traverse(PicoTestTraverseProc *proc) { \
        1251  const int nb = \
        1252  sizeof(_suiteName##_tests) / sizeof(*_suiteName##_tests) - 1; \
        1253  PicoTestDescr *test = _suiteName##_tests; \
        1254  proc(_PICOTEST_STRINGIZE(_suiteName), nb); \
        1255  for (; test->name; test++) { \
        1256  test->traverse(proc); \
        1257  } \
        1258  } \
        1259  int _suiteName##_testCaseRunner(const char *cond) { \
        1260  const int nb = \
        1261  sizeof(_suiteName##_tests) / sizeof(*_suiteName##_tests) - 1; \
        1262  PicoTestDescr *test = _suiteName##_tests; \
        1263  int fail = 0; \
        1264  PICOTEST_SUITE_ENTER(_PICOTEST_STRINGIZE(_suiteName), nb); \
        1265  for (; test->name; test++) { \
        1266  const int index = (int)(test - _suiteName##_tests); \
        1267  int sfail = 0; \
        1268  PICOTEST_SUITE_BEFORE_SUBTEST(_PICOTEST_STRINGIZE(_suiteName), nb, \
        1269  fail, index, test->name); \
        1270  sfail = test->test(cond); \
        1271  fail += sfail; \
        1272  PICOTEST_SUITE_AFTER_SUBTEST(_PICOTEST_STRINGIZE(_suiteName), nb, \
        1273  fail, index, test->name, sfail); \
        1274  } \
        1275  PICOTEST_SUITE_LEAVE(_PICOTEST_STRINGIZE(_suiteName), nb, fail); \
        1276  return fail; \
        1277  } \
        1278  int _suiteName(const char *cond) { \
        1279  int fail = 0; \
        1280  PicoTestFilterResult filterResult = \
        1281  (cond == NULL) \
        1282  ? PICOTEST_FILTER_PASS \
        1283  : PICOTEST_FILTER(_suiteName, _PICOTEST_STRINGIZE(_suiteName), \
        1284  cond); \
        1285  switch (filterResult) { \
        1286  case PICOTEST_FILTER_PASS: \
        1287  cond = NULL; \
        1288  case PICOTEST_FILTER_PASS_PROPAGATE: \
        1289  fail += _suiteName##_testCaseRunner(cond); \
        1290  break; \
        1291  case PICOTEST_FILTER_SKIP: \
        1292  break; \
        1293  case PICOTEST_FILTER_SKIP_PROPAGATE: { \
        1294  PicoTestDescr *test = _suiteName##_tests; \
        1295  for (; test->name; test++) { \
        1296  fail += test->test(cond); \
        1297  } \
        1298  } break; \
        1299  } \
        1300  return fail; \
        1301  }
        1302 
        1304 #define _PICOTEST_SUITE_DECLARE_TEST_CASE(_testName) \
        1305  {_PICOTEST_STRINGIZE(_testName), _testName, _testName##_traverse},
        1306 #define _PICOTEST_SUITE_DECLARE_TEST(_testName) \
        1307  int _testName(const char *); \
        1308  void _testName##_traverse(PicoTestTraverseProc *);
        1309 
        1311 typedef struct PicoTestDescr {
        1312  const char *name;
        1313  PicoTestProc *test;
        1314  void (*traverse)(PicoTestTraverseProc *);
        1315 } PicoTestDescr;
        1345 typedef void(PicoTestSuiteEnterProc)(const char *suiteName, int nb);
        1346 
        1353 #define PICOTEST_SUITE_ENTER_DEFAULT(suiteName, nb)
        1354 
        1375 #define PICOTEST_SUITE_ENTER PICOTEST_SUITE_ENTER_DEFAULT
        1376 
        1393 typedef void(PicoTestSuiteLeaveProc)(const char *suiteName, int nb, int fail);
        1394 
        1401 #define PICOTEST_SUITE_LEAVE_DEFAULT(suiteName, nb, fail)
        1402 
        1425 #define PICOTEST_SUITE_LEAVE PICOTEST_SUITE_LEAVE_DEFAULT
        1426 
        1447 typedef void(PicoTestSuiteBeforeSubtestProc)(const char *suiteName, int nb,
        1448  int fail, int index,
        1449  const char *testName);
        1450 
        1457 #define PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT(suiteName, nb, fail, index, \
        1458  testName)
        1459 
        1480 #define PICOTEST_SUITE_BEFORE_SUBTEST PICOTEST_SUITE_BEFORE_SUBTEST_DEFAULT
        1481 
        1504 typedef void(PicoTestSuiteAfterSubtestProc)(const char *suiteName, int nb,
        1505  int fail, int index,
        1506  const char *testName, int sfail);
        1507 
        1514 #define PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT(suiteName, nb, fail, index, \
        1515  testName, sfail)
        1516 
        1537 #define PICOTEST_SUITE_AFTER_SUBTEST PICOTEST_SUITE_AFTER_SUBTEST_DEFAULT
        1538 
        1560 #define _PICOTEST_STRINGIZE(arg) #arg
        1561 
        1565 #define _PICOTEST_CONCATENATE(arg1, arg2) _PICOTEST_CONCATENATE1(arg1, arg2)
        1566 
        1568 #define _PICOTEST_CONCATENATE1(arg1, arg2) _PICOTEST_CONCATENATE2(arg1, arg2)
        1569 #define _PICOTEST_CONCATENATE2(arg1, arg2) arg1##arg2
        1570 
        1592 #if defined(_PICOTEST_PARENS)
        1593 #define _PICOTEST_ARGCOUNT(...) \
        1594  _PICOTEST_LASTARG _PICOTEST_PARENS( \
        1595  __VA_ARGS__, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, \
        1596  49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, \
        1597  32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, \
        1598  15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
        1599 #else
        1600 #define _PICOTEST_ARGCOUNT(...) \
        1601  _PICOTEST_LASTARG(__VA_ARGS__, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, \
        1602  52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, \
        1603  38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, \
        1604  24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \
        1605  10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
        1606 #endif /* defined(_PICOTEST_PARENS) */
        1607 
        1609 #define _PICOTEST_LASTARG( \
        1610  _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, \
        1611  _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, \
        1612  _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, \
        1613  _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, \
        1614  _62, _63, N, ...) \
        1615  N
        1616 
        1628 #if defined(_PICOTEST_PARENS)
        1629 #define _PICOTEST_FOR_EACH(what, ...) \
        1630  _PICOTEST_CONCATENATE(_PICOTEST_FOR_EACH_, \
        1631  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        1632  _PICOTEST_PARENS(what, __VA_ARGS__)
        1633 #else
        1634 #define _PICOTEST_FOR_EACH(what, ...) \
        1635  _PICOTEST_CONCATENATE(_PICOTEST_FOR_EACH_, \
        1636  _PICOTEST_ARGCOUNT(__VA_ARGS__)) \
        1637  (what, __VA_ARGS__)
        1638 #endif /* defined(_PICOTEST_PARENS) */
        1639 
        1641 #if defined(_PICOTEST_PARENS)
        1642 #define _PICOTEST_FOR_EACH_1(what, x) what(x)
        1643 #define _PICOTEST_FOR_EACH_2(what, x, ...) \
        1644  what(x) _PICOTEST_FOR_EACH_1 _PICOTEST_PARENS(what, __VA_ARGS__)
        1645 #define _PICOTEST_FOR_EACH_3(what, x, ...) \
        1646  what(x) _PICOTEST_FOR_EACH_2 _PICOTEST_PARENS(what, __VA_ARGS__)
        1647 #define _PICOTEST_FOR_EACH_4(what, x, ...) \
        1648  what(x) _PICOTEST_FOR_EACH_3 _PICOTEST_PARENS(what, __VA_ARGS__)
        1649 #define _PICOTEST_FOR_EACH_5(what, x, ...) \
        1650  what(x) _PICOTEST_FOR_EACH_4 _PICOTEST_PARENS(what, __VA_ARGS__)
        1651 #define _PICOTEST_FOR_EACH_6(what, x, ...) \
        1652  what(x) _PICOTEST_FOR_EACH_5 _PICOTEST_PARENS(what, __VA_ARGS__)
        1653 #define _PICOTEST_FOR_EACH_7(what, x, ...) \
        1654  what(x) _PICOTEST_FOR_EACH_6 _PICOTEST_PARENS(what, __VA_ARGS__)
        1655 #define _PICOTEST_FOR_EACH_8(what, x, ...) \
        1656  what(x) _PICOTEST_FOR_EACH_7 _PICOTEST_PARENS(what, __VA_ARGS__)
        1657 #define _PICOTEST_FOR_EACH_9(what, x, ...) \
        1658  what(x) _PICOTEST_FOR_EACH_8 _PICOTEST_PARENS(what, __VA_ARGS__)
        1659 #define _PICOTEST_FOR_EACH_10(what, x, ...) \
        1660  what(x) _PICOTEST_FOR_EACH_9 _PICOTEST_PARENS(what, __VA_ARGS__)
        1661 #define _PICOTEST_FOR_EACH_11(what, x, ...) \
        1662  what(x) _PICOTEST_FOR_EACH_10 _PICOTEST_PARENS(what, __VA_ARGS__)
        1663 #define _PICOTEST_FOR_EACH_12(what, x, ...) \
        1664  what(x) _PICOTEST_FOR_EACH_11 _PICOTEST_PARENS(what, __VA_ARGS__)
        1665 #define _PICOTEST_FOR_EACH_13(what, x, ...) \
        1666  what(x) _PICOTEST_FOR_EACH_12 _PICOTEST_PARENS(what, __VA_ARGS__)
        1667 #define _PICOTEST_FOR_EACH_14(what, x, ...) \
        1668  what(x) _PICOTEST_FOR_EACH_13 _PICOTEST_PARENS(what, __VA_ARGS__)
        1669 #define _PICOTEST_FOR_EACH_15(what, x, ...) \
        1670  what(x) _PICOTEST_FOR_EACH_14 _PICOTEST_PARENS(what, __VA_ARGS__)
        1671 #define _PICOTEST_FOR_EACH_16(what, x, ...) \
        1672  what(x) _PICOTEST_FOR_EACH_15 _PICOTEST_PARENS(what, __VA_ARGS__)
        1673 #define _PICOTEST_FOR_EACH_17(what, x, ...) \
        1674  what(x) _PICOTEST_FOR_EACH_16 _PICOTEST_PARENS(what, __VA_ARGS__)
        1675 #define _PICOTEST_FOR_EACH_18(what, x, ...) \
        1676  what(x) _PICOTEST_FOR_EACH_17 _PICOTEST_PARENS(what, __VA_ARGS__)
        1677 #define _PICOTEST_FOR_EACH_19(what, x, ...) \
        1678  what(x) _PICOTEST_FOR_EACH_18 _PICOTEST_PARENS(what, __VA_ARGS__)
        1679 #define _PICOTEST_FOR_EACH_20(what, x, ...) \
        1680  what(x) _PICOTEST_FOR_EACH_19 _PICOTEST_PARENS(what, __VA_ARGS__)
        1681 #define _PICOTEST_FOR_EACH_21(what, x, ...) \
        1682  what(x) _PICOTEST_FOR_EACH_20 _PICOTEST_PARENS(what, __VA_ARGS__)
        1683 #define _PICOTEST_FOR_EACH_22(what, x, ...) \
        1684  what(x) _PICOTEST_FOR_EACH_21 _PICOTEST_PARENS(what, __VA_ARGS__)
        1685 #define _PICOTEST_FOR_EACH_23(what, x, ...) \
        1686  what(x) _PICOTEST_FOR_EACH_22 _PICOTEST_PARENS(what, __VA_ARGS__)
        1687 #define _PICOTEST_FOR_EACH_24(what, x, ...) \
        1688  what(x) _PICOTEST_FOR_EACH_23 _PICOTEST_PARENS(what, __VA_ARGS__)
        1689 #define _PICOTEST_FOR_EACH_25(what, x, ...) \
        1690  what(x) _PICOTEST_FOR_EACH_24 _PICOTEST_PARENS(what, __VA_ARGS__)
        1691 #define _PICOTEST_FOR_EACH_26(what, x, ...) \
        1692  what(x) _PICOTEST_FOR_EACH_25 _PICOTEST_PARENS(what, __VA_ARGS__)
        1693 #define _PICOTEST_FOR_EACH_27(what, x, ...) \
        1694  what(x) _PICOTEST_FOR_EACH_26 _PICOTEST_PARENS(what, __VA_ARGS__)
        1695 #define _PICOTEST_FOR_EACH_28(what, x, ...) \
        1696  what(x) _PICOTEST_FOR_EACH_27 _PICOTEST_PARENS(what, __VA_ARGS__)
        1697 #define _PICOTEST_FOR_EACH_29(what, x, ...) \
        1698  what(x) _PICOTEST_FOR_EACH_28 _PICOTEST_PARENS(what, __VA_ARGS__)
        1699 #define _PICOTEST_FOR_EACH_30(what, x, ...) \
        1700  what(x) _PICOTEST_FOR_EACH_29 _PICOTEST_PARENS(what, __VA_ARGS__)
        1701 #define _PICOTEST_FOR_EACH_31(what, x, ...) \
        1702  what(x) _PICOTEST_FOR_EACH_30 _PICOTEST_PARENS(what, __VA_ARGS__)
        1703 #define _PICOTEST_FOR_EACH_32(what, x, ...) \
        1704  what(x) _PICOTEST_FOR_EACH_31 _PICOTEST_PARENS(what, __VA_ARGS__)
        1705 #define _PICOTEST_FOR_EACH_33(what, x, ...) \
        1706  what(x) _PICOTEST_FOR_EACH_32 _PICOTEST_PARENS(what, __VA_ARGS__)
        1707 #define _PICOTEST_FOR_EACH_34(what, x, ...) \
        1708  what(x) _PICOTEST_FOR_EACH_33 _PICOTEST_PARENS(what, __VA_ARGS__)
        1709 #define _PICOTEST_FOR_EACH_35(what, x, ...) \
        1710  what(x) _PICOTEST_FOR_EACH_34 _PICOTEST_PARENS(what, __VA_ARGS__)
        1711 #define _PICOTEST_FOR_EACH_36(what, x, ...) \
        1712  what(x) _PICOTEST_FOR_EACH_35 _PICOTEST_PARENS(what, __VA_ARGS__)
        1713 #define _PICOTEST_FOR_EACH_37(what, x, ...) \
        1714  what(x) _PICOTEST_FOR_EACH_36 _PICOTEST_PARENS(what, __VA_ARGS__)
        1715 #define _PICOTEST_FOR_EACH_38(what, x, ...) \
        1716  what(x) _PICOTEST_FOR_EACH_37 _PICOTEST_PARENS(what, __VA_ARGS__)
        1717 #define _PICOTEST_FOR_EACH_39(what, x, ...) \
        1718  what(x) _PICOTEST_FOR_EACH_38 _PICOTEST_PARENS(what, __VA_ARGS__)
        1719 #define _PICOTEST_FOR_EACH_40(what, x, ...) \
        1720  what(x) _PICOTEST_FOR_EACH_39 _PICOTEST_PARENS(what, __VA_ARGS__)
        1721 #define _PICOTEST_FOR_EACH_41(what, x, ...) \
        1722  what(x) _PICOTEST_FOR_EACH_40 _PICOTEST_PARENS(what, __VA_ARGS__)
        1723 #define _PICOTEST_FOR_EACH_42(what, x, ...) \
        1724  what(x) _PICOTEST_FOR_EACH_41 _PICOTEST_PARENS(what, __VA_ARGS__)
        1725 #define _PICOTEST_FOR_EACH_43(what, x, ...) \
        1726  what(x) _PICOTEST_FOR_EACH_42 _PICOTEST_PARENS(what, __VA_ARGS__)
        1727 #define _PICOTEST_FOR_EACH_44(what, x, ...) \
        1728  what(x) _PICOTEST_FOR_EACH_43 _PICOTEST_PARENS(what, __VA_ARGS__)
        1729 #define _PICOTEST_FOR_EACH_45(what, x, ...) \
        1730  what(x) _PICOTEST_FOR_EACH_44 _PICOTEST_PARENS(what, __VA_ARGS__)
        1731 #define _PICOTEST_FOR_EACH_46(what, x, ...) \
        1732  what(x) _PICOTEST_FOR_EACH_45 _PICOTEST_PARENS(what, __VA_ARGS__)
        1733 #define _PICOTEST_FOR_EACH_47(what, x, ...) \
        1734  what(x) _PICOTEST_FOR_EACH_46 _PICOTEST_PARENS(what, __VA_ARGS__)
        1735 #define _PICOTEST_FOR_EACH_48(what, x, ...) \
        1736  what(x) _PICOTEST_FOR_EACH_47 _PICOTEST_PARENS(what, __VA_ARGS__)
        1737 #define _PICOTEST_FOR_EACH_49(what, x, ...) \
        1738  what(x) _PICOTEST_FOR_EACH_48 _PICOTEST_PARENS(what, __VA_ARGS__)
        1739 #define _PICOTEST_FOR_EACH_50(what, x, ...) \
        1740  what(x) _PICOTEST_FOR_EACH_49 _PICOTEST_PARENS(what, __VA_ARGS__)
        1741 #define _PICOTEST_FOR_EACH_51(what, x, ...) \
        1742  what(x) _PICOTEST_FOR_EACH_50 _PICOTEST_PARENS(what, __VA_ARGS__)
        1743 #define _PICOTEST_FOR_EACH_52(what, x, ...) \
        1744  what(x) _PICOTEST_FOR_EACH_51 _PICOTEST_PARENS(what, __VA_ARGS__)
        1745 #define _PICOTEST_FOR_EACH_53(what, x, ...) \
        1746  what(x) _PICOTEST_FOR_EACH_52 _PICOTEST_PARENS(what, __VA_ARGS__)
        1747 #define _PICOTEST_FOR_EACH_54(what, x, ...) \
        1748  what(x) _PICOTEST_FOR_EACH_53 _PICOTEST_PARENS(what, __VA_ARGS__)
        1749 #define _PICOTEST_FOR_EACH_55(what, x, ...) \
        1750  what(x) _PICOTEST_FOR_EACH_54 _PICOTEST_PARENS(what, __VA_ARGS__)
        1751 #define _PICOTEST_FOR_EACH_56(what, x, ...) \
        1752  what(x) _PICOTEST_FOR_EACH_55 _PICOTEST_PARENS(what, __VA_ARGS__)
        1753 #define _PICOTEST_FOR_EACH_57(what, x, ...) \
        1754  what(x) _PICOTEST_FOR_EACH_56 _PICOTEST_PARENS(what, __VA_ARGS__)
        1755 #define _PICOTEST_FOR_EACH_58(what, x, ...) \
        1756  what(x) _PICOTEST_FOR_EACH_57 _PICOTEST_PARENS(what, __VA_ARGS__)
        1757 #define _PICOTEST_FOR_EACH_59(what, x, ...) \
        1758  what(x) _PICOTEST_FOR_EACH_58 _PICOTEST_PARENS(what, __VA_ARGS__)
        1759 #define _PICOTEST_FOR_EACH_60(what, x, ...) \
        1760  what(x) _PICOTEST_FOR_EACH_59 _PICOTEST_PARENS(what, __VA_ARGS__)
        1761 #define _PICOTEST_FOR_EACH_61(what, x, ...) \
        1762  what(x) _PICOTEST_FOR_EACH_60 _PICOTEST_PARENS(what, __VA_ARGS__)
        1763 #define _PICOTEST_FOR_EACH_62(what, x, ...) \
        1764  what(x) _PICOTEST_FOR_EACH_61 _PICOTEST_PARENS(what, __VA_ARGS__)
        1765 #define _PICOTEST_FOR_EACH_63(what, x, ...) \
        1766  what(x) _PICOTEST_FOR_EACH_62 _PICOTEST_PARENS(what, __VA_ARGS__)
        1767 #else
        1768 #define _PICOTEST_FOR_EACH_1(what, x) what(x)
        1769 #define _PICOTEST_FOR_EACH_2(what, x, ...) \
        1770  what(x) _PICOTEST_FOR_EACH_1(what, __VA_ARGS__)
        1771 #define _PICOTEST_FOR_EACH_3(what, x, ...) \
        1772  what(x) _PICOTEST_FOR_EACH_2(what, __VA_ARGS__)
        1773 #define _PICOTEST_FOR_EACH_4(what, x, ...) \
        1774  what(x) _PICOTEST_FOR_EACH_3(what, __VA_ARGS__)
        1775 #define _PICOTEST_FOR_EACH_5(what, x, ...) \
        1776  what(x) _PICOTEST_FOR_EACH_4(what, __VA_ARGS__)
        1777 #define _PICOTEST_FOR_EACH_6(what, x, ...) \
        1778  what(x) _PICOTEST_FOR_EACH_5(what, __VA_ARGS__)
        1779 #define _PICOTEST_FOR_EACH_7(what, x, ...) \
        1780  what(x) _PICOTEST_FOR_EACH_6(what, __VA_ARGS__)
        1781 #define _PICOTEST_FOR_EACH_8(what, x, ...) \
        1782  what(x) _PICOTEST_FOR_EACH_7(what, __VA_ARGS__)
        1783 #define _PICOTEST_FOR_EACH_9(what, x, ...) \
        1784  what(x) _PICOTEST_FOR_EACH_8(what, __VA_ARGS__)
        1785 #define _PICOTEST_FOR_EACH_10(what, x, ...) \
        1786  what(x) _PICOTEST_FOR_EACH_9(what, __VA_ARGS__)
        1787 #define _PICOTEST_FOR_EACH_11(what, x, ...) \
        1788  what(x) _PICOTEST_FOR_EACH_10(what, __VA_ARGS__)
        1789 #define _PICOTEST_FOR_EACH_12(what, x, ...) \
        1790  what(x) _PICOTEST_FOR_EACH_11(what, __VA_ARGS__)
        1791 #define _PICOTEST_FOR_EACH_13(what, x, ...) \
        1792  what(x) _PICOTEST_FOR_EACH_12(what, __VA_ARGS__)
        1793 #define _PICOTEST_FOR_EACH_14(what, x, ...) \
        1794  what(x) _PICOTEST_FOR_EACH_13(what, __VA_ARGS__)
        1795 #define _PICOTEST_FOR_EACH_15(what, x, ...) \
        1796  what(x) _PICOTEST_FOR_EACH_14(what, __VA_ARGS__)
        1797 #define _PICOTEST_FOR_EACH_16(what, x, ...) \
        1798  what(x) _PICOTEST_FOR_EACH_15(what, __VA_ARGS__)
        1799 #define _PICOTEST_FOR_EACH_17(what, x, ...) \
        1800  what(x) _PICOTEST_FOR_EACH_16(what, __VA_ARGS__)
        1801 #define _PICOTEST_FOR_EACH_18(what, x, ...) \
        1802  what(x) _PICOTEST_FOR_EACH_17(what, __VA_ARGS__)
        1803 #define _PICOTEST_FOR_EACH_19(what, x, ...) \
        1804  what(x) _PICOTEST_FOR_EACH_18(what, __VA_ARGS__)
        1805 #define _PICOTEST_FOR_EACH_20(what, x, ...) \
        1806  what(x) _PICOTEST_FOR_EACH_19(what, __VA_ARGS__)
        1807 #define _PICOTEST_FOR_EACH_21(what, x, ...) \
        1808  what(x) _PICOTEST_FOR_EACH_20(what, __VA_ARGS__)
        1809 #define _PICOTEST_FOR_EACH_22(what, x, ...) \
        1810  what(x) _PICOTEST_FOR_EACH_21(what, __VA_ARGS__)
        1811 #define _PICOTEST_FOR_EACH_23(what, x, ...) \
        1812  what(x) _PICOTEST_FOR_EACH_22(what, __VA_ARGS__)
        1813 #define _PICOTEST_FOR_EACH_24(what, x, ...) \
        1814  what(x) _PICOTEST_FOR_EACH_23(what, __VA_ARGS__)
        1815 #define _PICOTEST_FOR_EACH_25(what, x, ...) \
        1816  what(x) _PICOTEST_FOR_EACH_24(what, __VA_ARGS__)
        1817 #define _PICOTEST_FOR_EACH_26(what, x, ...) \
        1818  what(x) _PICOTEST_FOR_EACH_25(what, __VA_ARGS__)
        1819 #define _PICOTEST_FOR_EACH_27(what, x, ...) \
        1820  what(x) _PICOTEST_FOR_EACH_26(what, __VA_ARGS__)
        1821 #define _PICOTEST_FOR_EACH_28(what, x, ...) \
        1822  what(x) _PICOTEST_FOR_EACH_27(what, __VA_ARGS__)
        1823 #define _PICOTEST_FOR_EACH_29(what, x, ...) \
        1824  what(x) _PICOTEST_FOR_EACH_28(what, __VA_ARGS__)
        1825 #define _PICOTEST_FOR_EACH_30(what, x, ...) \
        1826  what(x) _PICOTEST_FOR_EACH_29(what, __VA_ARGS__)
        1827 #define _PICOTEST_FOR_EACH_31(what, x, ...) \
        1828  what(x) _PICOTEST_FOR_EACH_30(what, __VA_ARGS__)
        1829 #define _PICOTEST_FOR_EACH_32(what, x, ...) \
        1830  what(x) _PICOTEST_FOR_EACH_31(what, __VA_ARGS__)
        1831 #define _PICOTEST_FOR_EACH_33(what, x, ...) \
        1832  what(x) _PICOTEST_FOR_EACH_32(what, __VA_ARGS__)
        1833 #define _PICOTEST_FOR_EACH_34(what, x, ...) \
        1834  what(x) _PICOTEST_FOR_EACH_33(what, __VA_ARGS__)
        1835 #define _PICOTEST_FOR_EACH_35(what, x, ...) \
        1836  what(x) _PICOTEST_FOR_EACH_34(what, __VA_ARGS__)
        1837 #define _PICOTEST_FOR_EACH_36(what, x, ...) \
        1838  what(x) _PICOTEST_FOR_EACH_35(what, __VA_ARGS__)
        1839 #define _PICOTEST_FOR_EACH_37(what, x, ...) \
        1840  what(x) _PICOTEST_FOR_EACH_36(what, __VA_ARGS__)
        1841 #define _PICOTEST_FOR_EACH_38(what, x, ...) \
        1842  what(x) _PICOTEST_FOR_EACH_37(what, __VA_ARGS__)
        1843 #define _PICOTEST_FOR_EACH_39(what, x, ...) \
        1844  what(x) _PICOTEST_FOR_EACH_38(what, __VA_ARGS__)
        1845 #define _PICOTEST_FOR_EACH_40(what, x, ...) \
        1846  what(x) _PICOTEST_FOR_EACH_39(what, __VA_ARGS__)
        1847 #define _PICOTEST_FOR_EACH_41(what, x, ...) \
        1848  what(x) _PICOTEST_FOR_EACH_40(what, __VA_ARGS__)
        1849 #define _PICOTEST_FOR_EACH_42(what, x, ...) \
        1850  what(x) _PICOTEST_FOR_EACH_41(what, __VA_ARGS__)
        1851 #define _PICOTEST_FOR_EACH_43(what, x, ...) \
        1852  what(x) _PICOTEST_FOR_EACH_42(what, __VA_ARGS__)
        1853 #define _PICOTEST_FOR_EACH_44(what, x, ...) \
        1854  what(x) _PICOTEST_FOR_EACH_43(what, __VA_ARGS__)
        1855 #define _PICOTEST_FOR_EACH_45(what, x, ...) \
        1856  what(x) _PICOTEST_FOR_EACH_44(what, __VA_ARGS__)
        1857 #define _PICOTEST_FOR_EACH_46(what, x, ...) \
        1858  what(x) _PICOTEST_FOR_EACH_45(what, __VA_ARGS__)
        1859 #define _PICOTEST_FOR_EACH_47(what, x, ...) \
        1860  what(x) _PICOTEST_FOR_EACH_46(what, __VA_ARGS__)
        1861 #define _PICOTEST_FOR_EACH_48(what, x, ...) \
        1862  what(x) _PICOTEST_FOR_EACH_47(what, __VA_ARGS__)
        1863 #define _PICOTEST_FOR_EACH_49(what, x, ...) \
        1864  what(x) _PICOTEST_FOR_EACH_48(what, __VA_ARGS__)
        1865 #define _PICOTEST_FOR_EACH_50(what, x, ...) \
        1866  what(x) _PICOTEST_FOR_EACH_49(what, __VA_ARGS__)
        1867 #define _PICOTEST_FOR_EACH_51(what, x, ...) \
        1868  what(x) _PICOTEST_FOR_EACH_50(what, __VA_ARGS__)
        1869 #define _PICOTEST_FOR_EACH_52(what, x, ...) \
        1870  what(x) _PICOTEST_FOR_EACH_51(what, __VA_ARGS__)
        1871 #define _PICOTEST_FOR_EACH_53(what, x, ...) \
        1872  what(x) _PICOTEST_FOR_EACH_52(what, __VA_ARGS__)
        1873 #define _PICOTEST_FOR_EACH_54(what, x, ...) \
        1874  what(x) _PICOTEST_FOR_EACH_53(what, __VA_ARGS__)
        1875 #define _PICOTEST_FOR_EACH_55(what, x, ...) \
        1876  what(x) _PICOTEST_FOR_EACH_54(what, __VA_ARGS__)
        1877 #define _PICOTEST_FOR_EACH_56(what, x, ...) \
        1878  what(x) _PICOTEST_FOR_EACH_55(what, __VA_ARGS__)
        1879 #define _PICOTEST_FOR_EACH_57(what, x, ...) \
        1880  what(x) _PICOTEST_FOR_EACH_56(what, __VA_ARGS__)
        1881 #define _PICOTEST_FOR_EACH_58(what, x, ...) \
        1882  what(x) _PICOTEST_FOR_EACH_57(what, __VA_ARGS__)
        1883 #define _PICOTEST_FOR_EACH_59(what, x, ...) \
        1884  what(x) _PICOTEST_FOR_EACH_58(what, __VA_ARGS__)
        1885 #define _PICOTEST_FOR_EACH_60(what, x, ...) \
        1886  what(x) _PICOTEST_FOR_EACH_59(what, __VA_ARGS__)
        1887 #define _PICOTEST_FOR_EACH_61(what, x, ...) \
        1888  what(x) _PICOTEST_FOR_EACH_60(what, __VA_ARGS__)
        1889 #define _PICOTEST_FOR_EACH_62(what, x, ...) \
        1890  what(x) _PICOTEST_FOR_EACH_61(what, __VA_ARGS__)
        1891 #define _PICOTEST_FOR_EACH_63(what, x, ...) \
        1892  what(x) _PICOTEST_FOR_EACH_62(what, __VA_ARGS__)
        1893 #endif /* defined(_PICOTEST_PARENS) */
        1894 
        1900 #endif /* _PICOTEST */
        Test matches the condition, run this test and all its subtests.
        Definition: picotest.h:131
        void() PicoTestSuiteAfterSubtestProc(const char *suiteName, int nb, int fail, int index, const char *testName, int sfail)
        Function signature of test suite after subtest hooks.
        Definition: picotest.h:1504
        void() PicoTestTraverseProc(const char *name, int nb)
        Function signature of test traversal proc.
        Definition: picotest.h:249
        PicoTestFilterResult() PicoTestFilterProc(PicoTestProc *test, const char *testName, const char *cond)
        Signature of test filter functions.
        Definition: picotest.h:165
        diff --git a/docs/xml/_r_e_a_d_m_e_8md.xml b/docs/xml/_r_e_a_d_m_e_8md.xml index 0eaaa9e..80a474f 100644 --- a/docs/xml/_r_e_a_d_m_e_8md.xml +++ b/docs/xml/_r_e_a_d_m_e_8md.xml @@ -14,21 +14,18 @@ https://en.wikipedia.org/wiki/XUnit - ##License PicoTestisreleasedunderthetermsoftheThe3-ClauseBSDLicense: https://opensource.org/licenses/BSD-3-Clause - ##Installation PicoTestisasingle-filepackage,everythingisdefinedintheheaderfile `picotest.h`.Soyoucaneitherinstallthisfileinastandardlocation,or copyitwithinyourprojectsourcetree. - ##Usage Simplyincludethefileinyoursourcefile,thenstartwritingyourtests! @@ -51,7 +48,6 @@ Youcanrebuildthedocumentationfromscratchusingtheprovided`Doxyfile` file. - ##Examples The`examples`subdirectorycontainsseveralexamplesourcefilesthat @@ -63,10 +59,38 @@ https://cmake.org/ +##Tests + +PicoTestisself-testedandcomeswithacompletetestsuitethatcoversall +aspectsoftheframework.ThisguaranteesthatPicoTestisproduction-ready. + +Thetestsuiteitselfisagoodreal-worldexampleofPicoTestinaction. + +BuildingandrunningthetestsuiterequiresCMake(seenextsectionformore +information).Tobuildthesuite: + +```sh +cdtests +cmake-S.-Bbuild +cmake--buildbuild +``` + +Thebuildprocessmakesuseofthetestdiscoverymechanismdescribedinthe +nextsection. + +TorunthesuiteusingCTest: + +```sh +cdtests/build +ctest +``` + +Youcanalsorunthesuiteexecutable`test_picotest`directlyfromtheCMake +outputdirectory. ##IntegrationwithCMake -PicoTestprovidesaCMakemoduledefinitionforeasierintegrationwith +PicoTestprovidesaCMakemoduledefinitionforeasierintegrationwith otherCMakeprojects.Inparticular,itcomeswithanauto-discoveryscriptfor CTestthatmakesuseofthetesttraversalfeaturesofPicoTest. @@ -75,7 +99,7 @@ ```cmake find_package(PicoTest) -``` +``` Youcanthenaddthe`PicoTest`dependencytoyourtargets,e.g.: @@ -84,9 +108,10 @@ target_link_libraries(my_test_runner PRIVATEPicoTest ) -``` +``` -IfyoualsouseCTestfortestautomationwith`enable_testing()`,youcanalsocalltheprovided`picotest_discover_tests`macrotointegratePicoTesttest +IfyoualsouseCTestfortestautomationwith`enable_testing()`,youcanalso +calltheprovided`picotest_discover_tests`macrotointegratePicoTesttest casesinyourbuildprocessautomatically.Forexample,assumingthatthe `my_test_runner`executable: @@ -95,7 +120,8 @@ -whenpassed`<test_name>`,willexecutethematchingtestcase. Thenthefollowinglineswill: -1.execute`my_test_runner-l`asapost-buildcommandto`my_test_runner`, + +1.execute`my_test_runner-l`asapost-buildcommandto`my_test_runner`, 2.addeachdiscoveredtestcaseusing`add_test(<test_name>)`, 3.wheninvokingthe`test`rule,executeeachtestunitarilywith `my_test_runner<test_name>`. @@ -105,8 +131,7 @@ picotest_discover_tests(my_test_runner TEST_LIST_OPTION"-l" ) -``` - +``` ##Development @@ -114,11 +139,12 @@ tools: -IDE:VisualStudioCode --Buildtool:CMake3.11.0 +-Buildtool:CMake3.15.2 -Windowstoolchain:MicrosoftVisualC++BuildTools14 -Linuxtoolchain:GCC5.4.0 -ItshouldworkwithanyreasonablymodernCcompilerthatsupportsvariadicmacros. +ItshouldworkwithanyreasonablymodernCcompilerthatsupportsvariadic +macros. Theassertionmechanismrelieson`setjmp()`/`longjmp()`.Whilethese functionsarediscouragedforproductioncode,theirusageisacceptableinthe diff --git a/docs/xml/indexpage.xml b/docs/xml/indexpage.xml index 7c94b85..c57144c 100644 --- a/docs/xml/indexpage.xml +++ b/docs/xml/indexpage.xml @@ -32,6 +32,21 @@ The examples subdirectory contains several example source files that demonstrate the various features of PicoTest. These examples are also integrated in the documentation. Building the examples requires the CMake build tool along with your favorite toolchain: https://cmake.org/ +Tests + +PicoTest is self-tested and comes with a complete test suite that covers all aspects of the framework. This guarantees that PicoTest is production-ready. +The test suite itself is a good real-world example of PicoTest in action. +Building and running the test suite requires CMake (see next section for more information). To build the suite: +cdtests +cmake-S.-Bbuild +cmake--buildbuild + +The build process makes use of the test discovery mechanism described in the next section. +To run the suite using CTest: +cdtests/build +ctest + +You can also run the suite executable test_picotest directly from the CMake output directory. Integration with CMake PicoTest provides a CMake module definition for easier integration with other CMake projects. In particular, it comes with an auto-discovery script for CTest that makes use of the test traversal features of PicoTest. @@ -50,7 +65,8 @@ when passed <test_name>, will execute the matching test case. -Then the following lines will: +Then the following lines will: + execute my_test_runner -l as a post-build command to my_test_runner, add each discovered test case using add_test(<test_name>), when invoking the test rule, execute each test unitarily with my_test_runner <test_name>. @@ -66,7 +82,7 @@ PicoTest was developed on Windows 10 and Linux Ubuntu 16.04 using the following tools: IDE: Visual Studio Code -Build tool: CMake 3.11.0 +Build tool: CMake 3.15.2 Windows toolchain: Microsoft Visual C++ Build Tools 14 Linux toolchain: GCC 5.4.0 diff --git a/docs/xml/picotest_8h.xml b/docs/xml/picotest_8h.xml index 1dc4844..fbdf397 100644 --- a/docs/xml/picotest_8h.xml +++ b/docs/xml/picotest_8h.xml @@ -2718,10 +2718,10 @@ PicoTest is released under the terms of the The 3-Clause BSD License: #define_PICOTEST_PARENS #endif/*defined(_MSC_VER)*/ -#definePICOTEST_VERSION"1.2.0" +#definePICOTEST_VERSION"1.3.0" #definePICOTEST_VERSION_MAJOR1 -#definePICOTEST_VERSION_MINOR2 -#definePICOTEST_VERSION_PATCH1 +#definePICOTEST_VERSION_MINOR3 +#definePICOTEST_VERSION_PATCH0 typedefint(PicoTestProc)(constchar*cond); diff --git a/include/picotest.h b/include/picotest.h index 5e1a97a..0593045 100644 --- a/include/picotest.h +++ b/include/picotest.h @@ -75,10 +75,10 @@ * \{ */ -#define PICOTEST_VERSION "1.2.0" +#define PICOTEST_VERSION "1.3.0" #define PICOTEST_VERSION_MAJOR 1 -#define PICOTEST_VERSION_MINOR 2 -#define PICOTEST_VERSION_PATCH 1 +#define PICOTEST_VERSION_MINOR 3 +#define PICOTEST_VERSION_PATCH 0 /*! \} End of Version */