Skip to content

Commit

Permalink
- added target for checking ANSI compliance
Browse files Browse the repository at this point in the history
- fixed ANSI (C89) issues, including #418
  • Loading branch information
mvandervoord committed Oct 25, 2019
1 parent 748efa2 commit d16c27b
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 46 deletions.
9 changes: 9 additions & 0 deletions docs/UnityConfigurationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions extras/fixture/test/unity_fixture_Test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/unity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
5 changes: 4 additions & 1 deletion src/unity_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,14 +683,17 @@ 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
#define RUN_TEST_SECOND(...) RUN_TEST_SECOND_HELPER(__VA_ARGS__, __LINE__, throwaway)
#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
Expand Down
9 changes: 9 additions & 0 deletions test/rakefile_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ def run_tests(test_files)

# 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?
Expand Down
48 changes: 48 additions & 0 deletions test/targets/ansi.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/testdata/CException.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
#define Try if (e)
#define Catch(a) if (!a)

#endif //CEXCEPTION_H
#endif
2 changes: 1 addition & 1 deletion test/testdata/Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

extern int CounterSuiteSetup;

#endif //DEF_H
#endif
2 changes: 1 addition & 1 deletion test/testdata/cmock.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion test/testdata/mockMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ void mockMock_Init(void);
void mockMock_Verify(void);
void mockMock_Destroy(void);

#endif //MOCK_MOCK_H
#endif
4 changes: 2 additions & 2 deletions test/testdata/testRunnerGenerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -185,5 +187,3 @@ void suitetest_ThisTestPassesWhenCustomSuiteSetupAndTeardownRan(void)
{
TEST_ASSERT_EQUAL_MESSAGE(1, CounterSuiteSetup, "Suite Setup Should Have Run");
}


2 changes: 2 additions & 0 deletions test/testdata/testRunnerGeneratorWithMocks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
20 changes: 18 additions & 2 deletions test/tests/test_generate_test_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
:test_prefix => "paratest",
:use_param_tests => true,
},
:features => [ :parameterized ],
:expected => {
:to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
'paratest_ShouldHandleParameterizedTests\(125\)',
Expand All @@ -160,6 +161,7 @@
: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\)',
Expand All @@ -179,6 +181,7 @@
:yaml => {
:test_prefix => "paratest"
},
:features => [ :parameterized ],
:expected => {
:to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
'paratest_ShouldHandleParameterizedTests\(125\)',
Expand Down Expand Up @@ -468,6 +471,7 @@
:test_prefix => "paratest",
:use_param_tests => true,
},
:features => [ :parameterized ],
:expected => {
:to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
'paratest_ShouldHandleParameterizedTests\(125\)',
Expand All @@ -484,6 +488,7 @@
: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\)',
Expand All @@ -503,6 +508,7 @@
:yaml => {
:test_prefix => "paratest"
},
:features => [ :parameterized ],
:expected => {
:to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
'paratest_ShouldHandleParameterizedTests\(125\)',
Expand Down Expand Up @@ -1044,6 +1050,7 @@
:test_prefix => "paratest"
},
:cmdline_args => "-n ShouldHandleParameterizedTests",
:features => [ :parameterized ],
:expected => {
:to_pass => [ 'paratest_ShouldHandleParameterizedTests\(25\)',
'paratest_ShouldHandleParameterizedTests\(125\)',
Expand Down Expand Up @@ -1090,6 +1097,7 @@
:cmdline_args => true,
},
:cmdline_args => "-l",
:features => [ :parameterized ],
:expected => {
:to_pass => [ ],
:to_fail => [ ],
Expand Down Expand Up @@ -1151,10 +1159,18 @@
},
]

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),
Expand Down Expand Up @@ -1239,7 +1255,7 @@ def verify_number(expected, expression, output)
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"
Expand Down
3 changes: 0 additions & 3 deletions test/tests/testparameterized.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,3 @@ void test_CharsArePreserved(unsigned index, char c)

NextExpectedCharIndex++;
}



Loading

0 comments on commit d16c27b

Please sign in to comment.