提交 3fbc034e 编写于 作者: M mvandervoord

- restored examples to working condition

- restored makefiles to working condition
- updated files to include copyright notice
- fixed bug in string array comparisons
- ignored tests no longer run teardown
- tests failing for uncaught cexceptions now get exception id reported

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@70 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
上级 12d4d143
# ==========================================
# 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]
# ==========================================
if RUBY_PLATFORM =~/(win|w)32$/
begin
require 'Win32API'
......
# ==========================================
# 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]
# ==========================================
require "#{File.expand_path(File.dirname(__FILE__))}/colour_prompt"
......
# ==========================================
# 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]
# ==========================================
# This script creates all the files with start code necessary for a new module.
# A simple module only requires a source file, header file, and test file.
# Triad modules require a source, header, and test file for each triad type (like model, conductor, and hardware).
......
# ==========================================
# 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]
# ==========================================
File.expand_path(File.join(File.dirname(__FILE__),'colour_prompt'))
class UnityTestRunnerGenerator
......@@ -187,10 +193,10 @@ class UnityTestRunnerGenerator
output.puts(" setUp();")
output.puts(" test();")
output.puts(" CMock_Verify();") unless (used_mocks.empty?)
output.puts(" } Catch(e) { TEST_FAIL(\"Unhandled Exception!\"); }") if @options[:cexception]
output.puts(" } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, \"Unhandled Exception!\"); }") if @options[:cexception]
output.puts(" }")
output.puts(" CMock_Destroy();") unless (used_mocks.empty?)
output.puts(" if (TEST_PROTECT())")
output.puts(" if (TEST_PROTECT() && !TEST_IS_IGNORED)")
output.puts(" {")
output.puts(" tearDown();")
output.puts(" }")
......
# ==========================================
# 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]
# ==========================================
require'yaml'
module RakefileHelpers
......
# ==========================================
# 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]
# ==========================================
#!/usr/bin/ruby
#
# unity_test_summary.rb
......
此差异由.gitattributes 抑制。
此差异由.gitattributes 抑制。
......@@ -2,6 +2,8 @@
Unity Test API
==============
[Copyright (c) 2007 - Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams]
-------------
Running Tests
-------------
......
......@@ -3,19 +3,6 @@
#include <stdio.h>
#include <string.h>
static char message[1024];
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length, const unsigned short line)
{
unsigned int i;
for (i = 0; i < length; i++)
{
sprintf(message, "Array mismatch at index %u, Expected %f, Actual %f, Tolerance %f, Delta %f", i, expected[i], actual[i], tolerance, (expected[i]-actual[i]));
UNITY_TEST_ASSERT_WITHIN_FLOAT(tolerance, expected[i], actual[i], line, message);
}
}
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual, const unsigned short line)
{
UNITY_TEST_ASSERT_EQUAL_INT(expected.x, actual.x, line, "Example Struct Failed For Field x");
......
......@@ -3,13 +3,10 @@
#include "Types.h"
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length, const unsigned short line);
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual, const unsigned short line);
#define UNITY_TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length, line, message) AssertFloatArrayWithin(tolerance, expected, actual, length, line);
#define UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, line, message) AssertEqualExampleStruct(expected, actual, line);
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) UNITY_TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, __LINE__, NULL);
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) UNITY_TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual, __LINE__, NULL);
#endif // _TESTHELPER_H
......@@ -31,8 +31,8 @@ compiler:
items:
- [*tools_root, 'arm\inc\']
- 'src\'
- '../src/'
- *unit_tests_path
- 'vendor\unity\src\'
defines:
prefix: '-D'
items:
......
......@@ -30,9 +30,8 @@ compiler:
items:
- [*tools_root, 'arm\inc\']
- 'src\'
- '../src/'
- *unit_tests_path
- 'vendor\unity\src\'
- 'iar\iar_v5\incIAR\'
defines:
prefix: '-D'
items:
......
# ==========================================
# 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]
# ==========================================
C_COMPILER=gcc
TARGET_BASE1=test1
TARGET_BASE2=test2
ifeq ($(OS),Windows_NT)
TARGET_EXTENSION=.exe
else
TARGET_EXTENSION=.out
endif
TARGET1 = $(TARGET_BASE1)$(TARGET_EXTENSION)
TARGET2 = $(TARGET_BASE2)$(TARGET_EXTENSION)
SRC_FILES1=../src/unity.c src/ProductionCode.c test/TestProductionCode.c test/no_ruby/TestProductionCode_Runner.c
SRC_FILES2=../src/unity.c src/ProductionCode2.c test/TestProductionCode2.c test/no_ruby/TestProductionCode2_Runner.c
INC_DIRS=-Isrc -I../src
SYMBOLS=-DTEST
ifeq ($(OS),Windows_NT)
CLEANUP = del /F /Q build\* && del /F /Q $(TARGET1) && del /F /Q $(TARGET2)
else
CLEANUP = rm -f build/*.o ; rm -f $(TARGET1) ; rm -f $(TARGET2)
endif
all: clean default
default:
# ruby auto/generate_test_runner.rb test/TestProductionCode.c test/no_ruby/TestProductionCode_Runner.c
# ruby auto/generate_test_runner.rb test/TestProductionCode2.c test/no_ruby/TestProductionCode2_Runner.c
$(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES1) -o $(TARGET1)
$(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES2) -o $(TARGET2)
$(TARGET1)
$(TARGET2)
clean:
$(CLEANUP)
Example Project
This example project gives an example of some passing, ignored, and failing tests.
It's simple and meant for you to look over and get an idea for what all of this stuff does.
You can build and test using the makefile if you have gcc installed (you may need to tweak
the locations of some tools in the makefile). Otherwise, the rake version will let you
test with gcc or a couple versions of IAR. You can tweak the yaml files to get those versions
running.
Ruby is required if you're using the rake version (obviously). This version shows off most of
Unity's advanced features (automatically creating test runners, fancy summaries, etc.)
The makefile version doesn't require anything outside of your normal build tools, but won't do the
extras for you. So that you can test right away, we've written the test runners for you and
put them in the test\no_ruby subdirectory. If you make changes to the tests or source, you might
need to update these (like when you add or remove tests). Do that for a while and you'll learn
why you really want to start using the Ruby tools.
\ No newline at end of file
......@@ -5,4 +5,5 @@ char* ThisFunctionHasNotBeenTested(int Poor, char* 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;
}
/* AUTOGENERATED FILE. DO NOT EDIT. */
#include "unity.h"
#include <setjmp.h>
#include <stdio.h>
char MessageBuffer[50];
extern void setUp(void);
extern void tearDown(void);
extern void test_IgnoredTest(void);
extern void test_AnotherIgnoredTest(void);
extern void test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented(void);
static void runTest(UnityTestFunction test)
{
if (TEST_PROTECT())
{
setUp();
test();
}
if (TEST_PROTECT() && !TEST_IS_IGNORED)
{
tearDown();
}
}
void resetTest()
{
tearDown();
setUp();
}
int main(void)
{
Unity.TestFile = "test/TestProductionCode2.c";
UnityBegin();
// RUN_TEST calls runTest
RUN_TEST(test_IgnoredTest, 13);
RUN_TEST(test_AnotherIgnoredTest, 18);
RUN_TEST(test_ThisFunctionHasNotBeenTested_NeedsToBeImplemented, 23);
UnityEnd();
return 0;
}
/* AUTOGENERATED FILE. DO NOT EDIT. */
#include "unity.h"
#include <setjmp.h>
#include <stdio.h>
char MessageBuffer[50];
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);
static void runTest(UnityTestFunction test)
{
if (TEST_PROTECT())
{
setUp();
test();
}
if (TEST_PROTECT() && !TEST_IS_IGNORED)
{
tearDown();
}
}
void resetTest()
{
tearDown();
setUp();
}
int main(void)
{
Unity.TestFile = "test/TestProductionCode.c";
UnityBegin();
// RUN_TEST calls runTest
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);
UnityEnd();
return 0;
}
# ==========================================
# 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]
# ==========================================
C_COMPILER=gcc
TARGET_BASE = testunity
ifeq ($(OS),Windows_NT)
......@@ -7,7 +13,7 @@ else
endif
TARGET = $(TARGET_BASE)$(TARGET_EXTENSION)
OUT_FILE=-o $(TARGET)
SRC_FILES=src/unity.c test/testunity.c test/testunity_Runner.c
SRC_FILES=src/unity.c test/testunity.c build/testunity_Runner.c
INC_DIRS=-Isrc
SYMBOLS=-DTEST
......@@ -20,7 +26,8 @@ endif
all: clean default
default:
$(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) $(OUT_FILE)$(OUT_EXTENSION)
ruby auto/generate_test_runner.rb test/testunity.c build/testunity_Runner.c
$(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) $(OUT_FILE)
$(TARGET)
clean:
......
# ==========================================
# 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]
# ==========================================
HERE = File.expand_path(File.dirname(__FILE__)) + '/'
#require HERE + 'config/environment'
......
# ==========================================
# 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]
# ==========================================
require 'yaml'
require 'fileutils'
require 'auto/unity_test_summary'
......
/* ==========================================
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.h"
#include <stdio.h>
#include <string.h>
......@@ -459,6 +465,7 @@ void UnityAssertEqualString(const char* expected,
if (expected[i] != actual[i])
{
Unity.CurrentTestFailed = 1;
break;
}
}
}
......
/* ==========================================
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_FRAMEWORK_H
#define UNITY_FRAMEWORK_H
......@@ -41,6 +47,7 @@
UnityConcludeTest();
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
//-------------------------------------------------------
// Basic Fail and Ignore
......
/* ==========================================
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_INTERNALS_H
#define UNITY_INTERNALS_H
......@@ -70,6 +76,10 @@ typedef UNITY_FLOAT_TYPE _UF;
#define UNITY_LINE_TYPE unsigned short
#endif
#ifndef UNITY_COUNTER_TYPE
#define UNITY_COUNTER_TYPE unsigned short
#endif
//-------------------------------------------------------
// Internal Structs Needed
//-------------------------------------------------------
......@@ -90,11 +100,11 @@ struct _Unity
const char* TestFile;
const char* CurrentTestName;
_UU32 CurrentTestLineNumber;
unsigned char NumberOfTests;
unsigned char TestFailures;
unsigned char TestIgnores;
unsigned char CurrentTestFailed;
unsigned char CurrentTestIgnored;
UNITY_COUNTER_TYPE NumberOfTests;
UNITY_COUNTER_TYPE TestFailures;
UNITY_COUNTER_TYPE TestIgnores;
UNITY_COUNTER_TYPE CurrentTestFailed;
UNITY_COUNTER_TYPE CurrentTestIgnored;
jmp_buf AbortFrame;
};
......
#define UNITY_ENABLE_EXTERNAL_ASSERTIONS
/* ==========================================
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 <setjmp.h>
#include "unity.h"
......@@ -17,12 +21,17 @@
TEST_ASSERT_MESSAGE((1u == failed), "<---- [ This Test Should Have Failed But Did Not ]"); \
EXPECT_ABORT_END
int SetToOneToFailInTearDown;
void setUp(void)
{
SetToOneToFailInTearDown = 0;
}
void tearDown(void)
{
if (SetToOneToFailInTearDown == 1)
TEST_FAIL("Failed in tearDown");
}
void testTrue(void)
......@@ -429,6 +438,25 @@ void testEqualHex8s(void)
TEST_ASSERT_EQUAL_HEX8(*p0, 0x22);
}
void testEqualHex8sNegatives(void)
{
_UU8 v0, v1;
_UU8 *p0, *p1;
v0 = 0xDD;
v1 = 0xDD;
p0 = &v0;
p1 = &v1;
TEST_ASSERT_EQUAL_HEX8(0xDD, 0xDD);
TEST_ASSERT_EQUAL_HEX8(v0, v1);
TEST_ASSERT_EQUAL_HEX8(0xDD, v1);
TEST_ASSERT_EQUAL_HEX8(v0, 0xDD);
TEST_ASSERT_EQUAL_HEX8(*p0, v1);
TEST_ASSERT_EQUAL_HEX8(*p0, *p1);
TEST_ASSERT_EQUAL_HEX8(*p0, 0xDD);
}
void testEqualHex16s(void)
{
_UU16 v0, v1;
......@@ -689,7 +717,7 @@ void testUIntsNotWithinDelta(void)
int failed;
EXPECT_ABORT_BEGIN
TEST_ASSERT_UINT_WITHIN(1, 2147483647, 2147483649);
TEST_ASSERT_UINT_WITHIN(1, 2147483647u, 2147483649u);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
......@@ -738,7 +766,7 @@ void testHEX32sNotWithinDelta(void)
int failed;
EXPECT_ABORT_BEGIN
TEST_ASSERT_HEX32_WITHIN(1, 2147483647, 2147483649);
TEST_ASSERT_HEX32_WITHIN(1, 2147483647u, 2147483649u);
EXPECT_ABORT_END
failed = Unity.CurrentTestFailed;
......@@ -1477,3 +1505,8 @@ void testProtection(void)
TEST_ASSERT_EQUAL(3, mask);
}
void testIgnoredAndThenFailInTearDown(void)
{
SetToOneToFailInTearDown = 1;
TEST_IGNORE();
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册