-
Notifications
You must be signed in to change notification settings - Fork 12
[MrBot] Add test cases (parameterized tests) #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mattdurak
wants to merge
1
commit into
master
Choose a base branch
from
experiment_test_cases
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,81 @@ typedef void* TEST_MUTEX_HANDLE; | |
| // a macro useful for disabling tests while debugging | ||
| #define DISABLED_TEST_FUNCTION(name) void name(void) | ||
|
|
||
| /* | ||
| * PARAMETERIZED_TEST_FUNCTION - A macro for defining parameterized test functions | ||
| * | ||
| * Usage: | ||
| * PARAMETERIZED_TEST_FUNCTION(base_name, | ||
| * ARGS(type1, param1, type2, param2), | ||
| * CASE((value1, value2), suffix1), | ||
| * CASE((value3, value4), suffix2)) | ||
| * { | ||
| * // test code using param1, param2 | ||
| * } | ||
| * | ||
| * This expands to: | ||
| * - A static function declaration | ||
| * - Multiple TEST_FUNCTION wrappers that call the static function with the specified arguments | ||
| * - The static function definition with the test body | ||
| * | ||
| * Example: | ||
| * PARAMETERIZED_TEST_FUNCTION(test_addition, | ||
| * ARGS(int, a, int, b, int, expected), | ||
| * CASE((1, 2, 3), when_adding_1_and_2), | ||
| * CASE((0, 0, 0), when_adding_zeros)) | ||
| * { | ||
| * ASSERT_ARE_EQUAL(int, expected, a + b); | ||
| * } | ||
| */ | ||
|
|
||
| /* Helper macros for extracting parts from ARGS(...) */ | ||
| /* ARGS format: (type1, name1, type2, name2, ...) - uses MU_FOR_EACH_2 */ | ||
|
|
||
| /* Add comma before parameter declaration (used for all but first) */ | ||
| #define PTRS_ARGS_DECL_REST_DO(type, name) , type name | ||
| #define PTRS_ARGS_DECL_REST(...) MU_FOR_EACH_2(PTRS_ARGS_DECL_REST_DO, __VA_ARGS__) | ||
|
|
||
| /* Main ARGS declaration - handles 2+ args (1+ pairs) */ | ||
| #define PTRS_ARGS_DECL_2(t1, n1) t1 n1 | ||
| #define PTRS_ARGS_DECL_MORE(t1, n1, ...) t1 n1 PTRS_ARGS_DECL_REST(__VA_ARGS__) | ||
| #define PTRS_ARGS_DECL_DISPATCH_0(...) PTRS_ARGS_DECL_MORE(__VA_ARGS__) | ||
| #define PTRS_ARGS_DECL_DISPATCH_1(...) PTRS_ARGS_DECL_2(__VA_ARGS__) | ||
| #define PTRS_ARGS_DECL(...) MU_C2(PTRS_ARGS_DECL_DISPATCH_, MU_ISEMPTY(MU_IF(MU_ISZERO(MU_DEC(MU_DEC(MU_COUNT_ARG(__VA_ARGS__)))), 1, )))(__VA_ARGS__) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a feeling this can be re-written with macro_utils, this is just what the bot came up with |
||
|
|
||
| /* The ARGS wrapper just passes through */ | ||
| #define ARGS(...) __VA_ARGS__ | ||
|
|
||
| /* Strip parentheses helper */ | ||
| #define PTRS_STRIP_PARENS(...) __VA_ARGS__ | ||
|
|
||
| /* Generate a single TEST_FUNCTION wrapper for a CASE */ | ||
| /* This is called with (base_name, (values), suffix) - values wrapped in parens */ | ||
| #define PTRS_GENERATE_ONE_WRAPPER_IMPL(base_name, values, suffix) \ | ||
| TEST_FUNCTION(MU_C3(base_name, _, suffix)) \ | ||
| { \ | ||
| MU_C2(base_name, _impl)(PTRS_STRIP_PARENS values); \ | ||
| } | ||
|
|
||
| /* Helper to call IMPL with expanded args - this forces argument re-parsing */ | ||
| #define PTRS_GENERATE_ONE_WRAPPER_CALL(base_name, ...) PTRS_GENERATE_ONE_WRAPPER_IMPL(base_name, __VA_ARGS__) | ||
|
|
||
| /* When we paste PTRS_EXPAND_CASE_ with CASE(values, suffix), we get PTRS_EXPAND_CASE_CASE(values, suffix) */ | ||
| /* which expands to just: values, suffix (removing the CASE wrapper) */ | ||
| #define PTRS_EXPAND_CASE_CASE(values, suffix) values, suffix | ||
|
|
||
| /* This is called by MU_FOR_EACH_1_KEEP_1 with (base_name, CASE((vals), suffix)) */ | ||
| /* We use MU_C2B to paste PTRS_EXPAND_CASE_ with the case_item (which starts with CASE) */ | ||
| /* This gives us PTRS_EXPAND_CASE_CASE((vals), suffix) which expands to (vals), suffix */ | ||
| /* PTRS_GENERATE_ONE_WRAPPER_CALL uses __VA_ARGS__ to allow the expansion to split into multiple args */ | ||
| #define PTRS_GENERATE_ONE_WRAPPER(base_name, case_item) PTRS_GENERATE_ONE_WRAPPER_CALL(base_name, MU_C2B(PTRS_EXPAND_CASE_, case_item)) | ||
|
|
||
| /* Main PARAMETERIZED_TEST_FUNCTION macro */ | ||
| /* Usage: PARAMETERIZED_TEST_FUNCTION(name, ARGS(...), CASE((vals), suffix), ...) { body } */ | ||
| #define PARAMETERIZED_TEST_FUNCTION(base_name, args, ...) \ | ||
| static void MU_C2(base_name, _impl)(PTRS_ARGS_DECL(args)); \ | ||
| MU_FOR_EACH_1_KEEP_1(PTRS_GENERATE_ONE_WRAPPER, base_name, __VA_ARGS__) \ | ||
| static void MU_C2(base_name, _impl)(PTRS_ARGS_DECL(args)) | ||
|
|
||
| #ifdef USE_CTEST | ||
|
|
||
| #define TEST_DEFINE_ENUM_TYPE(type, ...) CTEST_DEFINE_ENUM_TYPE(type, __VA_ARGS__) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open item: Should we have some MD for this? We don't have docs for c-testrunnerswitcher