From 5dd2be96fa64d2c09cc040f531ce9c384690746c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Hangh=C3=B8j=20Henneberg?= Date: Thu, 13 Jul 2023 23:01:13 +0200 Subject: [PATCH] Add TEST_MATRIX to docs --- docs/UnityConfigurationGuide.md | 4 +- docs/UnityHelperScriptsGuide.md | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index d5e4098..88603fc 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -448,7 +448,7 @@ To enable it, use the following example: #define UNITY_SUPPORT_TEST_CASES ``` -You can manually provide required `TEST_CASE` or `TEST_RANGE` macro definitions +You can manually provide required `TEST_CASE`, `TEST_RANGE` or `TEST_MATRIX` macro definitions before including `unity.h`, and they won't be redefined. If you provide one of the following macros, some of default definitions will not be defined: @@ -456,8 +456,10 @@ defined: |---|---| | `UNITY_EXCLUDE_TEST_CASE` | `TEST_CASE` | | `UNITY_EXCLUDE_TEST_RANGE` | `TEST_RANGE` | +| `UNITY_EXCLUDE_TEST_MATRIX` | `TEST_MATRIX` | | `TEST_CASE` | `TEST_CASE` | | `TEST_RANGE` | `TEST_RANGE` | +| `TEST_MATRIX` | `TEST_MATRIX` | `UNITY_EXCLUDE_TEST_*` defines is not processed by test runner generator script. If you exclude one of them from definition, you should provide your own definition diff --git a/docs/UnityHelperScriptsGuide.md b/docs/UnityHelperScriptsGuide.md index 8b1e637..3c32133 100644 --- a/docs/UnityHelperScriptsGuide.md +++ b/docs/UnityHelperScriptsGuide.md @@ -296,6 +296,93 @@ TEST_CASE(4, 8, 30) TEST_CASE(4, 6, 30) ``` +##### `TEST_MATRIX` + +Test matix is an advanced generator. It single call can be converted to zero, +one or few `TEST_CASE` equivalent commands. + +That generator will create tests for all cobinations of the provided list. Each argument has to be given as a list of one or more elements in the format `[, , ..., , ]`. + +All parameters supported by the `TEST_CASE` is supported as arguments: +- Numbers incl type specifiers e.g. `<1>`, `<1u>`, `<1l>`, `<2.3>`, or `<2.3f>` +- Strings incl string concatianion e.g. `<"string">`, or `<"partial" "string">` +- Chars e.g. `<'c'>` +- Enums e.g. `` +- Elements of arrays e.g. `` + +Let's use our `test_demoParamFunction` test for checking, what ranges +will be generated for our single `TEST_RANGE` row: + +```C +TEST_MATRIX([3, 4, 7], [10, 8, 2, 1],[30u, 20.0f]) +``` + +Tests execution output will be similar to that text: + +```Log +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(3, 10, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(3, 10, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(3, 8, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(3, 8, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(3, 2, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(3, 2, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(3, 1, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(3, 1, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(4, 10, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(4, 10, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(4, 8, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(4, 8, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(4, 2, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(4, 2, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(4, 1, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(4, 1, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(7, 10, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(7, 10, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(7, 8, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(7, 8, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(7, 2, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(7, 2, 20.0f):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(7, 1, 30u):PASS +tests/test_unity_parameterizedDemo.c:18:test_demoParamFunction(7, 1, 20.0f):PASS +``` + +As we can see: + +| Parameter | Format | Count of values | +|---|---|---| +| `a` | `[3, 4, 7]` | 2 | +| `b` | `[10, 8, 2, 1]` | 4 | +| `c` | `[30u, 20.0f]` | 2 | + +We totally have 2 * 4 * 2 = 16 equal test cases, that can be written as following: + +```C +TEST_CASE(3, 10, 30u) +TEST_CASE(3, 10, 20.0f) +TEST_CASE(3, 8, 30u) +TEST_CASE(3, 8, 20.0f) +TEST_CASE(3, 2, 30u) +TEST_CASE(3, 2, 20.0f) +TEST_CASE(3, 1, 30u) +TEST_CASE(3, 1, 20.0f) +TEST_CASE(4, 10, 30u) +TEST_CASE(4, 10, 20.0f) +TEST_CASE(4, 8, 30u) +TEST_CASE(4, 8, 20.0f) +TEST_CASE(4, 2, 30u) +TEST_CASE(4, 2, 20.0f) +TEST_CASE(4, 1, 30u) +TEST_CASE(4, 1, 20.0f) +TEST_CASE(7, 10, 30u) +TEST_CASE(7, 10, 20.0f) +TEST_CASE(7, 8, 30u) +TEST_CASE(7, 8, 20.0f) +TEST_CASE(7, 2, 30u) +TEST_CASE(7, 2, 20.0f) +TEST_CASE(7, 1, 30u) +TEST_CASE(7, 1, 20.0f) +``` + ### `unity_test_summary.rb` A Unity test file contains one or more test case functions.