diff options
Diffstat (limited to 'deps/Unity/extras/fixture')
-rw-r--r-- | deps/Unity/extras/fixture/readme.md | 26 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/src/meson.build | 10 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/src/unity_fixture.c | 240 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/src/unity_fixture.h | 94 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/src/unity_fixture_internals.h | 50 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/test/Makefile | 72 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/test/main/AllTests.c | 20 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/test/template_fixture_tests.c | 39 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/test/unity_fixture_Test.c | 245 | ||||
-rw-r--r-- | deps/Unity/extras/fixture/test/unity_fixture_TestRunner.c | 32 |
10 files changed, 828 insertions, 0 deletions
diff --git a/deps/Unity/extras/fixture/readme.md b/deps/Unity/extras/fixture/readme.md new file mode 100644 index 0000000..e0c9e1b --- /dev/null +++ b/deps/Unity/extras/fixture/readme.md @@ -0,0 +1,26 @@ +# Unity Fixtures + +This Framework is an optional add-on to Unity. +By including unity_fixture.h in place of unity.h, you may now work with Unity in a manner similar to CppUTest. +This framework adds the concepts of test groups and gives finer control of your tests over the command line. + +This framework is primarily supplied for those working through James Grenning's book on Embedded Test Driven Development, or those coming to Unity from CppUTest. +We should note that using this framework glosses over some of the features of Unity, and makes it more difficult to integrate with other testing tools like Ceedling and CMock. + +## Dependency Notification + +Fixtures, by default, uses the Memory addon as well. +This is to make it simple for those trying to follow along with James' book. +Using them together is completely optional. +You may choose to use Fixtures without Memory handling by defining `UNITY_FIXTURE_NO_EXTRAS`. +It will then stop automatically pulling in extras and leave you to do it as desired. + +## Usage information + +By default the test executables produced by Unity Fixtures run all tests once, but the behavior can be configured with command-line flags. +Run the test executable with the `--help` flag for more information. + +It's possible to add a custom line at the end of the help message, typically to point to project-specific or company-specific unit test documentation. +Define `UNITY_CUSTOM_HELP_MSG` to provide a custom message, e.g.: + + #define UNITY_CUSTOM_HELP_MSG "If any test fails see https://example.com/troubleshooting" diff --git a/deps/Unity/extras/fixture/src/meson.build b/deps/Unity/extras/fixture/src/meson.build new file mode 100644 index 0000000..224911d --- /dev/null +++ b/deps/Unity/extras/fixture/src/meson.build @@ -0,0 +1,10 @@ +unity_inc += include_directories('.') +unity_src += files('unity_fixture.c') + +if not meson.is_subproject() + install_headers( + 'unity_fixture.h', + 'unity_fixture_internals.h', + subdir: meson.project_name() + ) +endif diff --git a/deps/Unity/extras/fixture/src/unity_fixture.c b/deps/Unity/extras/fixture/src/unity_fixture.c new file mode 100644 index 0000000..e69b5a3 --- /dev/null +++ b/deps/Unity/extras/fixture/src/unity_fixture.c @@ -0,0 +1,240 @@ +/* Copyright (c) 2010 James Grenning and Contributed to Unity Project + * ========================================== + * Unity Project - A Test Framework for C + * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams + * [Released under MIT License. Please refer to license.txt for details] + * ========================================== */ + +#include "unity_fixture.h" +#include <string.h> +#include "unity_internals.h" + +struct UNITY_FIXTURE_T UnityFixture; + +/* If you decide to use the function pointer approach. + * Build with -D UNITY_OUTPUT_CHAR=outputChar and include <stdio.h> + * int (*outputChar)(int) = putchar; */ + +void setUp(void) { /*does nothing*/ +} +void tearDown(void) { /*does nothing*/ +} + +static void announceTestRun(unsigned int runNumber) { + UnityPrint("Unity test run "); + UnityPrintNumberUnsigned(runNumber + 1); + UnityPrint(" of "); + UnityPrintNumberUnsigned(UnityFixture.RepeatCount); + UNITY_PRINT_EOL(); +} + +int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)) { + int result = UnityGetCommandLineOptions(argc, argv); + unsigned int r; + if (result != 0) return result; + + for (r = 0; r < UnityFixture.RepeatCount; r++) { + UnityBegin(argv[0]); + announceTestRun(r); + runAllTests(); + if (!UnityFixture.Verbose) UNITY_PRINT_EOL(); + UnityEnd(); + } + + return (int)Unity.TestFailures; +} + +static int selected(const char* filter, const char* name) { + if (filter == 0) return 1; + return strstr(name, filter) ? 1 : 0; +} + +static int testSelected(const char* test) { return selected(UnityFixture.NameFilter, test); } + +static int groupSelected(const char* group) { return selected(UnityFixture.GroupFilter, group); } + +void UnityTestRunner(unityfunction* setup, unityfunction* testBody, unityfunction* teardown, + const char* printableName, const char* group, const char* name, + const char* file, unsigned int line) { + if (testSelected(name) && groupSelected(group)) { + Unity.TestFile = file; + Unity.CurrentTestName = printableName; + Unity.CurrentTestLineNumber = line; + if (UnityFixture.Verbose) { + UnityPrint(printableName); +#ifndef UNITY_REPEAT_TEST_NAME + Unity.CurrentTestName = NULL; +#endif + } else if (UnityFixture.Silent) { + /* Do Nothing */ + } else { + UNITY_OUTPUT_CHAR('.'); + } + + Unity.NumberOfTests++; + UnityPointer_Init(); + + UNITY_EXEC_TIME_START(); + + if (TEST_PROTECT()) { + setup(); + testBody(); + } + if (TEST_PROTECT()) { + teardown(); + } + if (TEST_PROTECT()) { + UnityPointer_UndoAllSets(); + } + UnityConcludeFixtureTest(); + } +} + +void UnityIgnoreTest(const char* printableName, const char* group, const char* name) { + if (testSelected(name) && groupSelected(group)) { + Unity.NumberOfTests++; + Unity.TestIgnores++; + if (UnityFixture.Verbose) { + UnityPrint(printableName); + UNITY_PRINT_EOL(); + } else if (UnityFixture.Silent) { + /* Do Nothing */ + } else { + UNITY_OUTPUT_CHAR('!'); + } + } +} + +/*-------------------------------------------------------- */ +/*Automatic pointer restoration functions */ +struct PointerPair { + void** pointer; + void* old_value; +}; + +static struct PointerPair pointer_store[UNITY_MAX_POINTERS]; +static int pointer_index = 0; + +void UnityPointer_Init(void) { pointer_index = 0; } + +void UnityPointer_Set(void** pointer, void* newValue, UNITY_LINE_TYPE line) { + if (pointer_index >= UNITY_MAX_POINTERS) { + UNITY_TEST_FAIL(line, "Too many pointers set"); + } else { + pointer_store[pointer_index].pointer = pointer; + pointer_store[pointer_index].old_value = *pointer; + *pointer = newValue; + pointer_index++; + } +} + +void UnityPointer_UndoAllSets(void) { + while (pointer_index > 0) { + pointer_index--; + *(pointer_store[pointer_index].pointer) = pointer_store[pointer_index].old_value; + } +} + +int UnityGetCommandLineOptions(int argc, const char* argv[]) { + int i; + UnityFixture.Verbose = 0; + UnityFixture.Silent = 0; + UnityFixture.GroupFilter = 0; + UnityFixture.NameFilter = 0; + UnityFixture.RepeatCount = 1; + + if (argc == 1) return 0; + + for (i = 1; i < argc;) { + if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { + /* Usage */ + UnityPrint("Runs a series of unit tests."); + UNITY_PRINT_EOL(); + UNITY_PRINT_EOL(); + UnityPrint("When no flag is specified, all tests are run."); + UNITY_PRINT_EOL(); + UNITY_PRINT_EOL(); + UnityPrint("Optional flags:"); + UNITY_PRINT_EOL(); + UnityPrint(" -v Verbose output: show all tests executed even if they pass"); + UNITY_PRINT_EOL(); + UnityPrint(" -s Silent mode: minimal output showing only test failures"); + UNITY_PRINT_EOL(); + UnityPrint(" -g NAME Only run tests in groups that contain the string NAME"); + UNITY_PRINT_EOL(); + UnityPrint(" -n NAME Only run tests whose name contains the string NAME"); + UNITY_PRINT_EOL(); + UnityPrint(" -r NUMBER Repeatedly run all tests NUMBER times"); + UNITY_PRINT_EOL(); + UnityPrint(" -h, --help Display this help message"); + UNITY_PRINT_EOL(); + UNITY_PRINT_EOL(); +#ifdef UNITY_CUSTOM_HELP_MSG + /* User-defined help message, e.g. to point to project-specific documentation */ + UnityPrint(UNITY_CUSTOM_HELP_MSG); + UNITY_PRINT_EOL(); +#else + /* Default help suffix if a custom one is not defined */ + UnityPrint("More information about Unity: https://www.throwtheswitch.org/unity"); + UNITY_PRINT_EOL(); +#endif + return 1; /* Exit without running the tests */ + } else if (strcmp(argv[i], "-v") == 0) { + UnityFixture.Verbose = 1; + i++; + } else if (strcmp(argv[i], "-s") == 0) { + UnityFixture.Silent = 1; + i++; + } else if (strcmp(argv[i], "-g") == 0) { + i++; + if (i >= argc) return 1; + UnityFixture.GroupFilter = argv[i]; + i++; + } else if (strcmp(argv[i], "-n") == 0) { + i++; + if (i >= argc) return 1; + UnityFixture.NameFilter = argv[i]; + i++; + } else if (strcmp(argv[i], "-r") == 0) { + UnityFixture.RepeatCount = 2; + i++; + if (i < argc) { + if (*(argv[i]) >= '0' && *(argv[i]) <= '9') { + unsigned int digit = 0; + UnityFixture.RepeatCount = 0; + while (argv[i][digit] >= '0' && argv[i][digit] <= '9') { + UnityFixture.RepeatCount *= 10; + UnityFixture.RepeatCount += (unsigned int)argv[i][digit++] - '0'; + } + i++; + } + } + } else { + /* ignore unknown parameter */ + i++; + } + } + return 0; +} + +void UnityConcludeFixtureTest(void) { + if (Unity.CurrentTestIgnored) { + Unity.TestIgnores++; + UNITY_PRINT_EOL(); + } else if (!Unity.CurrentTestFailed) { + if (UnityFixture.Verbose) { + UnityPrint(" "); + UnityPrint(UnityStrPass); + UNITY_EXEC_TIME_STOP(); + UNITY_PRINT_EXEC_TIME(); + UNITY_PRINT_EOL(); + } + } else /* Unity.CurrentTestFailed */ + { + Unity.TestFailures++; + UNITY_PRINT_EOL(); + } + + Unity.CurrentTestFailed = 0; + Unity.CurrentTestIgnored = 0; +} diff --git a/deps/Unity/extras/fixture/src/unity_fixture.h b/deps/Unity/extras/fixture/src/unity_fixture.h new file mode 100644 index 0000000..6575066 --- /dev/null +++ b/deps/Unity/extras/fixture/src/unity_fixture.h @@ -0,0 +1,94 @@ +/* Copyright (c) 2010 James Grenning and Contributed to Unity Project + * ========================================== + * Unity Project - A Test Framework for C + * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams + * [Released under MIT License. Please refer to license.txt for details] + * ========================================== */ + +#ifndef UNITY_FIXTURE_H_ +#define UNITY_FIXTURE_H_ + +#include "unity.h" +#include "unity_fixture_internals.h" + +#ifndef UNITY_FIXTURE_NO_EXTRAS +#include "unity_memory.h" +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "unity_internals.h" + + +int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)); + + +#define TEST_GROUP(group)\ + static const char* TEST_GROUP_##group = #group + +#define TEST_SETUP(group) void TEST_##group##_SETUP(void);\ + void TEST_##group##_SETUP(void) + +#define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void);\ + void TEST_##group##_TEAR_DOWN(void) + + +#define TEST(group, name) \ + void TEST_##group##_##name##_(void);\ + void TEST_##group##_##name##_run(void);\ + void TEST_##group##_##name##_run(void)\ + {\ + UnityTestRunner(TEST_##group##_SETUP,\ + TEST_##group##_##name##_,\ + TEST_##group##_TEAR_DOWN,\ + "TEST(" #group ", " #name ")",\ + TEST_GROUP_##group, #name,\ + __FILE__, __LINE__);\ + }\ + void TEST_##group##_##name##_(void) + +#define IGNORE_TEST(group, name) \ + void TEST_##group##_##name##_(void);\ + void TEST_##group##_##name##_run(void);\ + void TEST_##group##_##name##_run(void)\ + {\ + UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")", TEST_GROUP_##group, #name);\ + }\ + void TEST_##group##_##name##_(void) + +/* Call this for each test, insider the group runner */ +#define RUN_TEST_CASE(group, name) \ + { void TEST_##group##_##name##_run(void);\ + TEST_##group##_##name##_run(); } + +/* This goes at the bottom of each test file or in a separate c file */ +#define TEST_GROUP_RUNNER(group)\ + void TEST_##group##_GROUP_RUNNER(void);\ + void TEST_##group##_GROUP_RUNNER(void) + +/* Call this from main */ +#define RUN_TEST_GROUP(group)\ + { void TEST_##group##_GROUP_RUNNER(void);\ + TEST_##group##_GROUP_RUNNER(); } + +/* CppUTest Compatibility Macros */ +#ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS +/* Sets a pointer and automatically restores it to its old value after teardown */ +#define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__) +#define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual)) +#define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual)) +#define FAIL(message) TEST_FAIL_MESSAGE((message)) +#define CHECK(condition) TEST_ASSERT_TRUE((condition)) +#define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual)) +#define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual)) +#define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual)) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* UNITY_FIXTURE_H_ */ diff --git a/deps/Unity/extras/fixture/src/unity_fixture_internals.h b/deps/Unity/extras/fixture/src/unity_fixture_internals.h new file mode 100644 index 0000000..1c51aa9 --- /dev/null +++ b/deps/Unity/extras/fixture/src/unity_fixture_internals.h @@ -0,0 +1,50 @@ +/* Copyright (c) 2010 James Grenning and Contributed to Unity Project + * ========================================== + * Unity Project - A Test Framework for C + * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams + * [Released under MIT License. Please refer to license.txt for details] + * ========================================== */ + +#ifndef UNITY_FIXTURE_INTERNALS_H_ +#define UNITY_FIXTURE_INTERNALS_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +struct UNITY_FIXTURE_T +{ + int Verbose; + int Silent; + unsigned int RepeatCount; + const char* NameFilter; + const char* GroupFilter; +}; +extern struct UNITY_FIXTURE_T UnityFixture; + +typedef void unityfunction(void); +void UnityTestRunner(unityfunction* setup, + unityfunction* testBody, + unityfunction* teardown, + const char* printableName, + const char* group, + const char* name, + const char* file, unsigned int line); + +void UnityIgnoreTest(const char* printableName, const char* group, const char* name); +int UnityGetCommandLineOptions(int argc, const char* argv[]); +void UnityConcludeFixtureTest(void); + +void UnityPointer_Set(void** pointer, void* newValue, UNITY_LINE_TYPE line); +void UnityPointer_UndoAllSets(void); +void UnityPointer_Init(void); +#ifndef UNITY_MAX_POINTERS +#define UNITY_MAX_POINTERS 5 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* UNITY_FIXTURE_INTERNALS_H_ */ diff --git a/deps/Unity/extras/fixture/test/Makefile b/deps/Unity/extras/fixture/test/Makefile new file mode 100644 index 0000000..bbe3241 --- /dev/null +++ b/deps/Unity/extras/fixture/test/Makefile @@ -0,0 +1,72 @@ +CC = gcc +ifeq ($(shell uname -s), Darwin) +CC = clang +endif +#DEBUG = -O0 -g +CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror -DUNITY_FIXTURE_NO_EXTRAS +CFLAGS += $(DEBUG) +SRC = ../src/unity_fixture.c \ + ../../../src/unity.c \ + unity_fixture_Test.c \ + unity_fixture_TestRunner.c \ + main/AllTests.c + +INC_DIR = -I../src -I../../../src/ +BUILD_DIR = ../build +TARGET = ../build/fixture_tests.exe + +all: default noStdlibMalloc 32bits + +default: $(BUILD_DIR) + $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_SUPPORT_64 + @ echo "default build" + ./$(TARGET) + +32bits: $(BUILD_DIR) + $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m32 + @ echo "32bits build" + ./$(TARGET) + +noStdlibMalloc: $(BUILD_DIR) + $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC + @ echo "build with noStdlibMalloc" + ./$(TARGET) + +C89: CFLAGS += -D UNITY_EXCLUDE_STDINT_H # C89 did not have type 'long long', <stdint.h> +C89: $(BUILD_DIR) + $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -std=c89 && ./$(TARGET) + $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC -std=c89 + ./$(TARGET) + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +clean: + rm -f $(TARGET) $(BUILD_DIR)/*.gc* + +cov: $(BUILD_DIR) + cd $(BUILD_DIR) && \ + $(CC) $(DEFINES) $(foreach i, $(SRC), ../test/$(i)) $(INC_DIR) -o $(TARGET) -fprofile-arcs -ftest-coverage + rm -f $(BUILD_DIR)/*.gcda + ./$(TARGET) > /dev/null ; ./$(TARGET) -v > /dev/null + cd $(BUILD_DIR) && \ + gcov unity_fixture.c | head -3 + grep '###' $(BUILD_DIR)/unity_fixture.c.gcov -C2 || true # Show uncovered lines + +# These extended flags DO get included before any target build runs +CFLAGS += -Wbad-function-cast +CFLAGS += -Wcast-qual +CFLAGS += -Wconversion +CFLAGS += -Wformat=2 +CFLAGS += -Wmissing-prototypes +CFLAGS += -Wold-style-definition +CFLAGS += -Wpointer-arith +CFLAGS += -Wshadow +CFLAGS += -Wstrict-overflow=5 +CFLAGS += -Wstrict-prototypes +CFLAGS += -Wswitch-default +CFLAGS += -Wundef +CFLAGS += -Wno-error=undef # Warning only, this should not stop the build +CFLAGS += -Wunreachable-code +CFLAGS += -Wunused +CFLAGS += -fstrict-aliasing diff --git a/deps/Unity/extras/fixture/test/main/AllTests.c b/deps/Unity/extras/fixture/test/main/AllTests.c new file mode 100644 index 0000000..30242cb --- /dev/null +++ b/deps/Unity/extras/fixture/test/main/AllTests.c @@ -0,0 +1,20 @@ +/* Copyright (c) 2010 James Grenning and Contributed to Unity Project + * ========================================== + * Unity Project - A Test Framework for C + * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams + * [Released under MIT License. Please refer to license.txt for details] + * ========================================== */ + +#include "unity_fixture.h" + +static void runAllTests(void) +{ + RUN_TEST_GROUP(UnityFixture); + RUN_TEST_GROUP(UnityCommandOptions); +} + +int main(int argc, const char* argv[]) +{ + return UnityMain(argc, argv, runAllTests); +} + diff --git a/deps/Unity/extras/fixture/test/template_fixture_tests.c b/deps/Unity/extras/fixture/test/template_fixture_tests.c new file mode 100644 index 0000000..18bbb89 --- /dev/null +++ b/deps/Unity/extras/fixture/test/template_fixture_tests.c @@ -0,0 +1,39 @@ +/* Copyright (c) 2010 James Grenning and Contributed to Unity Project + * ========================================== + * Unity Project - A Test Framework for C + * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams + * [Released under MIT License. Please refer to license.txt for details] + * ========================================== */ + +#include "unity_fixture.h" + +static int data = -1; + +TEST_GROUP(mygroup); + +TEST_SETUP(mygroup) +{ + data = 0; +} + +TEST_TEAR_DOWN(mygroup) +{ + data = -1; +} + +TEST(mygroup, test1) +{ + TEST_ASSERT_EQUAL_INT(0, data); +} + +TEST(mygroup, test2) +{ + TEST_ASSERT_EQUAL_INT(0, data); + data = 5; +} + +TEST(mygroup, test3) +{ + data = 7; + TEST_ASSERT_EQUAL_INT(7, data); +} diff --git a/deps/Unity/extras/fixture/test/unity_fixture_Test.c b/deps/Unity/extras/fixture/test/unity_fixture_Test.c new file mode 100644 index 0000000..1422b48 --- /dev/null +++ b/deps/Unity/extras/fixture/test/unity_fixture_Test.c @@ -0,0 +1,245 @@ +/* Copyright (c) 2010 James Grenning and Contributed to Unity Project + * ========================================== + * Unity Project - A Test Framework for C + * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams + * [Released under MIT License. Please refer to license.txt for details] + * ========================================== */ + +#include "unity_fixture.h" +#include <stdlib.h> +#include <string.h> + +TEST_GROUP(UnityFixture); + +TEST_SETUP(UnityFixture) +{ +} + +TEST_TEAR_DOWN(UnityFixture) +{ +} + +static int* pointer1 = 0; +static int* pointer2 = (int*)2; +static int* pointer3 = (int*)3; +static int int1; +static int int2; +static int int3; +static int int4; + +TEST(UnityFixture, PointerSetting) +{ + TEST_ASSERT_POINTERS_EQUAL(pointer1, 0); + UT_PTR_SET(pointer1, &int1); + UT_PTR_SET(pointer2, &int2); + UT_PTR_SET(pointer3, &int3); + TEST_ASSERT_POINTERS_EQUAL(pointer1, &int1); + TEST_ASSERT_POINTERS_EQUAL(pointer2, &int2); + TEST_ASSERT_POINTERS_EQUAL(pointer3, &int3); + UT_PTR_SET(pointer1, &int4); + UnityPointer_UndoAllSets(); + TEST_ASSERT_POINTERS_EQUAL(pointer1, 0); + TEST_ASSERT_POINTERS_EQUAL(pointer2, (int*)2); + TEST_ASSERT_POINTERS_EQUAL(pointer3, (int*)3); +} + +static char *p1; +static char *p2; + +TEST(UnityFixture, PointerSet) +{ + char c1; + char c2; + char newC1; + char newC2; + p1 = &c1; + p2 = &c2; + + UnityPointer_Init(); + UT_PTR_SET(p1, &newC1); + UT_PTR_SET(p2, &newC2); + TEST_ASSERT_POINTERS_EQUAL(&newC1, p1); + TEST_ASSERT_POINTERS_EQUAL(&newC2, p2); + UnityPointer_UndoAllSets(); + TEST_ASSERT_POINTERS_EQUAL(&c1, p1); + TEST_ASSERT_POINTERS_EQUAL(&c2, p2); +} + +TEST(UnityFixture, FreeNULLSafety) +{ + free(NULL); +} + +TEST(UnityFixture, ConcludeTestIncrementsFailCount) +{ + UNITY_UINT savedFails = Unity.TestFailures; + UNITY_UINT savedIgnores = Unity.TestIgnores; + Unity.CurrentTestFailed = 1; + UnityConcludeFixtureTest(); /* Resets TestFailed for this test to pass */ + Unity.CurrentTestIgnored = 1; + UnityConcludeFixtureTest(); /* Resets TestIgnored */ + TEST_ASSERT_EQUAL(savedFails + 1, Unity.TestFailures); + TEST_ASSERT_EQUAL(savedIgnores + 1, Unity.TestIgnores); + Unity.TestFailures = savedFails; + Unity.TestIgnores = savedIgnores; +} + +/*------------------------------------------------------------ */ + +TEST_GROUP(UnityCommandOptions); + +static int savedVerbose; +static unsigned int savedRepeat; +static const char* savedName; +static const char* savedGroup; + +TEST_SETUP(UnityCommandOptions) +{ + savedVerbose = UnityFixture.Verbose; + savedRepeat = UnityFixture.RepeatCount; + savedName = UnityFixture.NameFilter; + savedGroup = UnityFixture.GroupFilter; +} + +TEST_TEAR_DOWN(UnityCommandOptions) +{ + UnityFixture.Verbose = savedVerbose; + UnityFixture.RepeatCount= savedRepeat; + UnityFixture.NameFilter = savedName; + UnityFixture.GroupFilter = savedGroup; +} + + +static const char* noOptions[] = { + "testrunner.exe" +}; + +TEST(UnityCommandOptions, DefaultOptions) +{ + UnityGetCommandLineOptions(1, noOptions); + TEST_ASSERT_EQUAL(0, UnityFixture.Verbose); + TEST_ASSERT_POINTERS_EQUAL(0, UnityFixture.GroupFilter); + TEST_ASSERT_POINTERS_EQUAL(0, UnityFixture.NameFilter); + TEST_ASSERT_EQUAL(1, UnityFixture.RepeatCount); +} + +static const char* verbose[] = { + "testrunner.exe", + "-v" +}; + +TEST(UnityCommandOptions, OptionVerbose) +{ + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(2, verbose)); + TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); +} + +static const char* group[] = { + "testrunner.exe", + "-g", "groupname" +}; + +TEST(UnityCommandOptions, OptionSelectTestByGroup) +{ + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, group)); + STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); +} + +static const char* name[] = { + "testrunner.exe", + "-n", "testname" +}; + +TEST(UnityCommandOptions, OptionSelectTestByName) +{ + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, name)); + STRCMP_EQUAL("testname", UnityFixture.NameFilter); +} + +static const char* repeat[] = { + "testrunner.exe", + "-r", "99" +}; + +TEST(UnityCommandOptions, OptionSelectRepeatTestsDefaultCount) +{ + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(2, repeat)); + TEST_ASSERT_EQUAL(2, UnityFixture.RepeatCount); +} + +TEST(UnityCommandOptions, OptionSelectRepeatTestsSpecificCount) +{ + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, repeat)); + TEST_ASSERT_EQUAL(99, UnityFixture.RepeatCount); +} + +static const char* multiple[] = { + "testrunner.exe", + "-v", + "-g", "groupname", + "-n", "testname", + "-r", "98" +}; + +TEST(UnityCommandOptions, MultipleOptions) +{ + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(8, multiple)); + TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); + STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); + STRCMP_EQUAL("testname", UnityFixture.NameFilter); + TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount); +} + +static const char* dashRNotLast[] = { + "testrunner.exe", + "-v", + "-g", "gggg", + "-r", + "-n", "tttt", +}; + +TEST(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified) +{ + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(7, dashRNotLast)); + TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); + STRCMP_EQUAL("gggg", UnityFixture.GroupFilter); + STRCMP_EQUAL("tttt", UnityFixture.NameFilter); + TEST_ASSERT_EQUAL(2, UnityFixture.RepeatCount); +} + +static const char* unknownCommand[] = { + "testrunner.exe", + "-v", + "-g", "groupname", + "-n", "testname", + "-r", "98", + "-z" +}; +TEST(UnityCommandOptions, UnknownCommandIsIgnored) +{ + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(9, unknownCommand)); + TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); + STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); + STRCMP_EQUAL("testname", UnityFixture.NameFilter); + TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount); +} + +TEST(UnityCommandOptions, GroupOrNameFilterWithoutStringFails) +{ + TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(3, unknownCommand)); + TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(5, unknownCommand)); + TEST_ASSERT_EQUAL(1, UnityMain(3, unknownCommand, NULL)); +} + +TEST(UnityCommandOptions, GroupFilterReallyFilters) +{ + UNITY_UINT saved = Unity.NumberOfTests; + TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(4, unknownCommand)); + UnityIgnoreTest(NULL, "non-matching", NULL); + TEST_ASSERT_EQUAL(saved, Unity.NumberOfTests); +} + +IGNORE_TEST(UnityCommandOptions, TestShouldBeIgnored) +{ + TEST_FAIL_MESSAGE("This test should not run!"); +} diff --git a/deps/Unity/extras/fixture/test/unity_fixture_TestRunner.c b/deps/Unity/extras/fixture/test/unity_fixture_TestRunner.c new file mode 100644 index 0000000..7b78c49 --- /dev/null +++ b/deps/Unity/extras/fixture/test/unity_fixture_TestRunner.c @@ -0,0 +1,32 @@ +/* Copyright (c) 2010 James Grenning and Contributed to Unity Project + * ========================================== + * Unity Project - A Test Framework for C + * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams + * [Released under MIT License. Please refer to license.txt for details] + * ========================================== */ + +#include "unity_fixture.h" + +TEST_GROUP_RUNNER(UnityFixture) +{ + RUN_TEST_CASE(UnityFixture, PointerSetting); + RUN_TEST_CASE(UnityFixture, PointerSet); + RUN_TEST_CASE(UnityFixture, FreeNULLSafety); + RUN_TEST_CASE(UnityFixture, ConcludeTestIncrementsFailCount); +} + +TEST_GROUP_RUNNER(UnityCommandOptions) +{ + RUN_TEST_CASE(UnityCommandOptions, DefaultOptions); + RUN_TEST_CASE(UnityCommandOptions, OptionVerbose); + RUN_TEST_CASE(UnityCommandOptions, OptionSelectTestByGroup); + RUN_TEST_CASE(UnityCommandOptions, OptionSelectTestByName); + RUN_TEST_CASE(UnityCommandOptions, OptionSelectRepeatTestsDefaultCount); + RUN_TEST_CASE(UnityCommandOptions, OptionSelectRepeatTestsSpecificCount); + RUN_TEST_CASE(UnityCommandOptions, MultipleOptions); + RUN_TEST_CASE(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified); + RUN_TEST_CASE(UnityCommandOptions, UnknownCommandIsIgnored); + RUN_TEST_CASE(UnityCommandOptions, GroupOrNameFilterWithoutStringFails); + RUN_TEST_CASE(UnityCommandOptions, GroupFilterReallyFilters); + RUN_TEST_CASE(UnityCommandOptions, TestShouldBeIgnored); +} |