summaryrefslogtreecommitdiff
path: root/deps/Unity/examples/example_1
diff options
context:
space:
mode:
Diffstat (limited to 'deps/Unity/examples/example_1')
-rw-r--r--deps/Unity/examples/example_1/makefile72
-rw-r--r--deps/Unity/examples/example_1/meson.build48
-rw-r--r--deps/Unity/examples/example_1/readme.txt12
-rw-r--r--deps/Unity/examples/example_1/src/ProductionCode.c24
-rw-r--r--deps/Unity/examples/example_1/src/ProductionCode.h3
-rw-r--r--deps/Unity/examples/example_1/src/ProductionCode2.c11
-rw-r--r--deps/Unity/examples/example_1/src/ProductionCode2.h2
-rw-r--r--deps/Unity/examples/example_1/subprojects/unity.wrap3
-rw-r--r--deps/Unity/examples/example_1/test/TestProductionCode.c62
-rw-r--r--deps/Unity/examples/example_1/test/TestProductionCode2.c31
-rw-r--r--deps/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c53
-rw-r--r--deps/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c57
12 files changed, 378 insertions, 0 deletions
diff --git a/deps/Unity/examples/example_1/makefile b/deps/Unity/examples/example_1/makefile
new file mode 100644
index 0000000..28409c1
--- /dev/null
+++ b/deps/Unity/examples/example_1/makefile
@@ -0,0 +1,72 @@
+# ==========================================
+# 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]
+# ==========================================
+
+#We try to detect the OS we are running on, and adjust commands as needed
+ifeq ($(OS),Windows_NT)
+ ifeq ($(shell uname -s),) # not in a bash-like shell
+ CLEANUP = del /F /Q
+ MKDIR = mkdir
+ else # in a bash-like shell, like msys
+ CLEANUP = rm -f
+ MKDIR = mkdir -p
+ endif
+ TARGET_EXTENSION=.exe
+else
+ CLEANUP = rm -f
+ MKDIR = mkdir -p
+ TARGET_EXTENSION=.out
+endif
+
+C_COMPILER=gcc
+ifeq ($(shell uname -s), Darwin)
+C_COMPILER=clang
+endif
+
+UNITY_ROOT=../..
+
+CFLAGS=-std=c89
+CFLAGS += -Wall
+CFLAGS += -Wextra
+CFLAGS += -Wpointer-arith
+CFLAGS += -Wcast-align
+CFLAGS += -Wwrite-strings
+CFLAGS += -Wswitch-default
+CFLAGS += -Wunreachable-code
+CFLAGS += -Winit-self
+CFLAGS += -Wmissing-field-initializers
+CFLAGS += -Wno-unknown-pragmas
+CFLAGS += -Wstrict-prototypes
+CFLAGS += -Wundef
+CFLAGS += -Wold-style-definition
+#CFLAGS += -Wno-misleading-indentation
+
+TARGET_BASE1=test1
+TARGET_BASE2=test2
+TARGET1 = $(TARGET_BASE1)$(TARGET_EXTENSION)
+TARGET2 = $(TARGET_BASE2)$(TARGET_EXTENSION)
+SRC_FILES1=$(UNITY_ROOT)/src/unity.c src/ProductionCode.c test/TestProductionCode.c test/test_runners/TestProductionCode_Runner.c
+SRC_FILES2=$(UNITY_ROOT)/src/unity.c src/ProductionCode2.c test/TestProductionCode2.c test/test_runners/TestProductionCode2_Runner.c
+INC_DIRS=-Isrc -I$(UNITY_ROOT)/src
+SYMBOLS=
+
+all: clean default
+
+default: $(SRC_FILES1) $(SRC_FILES2)
+ $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES1) -o $(TARGET1)
+ $(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES2) -o $(TARGET2)
+ - ./$(TARGET1)
+ - ./$(TARGET2)
+
+test/test_runners/TestProductionCode_Runner.c: test/TestProductionCode.c
+ ruby $(UNITY_ROOT)/auto/generate_test_runner.rb test/TestProductionCode.c test/test_runners/TestProductionCode_Runner.c
+test/test_runners/TestProductionCode2_Runner.c: test/TestProductionCode2.c
+ ruby $(UNITY_ROOT)/auto/generate_test_runner.rb test/TestProductionCode2.c test/test_runners/TestProductionCode2_Runner.c
+
+clean:
+ $(CLEANUP) $(TARGET1) $(TARGET2)
+
+ci: CFLAGS += -Werror
+ci: default
diff --git a/deps/Unity/examples/example_1/meson.build b/deps/Unity/examples/example_1/meson.build
new file mode 100644
index 0000000..645eeb9
--- /dev/null
+++ b/deps/Unity/examples/example_1/meson.build
@@ -0,0 +1,48 @@
+project('Unity example', 'c',
+ license: 'MIT',
+ default_options: [
+ 'c_std=c99',
+ 'warning_level=3',
+ ],
+ meson_version: '>= 0.49.0'
+)
+
+unity_subproject = subproject('unity')
+unity_dependency = unity_subproject.get_variable('unity_dep')
+unity_gen_runner = unity_subproject.get_variable('gen_test_runner')
+
+src1 = files([
+ 'src' / 'ProductionCode.c',
+ 'test' / 'TestProductionCode.c',
+])
+
+src2 = files([
+ 'src' / 'ProductionCode2.c',
+ 'test' / 'TestProductionCode2.c',
+])
+
+inc = include_directories('src')
+
+test1 = executable('test1',
+ sources: [
+ src1,
+ unity_gen_runner.process('test' / 'TestProductionCode.c')
+ ],
+ include_directories: [ inc ],
+ dependencies: [ unity_dependency ],
+)
+
+test('test1', test1,
+ should_fail: true)
+
+test2 = executable('test2',
+ sources: [
+ src2,
+ unity_gen_runner.process('test' / 'TestProductionCode2.c')
+ ],
+ include_directories: [ inc ],
+ dependencies: [ unity_dependency ],
+)
+
+test('test2', test2)
+
diff --git a/deps/Unity/examples/example_1/readme.txt b/deps/Unity/examples/example_1/readme.txt
new file mode 100644
index 0000000..ddddd36
--- /dev/null
+++ b/deps/Unity/examples/example_1/readme.txt
@@ -0,0 +1,12 @@
+Example 1
+=========
+
+Close to the simplest possible example of Unity, using only basic features.
+
+Build and run with Make
+---
+Just run `make`.
+
+Build and run with Meson
+---
+Run `meson setup build` to create the build directory, and then `meson test -C build` to build and run the tests.
diff --git a/deps/Unity/examples/example_1/src/ProductionCode.c b/deps/Unity/examples/example_1/src/ProductionCode.c
new file mode 100644
index 0000000..db128e5
--- /dev/null
+++ b/deps/Unity/examples/example_1/src/ProductionCode.c
@@ -0,0 +1,24 @@
+
+#include "ProductionCode.h"
+
+int Counter = 0;
+int NumbersToFind[9] = { 0, 34, 55, 66, 32, 11, 1, 77, 888 }; /* some obnoxious array to search that is 1-based indexing instead of 0. */
+
+/* This function is supposed to search through NumbersToFind and find a particular number.
+ * If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since
+ * NumbersToFind is indexed from 1. Unfortunately it's broken
+ * (and should therefore be caught by our tests) */
+int FindFunction_WhichIsBroken(int NumberToFind)
+{
+ int i = 0;
+ while (i < 8) /* Notice I should have been in braces */
+ i++;
+ if (NumbersToFind[i] == NumberToFind) /* Yikes! I'm getting run after the loop finishes instead of during it! */
+ return i;
+ return 0;
+}
+
+int FunctionWhichReturnsLocalVariable(void)
+{
+ return Counter;
+}
diff --git a/deps/Unity/examples/example_1/src/ProductionCode.h b/deps/Unity/examples/example_1/src/ProductionCode.h
new file mode 100644
index 0000000..250ca0d
--- /dev/null
+++ b/deps/Unity/examples/example_1/src/ProductionCode.h
@@ -0,0 +1,3 @@
+
+int FindFunction_WhichIsBroken(int NumberToFind);
+int FunctionWhichReturnsLocalVariable(void);
diff --git a/deps/Unity/examples/example_1/src/ProductionCode2.c b/deps/Unity/examples/example_1/src/ProductionCode2.c
new file mode 100644
index 0000000..98ee7ee
--- /dev/null
+++ b/deps/Unity/examples/example_1/src/ProductionCode2.c
@@ -0,0 +1,11 @@
+
+#include "ProductionCode2.h"
+
+char* ThisFunctionHasNotBeenTested(int Poor, char* LittleFunction)
+{
+ (void)Poor;
+ (void)LittleFunction;
+ /* Since There Are No Tests Yet, This Function Could Be Empty For All We Know.
+ * Which isn't terribly useful... but at least we put in a TEST_IGNORE so we won't forget */
+ return (char*)0;
+}
diff --git a/deps/Unity/examples/example_1/src/ProductionCode2.h b/deps/Unity/examples/example_1/src/ProductionCode2.h
new file mode 100644
index 0000000..34ae980
--- /dev/null
+++ b/deps/Unity/examples/example_1/src/ProductionCode2.h
@@ -0,0 +1,2 @@
+
+char* ThisFunctionHasNotBeenTested(int Poor, char* LittleFunction);
diff --git a/deps/Unity/examples/example_1/subprojects/unity.wrap b/deps/Unity/examples/example_1/subprojects/unity.wrap
new file mode 100644
index 0000000..6df241b
--- /dev/null
+++ b/deps/Unity/examples/example_1/subprojects/unity.wrap
@@ -0,0 +1,3 @@
+[wrap-git]
+url = https://github.com/ThrowTheSwitch/Unity.git
+revision = head
diff --git a/deps/Unity/examples/example_1/test/TestProductionCode.c b/deps/Unity/examples/example_1/test/TestProductionCode.c
new file mode 100644
index 0000000..404c371
--- /dev/null
+++ b/deps/Unity/examples/example_1/test/TestProductionCode.c
@@ -0,0 +1,62 @@
+
+#include "ProductionCode.h"
+#include "unity.h"
+
+/* sometimes you may want to get at local data in a module.
+ * for example: If you plan to pass by reference, this could be useful
+ * however, it should often be avoided */
+extern int Counter;
+
+void setUp(void)
+{
+ /* This is run before EACH TEST */
+ Counter = 0x5a5a;
+}
+
+void tearDown(void)
+{
+}
+
+void test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode(void)
+{
+ /* All of these should pass */
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(78));
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(2));
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(33));
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(999));
+ TEST_ASSERT_EQUAL(0, FindFunction_WhichIsBroken(-1));
+}
+
+void test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken(void)
+{
+ /* You should see this line fail in your test summary */
+ TEST_ASSERT_EQUAL(1, FindFunction_WhichIsBroken(34));
+
+ /* Notice the rest of these didn't get a chance to run because the line above failed.
+ * Unit tests abort each test function on the first sign of trouble.
+ * Then NEXT test function runs as normal. */
+ TEST_ASSERT_EQUAL(8, FindFunction_WhichIsBroken(8888));
+}
+
+void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue(void)
+{
+ /* This should be true because setUp set this up for us before this test */
+ TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable());
+
+ /* This should be true because we can still change our answer */
+ Counter = 0x1234;
+ TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable());
+}
+
+void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain(void)
+{
+ /* This should be true again because setup was rerun before this test (and after we changed it to 0x1234) */
+ TEST_ASSERT_EQUAL_HEX(0x5a5a, FunctionWhichReturnsLocalVariable());
+}
+
+void test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed(void)
+{
+ /* Sometimes you get the test wrong. When that happens, you get a failure too... and a quick look should tell
+ * you what actually happened...which in this case was a failure to setup the initial condition. */
+ TEST_ASSERT_EQUAL_HEX(0x1234, FunctionWhichReturnsLocalVariable());
+}
diff --git a/deps/Unity/examples/example_1/test/TestProductionCode2.c b/deps/Unity/examples/example_1/test/TestProductionCode2.c
new file mode 100644
index 0000000..7d940c1
--- /dev/null
+++ b/deps/Unity/examples/example_1/test/TestProductionCode2.c
@@ -0,0 +1,31 @@
+
+#include "ProductionCode2.h"
+#include "unity.h"
+
+/* These should be ignored because they are commented out in various ways:
+#include "whatever.h"
+#include "somethingelse.h"
+*/
+
+void setUp(void)
+{
+}
+
+void tearDown(void)
+{
+}
+
+void test_IgnoredTest(void)
+{
+ TEST_IGNORE_MESSAGE("This Test Was Ignored On Purpose");
+}
+
+void test_AnotherIgnoredTest(void)
+{
+ TEST_IGNORE_MESSAGE("These Can Be Useful For Leaving Yourself Notes On What You Need To Do Yet");
+}
+
+void test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented(void)
+{
+ TEST_IGNORE(); /* Like This */
+}
diff --git a/deps/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c b/deps/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c
new file mode 100644
index 0000000..cf72c21
--- /dev/null
+++ b/deps/Unity/examples/example_1/test/test_runners/TestProductionCode2_Runner.c
@@ -0,0 +1,53 @@
+/* AUTOGENERATED FILE. DO NOT EDIT. */
+
+/*=======Test Runner Used To Run Each Test Below=====*/
+#define RUN_TEST(TestFunc, TestLineNum) \
+{ \
+ Unity.CurrentTestName = #TestFunc; \
+ Unity.CurrentTestLineNumber = TestLineNum; \
+ Unity.NumberOfTests++; \
+ if (TEST_PROTECT()) \
+ { \
+ setUp(); \
+ TestFunc(); \
+ } \
+ if (TEST_PROTECT()) \
+ { \
+ tearDown(); \
+ } \
+ UnityConcludeTest(); \
+}
+
+/*=======Automagically Detected Files To Include=====*/
+#include "unity.h"
+#include <setjmp.h>
+#include <stdio.h>
+#include "ProductionCode2.h"
+
+/*=======External Functions This Runner Calls=====*/
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_IgnoredTest(void);
+extern void test_AnotherIgnoredTest(void);
+extern void test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented(void);
+
+
+/*=======Test Reset Option=====*/
+void resetTest(void);
+void resetTest(void)
+{
+ tearDown();
+ setUp();
+}
+
+
+/*=======MAIN=====*/
+int main(void)
+{
+ UnityBegin("test/TestProductionCode2.c");
+ RUN_TEST(test_IgnoredTest, 18);
+ RUN_TEST(test_AnotherIgnoredTest, 23);
+ RUN_TEST(test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented, 28);
+
+ return (UnityEnd());
+}
diff --git a/deps/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c b/deps/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c
new file mode 100644
index 0000000..3b49af7
--- /dev/null
+++ b/deps/Unity/examples/example_1/test/test_runners/TestProductionCode_Runner.c
@@ -0,0 +1,57 @@
+/* AUTOGENERATED FILE. DO NOT EDIT. */
+
+/*=======Test Runner Used To Run Each Test Below=====*/
+#define RUN_TEST(TestFunc, TestLineNum) \
+{ \
+ Unity.CurrentTestName = #TestFunc; \
+ Unity.CurrentTestLineNumber = TestLineNum; \
+ Unity.NumberOfTests++; \
+ if (TEST_PROTECT()) \
+ { \
+ setUp(); \
+ TestFunc(); \
+ } \
+ if (TEST_PROTECT()) \
+ { \
+ tearDown(); \
+ } \
+ UnityConcludeTest(); \
+}
+
+/*=======Automagically Detected Files To Include=====*/
+#include "unity.h"
+#include <setjmp.h>
+#include <stdio.h>
+#include "ProductionCode.h"
+
+/*=======External Functions This Runner Calls=====*/
+extern void setUp(void);
+extern void tearDown(void);
+extern void test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode(void);
+extern void test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken(void);
+extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue(void);
+extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain(void);
+extern void test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed(void);
+
+
+/*=======Test Reset Option=====*/
+void resetTest(void);
+void resetTest(void)
+{
+ tearDown();
+ setUp();
+}
+
+
+/*=======MAIN=====*/
+int main(void)
+{
+ UnityBegin("test/TestProductionCode.c");
+ RUN_TEST(test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWorksEvenInOurBrokenCode, 20);
+ RUN_TEST(test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWillFailBecauseOurFunctionUnderTestIsBroken, 30);
+ RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue, 41);
+ RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValueAgain, 51);
+ RUN_TEST(test_FunctionWhichReturnsLocalVariable_ShouldReturnCurrentCounter_ButFailsBecauseThisTestIsActuallyFlawed, 57);
+
+ return (UnityEnd());
+}