diff --git a/docs/UnityConfigurationGuide.md b/docs/UnityConfigurationGuide.md index 68fb106740227b4484aa16ca177399d26c011358..bdfb8539b5d0a99d7dce059ab9249c469c9eaae7 100644 --- a/docs/UnityConfigurationGuide.md +++ b/docs/UnityConfigurationGuide.md @@ -427,6 +427,15 @@ will allow you to specify how Unity will treat these assertions. - AS_NONE - Unity will disallow the use of these shorthand macros altogether, insisting that developers choose a more descriptive option. +#### `UNITY_SUPPORT_VARIADIC_MACROS` + +This will force Unity to support variadic macros when using it's own built-in +RUN_TEST macro. This will rarely be necessary. Most often, Unity will automatically +detect if the compiler supports variadic macros by checking to see if it's C99+ +compatible. In the event that the compiler supports variadic macros, but is primarily +C89 (ANSI), defining this option will allow you to use them. This option is also not +necessary when using Ceedling or the test runner generator script. + ## Getting Into The Guts There will be cases where the options above aren't quite going to get everything diff --git a/extras/fixture/test/unity_fixture_Test.c b/extras/fixture/test/unity_fixture_Test.c index a842b08537e7cc371af23eb346d8b1ba20ed135a..da44d5d9157952b1b6ef2b742d24898819d71fee 100644 --- a/extras/fixture/test/unity_fixture_Test.c +++ b/extras/fixture/test/unity_fixture_Test.c @@ -345,7 +345,7 @@ TEST_TEAR_DOWN(LeakDetection) /* This tricky set of defines lets us see if we are using the Spy, returns 1 if true */ #ifdef __STDC_VERSION__ -#if __STDC_VERSION__ >= 199901L +#if UNITY_SUPPORT_VARIADIC_MACROS #define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0) #define ASSIGN_VALUE(a) VAL_##a #define VAL_UnityOutputCharSpy_OutputChar 0, 1 @@ -354,7 +354,7 @@ TEST_TEAR_DOWN(LeakDetection) #if USING_SPY_AS(UNITY_OUTPUT_CHAR) #define USING_OUTPUT_SPY /* UNITY_OUTPUT_CHAR = UnityOutputCharSpy_OutputChar */ #endif -#endif /* >= 199901 */ +#endif /* UNITY_SUPPORT_VARIADIC_MACROS */ #else /* __STDC_VERSION__ else */ #define UnityOutputCharSpy_OutputChar 42 diff --git a/src/unity.c b/src/unity.c index 9883fd759e5e5ba082941dfd39e4c2229b2ff6d4..bcc0283aa79b3a60cba1e4b3aca51a26c02fe694 100644 --- a/src/unity.c +++ b/src/unity.c @@ -1814,9 +1814,9 @@ int UnityVerbosity = 1; /*-----------------------------------------------*/ int UnityParseOptions(int argc, char** argv) { + int i; UnityOptionIncludeNamed = NULL; UnityOptionExcludeNamed = NULL; - int i; for (i = 1; i < argc; i++) { diff --git a/src/unity_internals.h b/src/unity_internals.h index 0995281507db884fb4f02ffe29087865dcd4f2c2..0b8578e0afe3009b80350de7f99e02dc99d58a8b 100644 --- a/src/unity_internals.h +++ b/src/unity_internals.h @@ -683,6 +683,10 @@ extern const char UnityStrErrShorthand[]; #ifndef RUN_TEST #ifdef __STDC_VERSION__ #if __STDC_VERSION__ >= 199901L +#define UNITY_SUPPORT_VARIADIC +#endif +#endif +#ifdef UNITY_SUPPORT_VARIADIC_MACROS #define RUN_TEST(...) UnityDefaultTestRun(RUN_TEST_FIRST(__VA_ARGS__), RUN_TEST_SECOND(__VA_ARGS__)) #define RUN_TEST_FIRST(...) RUN_TEST_FIRST_HELPER(__VA_ARGS__, throwaway) #define RUN_TEST_FIRST_HELPER(first, ...) (first), #first @@ -690,7 +694,6 @@ extern const char UnityStrErrShorthand[]; #define RUN_TEST_SECOND_HELPER(first, second, ...) (second) #endif #endif -#endif /* If we can't do the tricky version, we'll just have to require them to always include the line number */ #ifndef RUN_TEST diff --git a/test/rakefile_helper.rb b/test/rakefile_helper.rb index 710686890dbda602d72c6dc47396180ef11ee89a..56f6dcc093b020087610b895b21250ef583b6ede 100644 --- a/test/rakefile_helper.rb +++ b/test/rakefile_helper.rb @@ -200,6 +200,15 @@ module RakefileHelpers # Build and execute each unit test test_files.each do |test| + + # Drop Out if we're skipping this type of test + if $cfg[:skip_tests] + if $cfg[:skip_tests].include?(:parameterized) && test.match(/parameterized/) + report("Skipping Parameterized Tests for this Target:IGNORE") + next + end + end + obj_list = [] unless $cfg['compiler']['aux_sources'].nil? diff --git a/test/targets/ansi.yml b/test/targets/ansi.yml new file mode 100644 index 0000000000000000000000000000000000000000..9cc393d60a379fc09c1c40d0aafff0594430d0a5 --- /dev/null +++ b/test/targets/ansi.yml @@ -0,0 +1,48 @@ +compiler: + path: gcc + source_path: '../src/' + unit_tests_path: &unit_tests_path 'tests/' + build_path: &build_path 'build/' + options: + - '-c' + - '-m64' + - '-Wall' + - '-Wno-address' + - '-ansi' + #- '-pedantic' + includes: + prefix: '-I' + items: + - 'src/' + - '../src/' + - 'testdata/' + - *unit_tests_path + defines: + prefix: '-D' + items: + - UNITY_INCLUDE_DOUBLE + - UNITY_SUPPORT_TEST_CASES + - UNITY_EXCLUDE_TESTING_NEW_COMMENTS + object_files: + prefix: '-o' + extension: '.o' + destination: *build_path +linker: + path: gcc + options: + - -lm + - '-m64' + includes: + prefix: '-I' + object_files: + path: *build_path + extension: '.o' + bin_files: + prefix: '-o' + extension: '.exe' + destination: *build_path +colour: true +:unity: + :plugins: [] +:skip_tests: + - :parameterized \ No newline at end of file diff --git a/test/testdata/CException.h b/test/testdata/CException.h index 91ad3e1bf22ff15b6b03faa896bb8ecc8f9e166d..3872fa75ffe16ecba390e40964439fb9e65afac9 100644 --- a/test/testdata/CException.h +++ b/test/testdata/CException.h @@ -8,4 +8,4 @@ #define Try if (e) #define Catch(a) if (!a) -#endif //CEXCEPTION_H +#endif diff --git a/test/testdata/Defs.h b/test/testdata/Defs.h index d3a90c0d506c34e561c9ba58f36cd94ea9ceae36..b1dc83e9ba5e85fcb70d6444954853879d6fa62c 100644 --- a/test/testdata/Defs.h +++ b/test/testdata/Defs.h @@ -5,4 +5,4 @@ extern int CounterSuiteSetup; -#endif //DEF_H +#endif diff --git a/test/testdata/cmock.h b/test/testdata/cmock.h index c6149be1b01749e893a0eee368478011e52bd438..33ddbfc567dbb7a043f54e61ceb63f0e9f66921e 100644 --- a/test/testdata/cmock.h +++ b/test/testdata/cmock.h @@ -11,4 +11,4 @@ void mockMock_Init(void) { mockMock_Init_Counter++; } void mockMock_Verify(void) { mockMock_Verify_Counter++; } void mockMock_Destroy(void) { mockMock_Destroy_Counter++; } -#endif //CMOCK_H +#endif diff --git a/test/testdata/mockMock.h b/test/testdata/mockMock.h index 0a2c616f797d2f901a9ad108eadd65de6c6134a9..5c6829d77f4c3bacd76f25d077dc642ef131fbf2 100644 --- a/test/testdata/mockMock.h +++ b/test/testdata/mockMock.h @@ -10,4 +10,4 @@ void mockMock_Init(void); void mockMock_Verify(void); void mockMock_Destroy(void); -#endif //MOCK_MOCK_H +#endif diff --git a/test/testdata/testRunnerGenerator.c b/test/testdata/testRunnerGenerator.c index 113993927557648f0faa5d6596ffcd996a4cccff..b5dd97f5d653da567e715582ee7f1aac8c55e5c8 100644 --- a/test/testdata/testRunnerGenerator.c +++ b/test/testdata/testRunnerGenerator.c @@ -108,10 +108,12 @@ void custtest_ThisTestPassesWhenCustomTeardownRan(void) TEST_ASSERT_EQUAL_MESSAGE(2, CounterTeardown, "Custom Teardown Wasn't Run"); } +#ifndef UNITY_EXCLUDE_TESTING_NEW_COMMENTS //void test_NewStyleCommentsShouldBeIgnored(void) //{ // TEST_ASSERT_FAIL("New Style Comments Should Be Ignored"); //} +#endif void test_NotBeConfusedByLongComplicatedStrings(void) { @@ -185,5 +187,3 @@ void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void) { TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run"); } - - diff --git a/test/testdata/testRunnerGeneratorWithMocks.c b/test/testdata/testRunnerGeneratorWithMocks.c index 4aacbf9ac3712bfbfb8de8553095ca9a1f0a0f25..aaceda4460fd4763995a8c33b98ae455d5e3cd42 100644 --- a/test/testdata/testRunnerGeneratorWithMocks.c +++ b/test/testdata/testRunnerGeneratorWithMocks.c @@ -109,10 +109,12 @@ void custtest_ThisTestPassesWhenCustomTeardownRan(void) TEST_ASSERT_EQUAL_MESSAGE(2, CounterTeardown, "Custom Teardown Wasn't Run"); } +#ifndef UNITY_EXCLUDE_TESTING_NEW_COMMENTS //void test_NewStyleCommentsShouldBeIgnored(void) //{ // TEST_ASSERT_FAIL("New Style Comments Should Be Ignored"); //} +#endif void test_NotBeConfusedByLongComplicatedStrings(void) { diff --git a/test/tests/test_generate_test_runner.rb b/test/tests/test_generate_test_runner.rb index 0b51bcd4f858a866d6b9e9000a00597a0464212b..ebf011dc33f7e05b802fcfb35bbe67d92a797ac6 100644 --- a/test/tests/test_generate_test_runner.rb +++ b/test/tests/test_generate_test_runner.rb @@ -144,6 +144,7 @@ RUNNER_TESTS = [ :test_prefix => "paratest", :use_param_tests => true, }, + :features => [ :parameterized ], :expected => { :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)', 'paratest_ShouldHandleParameterizedTests\(125\)', @@ -160,6 +161,7 @@ RUNNER_TESTS = [ :testfile => 'testdata/testRunnerGenerator.c', :testdefines => ['TEST'], :cmdline => " --test_prefix=\"paratest\" --use_param_tests=1", + :features => [ :parameterized ], :expected => { :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)', 'paratest_ShouldHandleParameterizedTests\(125\)', @@ -179,6 +181,7 @@ RUNNER_TESTS = [ :yaml => { :test_prefix => "paratest" }, + :features => [ :parameterized ], :expected => { :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)', 'paratest_ShouldHandleParameterizedTests\(125\)', @@ -468,6 +471,7 @@ RUNNER_TESTS = [ :test_prefix => "paratest", :use_param_tests => true, }, + :features => [ :parameterized ], :expected => { :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)', 'paratest_ShouldHandleParameterizedTests\(125\)', @@ -484,6 +488,7 @@ RUNNER_TESTS = [ :testfile => 'testdata/testRunnerGeneratorWithMocks.c', :testdefines => ['TEST'], :cmdline => " --test_prefix=\"paratest\" --use_param_tests=1", + :features => [ :parameterized ], :expected => { :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)', 'paratest_ShouldHandleParameterizedTests\(125\)', @@ -503,6 +508,7 @@ RUNNER_TESTS = [ :yaml => { :test_prefix => "paratest" }, + :features => [ :parameterized ], :expected => { :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)', 'paratest_ShouldHandleParameterizedTests\(125\)', @@ -1044,6 +1050,7 @@ RUNNER_TESTS = [ :test_prefix => "paratest" }, :cmdline_args => "-n ShouldHandleParameterizedTests", + :features => [ :parameterized ], :expected => { :to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)', 'paratest_ShouldHandleParameterizedTests\(125\)', @@ -1090,6 +1097,7 @@ RUNNER_TESTS = [ :cmdline_args => true, }, :cmdline_args => "-l", + :features => [ :parameterized ], :expected => { :to_pass => [ ], :to_fail => [ ], @@ -1151,10 +1159,18 @@ RUNNER_TESTS = [ }, ] -def runner_test(test, runner, expected, test_defines, cmdline_args) +def runner_test(test, runner, expected, test_defines, cmdline_args, features) # Tack on TEST define for compiling unit tests load_configuration($cfg_file) + # Drop Out if we're skipping this type of test + if $cfg[:skip_tests] && features + if $cfg[:skip_tests].include?(:parameterized) && features.include?(:parameterized) + report("Skipping Parameterized Tests for this Target:IGNORE") + return true + end + end + #compile objects obj_list = [ compile(runner, test_defines), @@ -1239,7 +1255,7 @@ RUNNER_TESTS.each do |testset| end #test the script against the specified test file and check results - if (runner_test(testset[:testfile], runner_name, testset[:expected], testset[:testdefines], testset[:cmdline_args])) + if (runner_test(testset[:testfile], runner_name, testset[:expected], testset[:testdefines], testset[:cmdline_args], testset[:features])) report "#{testset_name}:PASS" else report "#{testset_name}:FAIL" diff --git a/test/tests/testparameterized.c b/test/tests/testparameterized.c index 6100834f6f8fbc4ab87ed07664ddcd3bb11a8622..0583cb7478efb9b6ff378a5affcd8afd086395c5 100644 --- a/test/tests/testparameterized.c +++ b/test/tests/testparameterized.c @@ -169,6 +169,3 @@ void test_CharsArePreserved(unsigned index, char c) NextExpectedCharIndex++; } - - - diff --git a/test/tests/testunity.c b/test/tests/testunity.c index 297849fc8a3a121b8d752811d273aabc09ecf228..2771a995f0f39cd96a5c425834176ec901620d0b 100644 --- a/test/tests/testunity.c +++ b/test/tests/testunity.c @@ -8,8 +8,9 @@ #include #include -// Dividing by these constants produces +/- infinity. -// The rationale is given in UnityAssertFloatIsInf's body. +/* Dividing by these constants produces +/- infinity. + * The rationale is given in UnityAssertFloatIsInf's body. + */ #ifndef UNITY_EXCLUDE_FLOAT static const UNITY_FLOAT f_zero = 0.0f; #endif @@ -297,7 +298,9 @@ void testNotEqualInt16s(void) void testNotEqualInt32s(void) { EXPECT_ABORT_BEGIN - TEST_ASSERT_EQUAL_INT32(-2147483647, -2147483648); //use largest 32 bit negative to test printability + /*use largest 32 bit negative to test printability*/ + /*note: (-2147483647 - 1) is used instead of -2147483648 because of C90 casting rules */ + TEST_ASSERT_EQUAL_INT32(-2147483647, (-2147483647 - 1)); VERIFY_FAILS_END } @@ -336,8 +339,8 @@ void testNotEqualUInt16s(void) { UNITY_UINT16 v0, v1; - v0 = 65535; - v1 = 65534; + v0 = 65535u; + v1 = 65534u; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_UINT16(v0, v1); @@ -348,8 +351,8 @@ void testNotEqualUInt32s(void) { UNITY_UINT32 v0, v1; - v0 = 4294967295; - v1 = 4294967294; + v0 = 4294967295u; + v1 = 4294967294u; EXPECT_ABORT_BEGIN TEST_ASSERT_EQUAL_UINT32(v0, v1); @@ -1116,7 +1119,7 @@ void testHEX8sNotWithinDeltaAndCustomMessage(void) VERIFY_FAILS_END } -//----------------- +/*-----------------*/ void testUINT32sWithinDelta(void) { @@ -1340,7 +1343,7 @@ void testINT8sNotWithinDeltaAndCustomMessage(void) VERIFY_FAILS_END } -//------------------------ +/*------------------------*/ void testInt64ArrayWithinDelta(void) { @@ -2807,7 +2810,7 @@ void testHEX8ArrayWithinDeltaSamePointerAndMessage(void) TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(60, expected, expected, 3, "Custom Message."); } -//----------------- +/*-----------------*/ void testGreaterThan(void) { @@ -2998,8 +3001,8 @@ void testGreaterThanUINT32(void) UNITY_UINT32 v0, v1; UNITY_UINT32 *p0, *p1; - v0 = 0; - v1 = 4294967295; + v0 = 0u; + v1 = 4294967295u; p0 = &v0; p1 = &v1; @@ -3012,7 +3015,7 @@ void testGreaterThanUINT32(void) void testNotGreaterThanUINT32(void) { EXPECT_ABORT_BEGIN - TEST_ASSERT_GREATER_THAN_UINT32(4294967295, 0); + TEST_ASSERT_GREATER_THAN_UINT32(4294967295u, 0); VERIFY_FAILS_END } @@ -3323,7 +3326,7 @@ void testGreaterOrEqualUINT32(void) UNITY_UINT32 *p0, *p1, *p2; v0 = 0; - v1 = 4294967295; + v1 = 4294967295u; v2 = 0; p0 = &v0; p1 = &v1; @@ -3342,7 +3345,7 @@ void testGreaterOrEqualUINT32(void) void testNotGreaterOrEqualUINT32(void) { EXPECT_ABORT_BEGIN - TEST_ASSERT_GREATER_OR_EQUAL_UINT32(4294967295, 0); + TEST_ASSERT_GREATER_OR_EQUAL_UINT32(4294967295u, 0); VERIFY_FAILS_END } @@ -3433,8 +3436,7 @@ void testNotGreaterOrEqualHEX32(void) VERIFY_FAILS_END } -//----------------- - +/*-----------------*/ void testLessThan(void) { @@ -3625,7 +3627,7 @@ void testLessThanUINT32(void) UNITY_UINT32 v0, v1; UNITY_UINT32 *p0, *p1; - v0 = 4294967295; + v0 = 4294967295u; v1 = 0; p0 = &v0; p1 = &v1; @@ -3639,7 +3641,7 @@ void testLessThanUINT32(void) void testNotLessThanUINT32(void) { EXPECT_ABORT_BEGIN - TEST_ASSERT_LESS_THAN_UINT32(0, 4294967295); + TEST_ASSERT_LESS_THAN_UINT32(0, 4294967295u); VERIFY_FAILS_END } @@ -3949,9 +3951,9 @@ void testLessOrEqualUINT32(void) UNITY_UINT32 v0, v1, v2; UNITY_UINT32 *p0, *p1, *p2; - v0 = 4294967295; + v0 = 4294967295u; v1 = 0; - v2 = 4294967295; + v2 = 4294967295u; p0 = &v0; p1 = &v1; p2 = &v2; @@ -3969,7 +3971,7 @@ void testLessOrEqualUINT32(void) void testNotLessOrEqualUINT32(void) { EXPECT_ABORT_BEGIN - TEST_ASSERT_LESS_OR_EQUAL_UINT32(0, 4294967295); + TEST_ASSERT_LESS_OR_EQUAL_UINT32(0, 4294967295u); VERIFY_FAILS_END } @@ -4060,7 +4062,8 @@ void testNotLessOrEqualHEX32(void) VERIFY_FAILS_END } -//----------------- +/*-----------------*/ + void testEqualStrings(void) { const char *testString = "foo"; @@ -5651,14 +5654,14 @@ void testIgnoredAndThenFailInTearDown(void) TEST_IGNORE(); } -// Tricky series of macros to set USING_OUTPUT_SPY +/* Tricky series of macros to set USING_OUTPUT_SPY */ #define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0) #define ASSIGN_VALUE(a) VAL_##a #define VAL_putcharSpy 0, 1 #define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b, throwaway) #define SECOND_PARAM(a, b, ...) b #if USING_SPY_AS(UNITY_OUTPUT_CHAR) - #define USING_OUTPUT_SPY // true only if UNITY_OUTPUT_CHAR = putcharSpy + #define USING_OUTPUT_SPY /* true only if UNITY_OUTPUT_CHAR = putcharSpy */ #endif #ifdef USING_OUTPUT_SPY @@ -5712,7 +5715,7 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void) { UNITY_UINT savedFailures = Unity.TestFailures; Unity.CurrentTestFailed = 1; - startPutcharSpy(); // Suppress output + startPutcharSpy(); /* Suppress output */ startFlushSpy(); TEST_ASSERT_EQUAL(0, getFlushSpyCalls()); UnityConcludeTest(); @@ -5725,7 +5728,7 @@ void testFailureCountIncrementsAndIsReturnedAtEnd(void) #endif endFlushSpy(); - startPutcharSpy(); // Suppress output + startPutcharSpy(); /* Suppress output */ int failures = UnityEnd(); Unity.TestFailures--; endPutcharSpy(); @@ -5798,7 +5801,7 @@ void testPrintNumbersUnsigned32(void) } -// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES 64 BIT SUPPORT ================== +/* ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES 64 BIT SUPPORT ================== */ void testPrintNumbersInt64(void) { @@ -6175,7 +6178,8 @@ void testNotEqualInt64Arrays(void) VERIFY_FAILS_END #endif } -// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES FLOAT SUPPORT ================== + +/* ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES FLOAT SUPPORT ================== */ void testFloatsWithinDelta(void) { @@ -7033,7 +7037,7 @@ void testFloatPrintingRandomSamples(void) #endif } -// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ================== +/* ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ================== */ void testDoublesWithinDelta(void) { @@ -7774,7 +7778,7 @@ void testDoublePrintingInfinityAndNaN(void) #endif } -// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DETAIL SUPPORT ================== +/* ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DETAIL SUPPORT ================== */ void testThatDetailsCanBeHandleOneDetail(void) {