提交 d16c27b0 编写于 作者: M mvandervoord

- added target for checking ANSI compliance

- fixed ANSI (C89) issues, including #418
上级 748efa26
......@@ -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
......
......@@ -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
......
......@@ -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++)
{
......
......@@ -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
......
......@@ -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?
......
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
......@@ -8,4 +8,4 @@
#define Try if (e)
#define Catch(a) if (!a)
#endif //CEXCEPTION_H
#endif
......@@ -5,4 +5,4 @@
extern int CounterSuiteSetup;
#endif //DEF_H
#endif
......@@ -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
......@@ -10,4 +10,4 @@ void mockMock_Init(void);
void mockMock_Verify(void);
void mockMock_Destroy(void);
#endif //MOCK_MOCK_H
#endif
......@@ -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");
}
......@@ -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)
{
......
......@@ -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"
......
......@@ -169,6 +169,3 @@ void test_CharsArePreserved(unsigned index, char c)
NextExpectedCharIndex++;
}
......@@ -8,8 +8,9 @@
#include <string.h>
#include <stdint.h>
// 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)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册