提交 f39f8a77 编写于 作者: G greg-williams

Updated makefile to run tests after building and added :clean and :all tasks.

Added UnityHelper module in order to show how to extend Unity.

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@2 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
上级 720acfbb
C_COMPILER=gcc
OUT_FILE=-o testunity
TARGET_BASE = testunity
ifeq ($(OS),Windows_NT)
OUT_EXTENSION=.exe
TARGET_EXTENSION=.exe
else
OUT_EXTENSION=.out
TARGET_EXTENSION=.out
endif
TARGET = $(TARGET_BASE)$(TARGET_EXTENSION)
OUT_FILE=-o $(TARGET)
SRC_FILES=src/unity.c test/testunity.c test/testunity_Runner.c
INC_DIRS=-Isrc
SYMBOLS=-DTEST
ifeq ($(OS),Windows_NT)
CLEANUP = del /F /Q bin\* && del /F /Q $(TARGET)
else
CLEANUP = rm -f bin/*.o ; rm -f $(TARGET)
endif
all: clean default
default:
$(C_COMPILER) $(INC_DIRS) $(SYMBOLS) $(SRC_FILES) $(OUT_FILE)$(OUT_EXTENSION)
$(TARGET)
clean:
$(CLEANUP)
#include "unity.h"
#include "UnityHelper.h"
#include <stdio.h>
#include <string.h>
static char message[1024];
void AssertEqualArrayUint(unsigned int* expected, unsigned int* actual, unsigned int length)
{
unsigned int i;
for (i = 0; i < length; i++)
{
sprintf(message, "Array comparison failed at index %u.", i);
TEST_ASSERT_EQUAL_UINT_MESSAGE(expected[i], actual[i], message);
}
}
void AssertEqualArrayInt(int* expected, int* actual, unsigned int length)
{
unsigned int i;
for (i = 0; i < length; i++)
{
sprintf(message, "Array comparison failed at index %u.", i);
TEST_ASSERT_EQUAL_INT_MESSAGE(expected[i], actual[i], message);
}
}
void AssertEqualArrayFloatWithin(float tolerance, float* expected, float* actual, unsigned int length)
{
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]));
TEST_ASSERT_FLOAT_WITHIN_MESSAGE(tolerance, expected[i], actual[i], message);
}
}
#ifndef _TESTHELPER_H
#define _TESTHELPER_H
void AssertEqualArrayUint(unsigned int* expected, unsigned int* actual, unsigned int length);
void AssertEqualArrayInt(int* expected, int* actual, unsigned int length);
void AssertEqualArrayFloatWithin(float tolerance, float* expected, float* actual, unsigned int length);
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, length) {TEST_WRAP(AssertEqualArrayUint(expected, actual, length));}
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {TEST_WRAP(AssertEqualArrayInt(expected, actual, length));}
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {TEST_WRAP(AssertEqualArrayFloatWithin(tolerance, expected, actual, length));}
#endif // _TESTHELPER_H
......@@ -334,3 +334,7 @@ void UnityEnd(void)
}
}
int UnityGetNumFailures(void)
{
return Unity.TestFailures;
}
......@@ -34,6 +34,7 @@ void CreateResults();
void UnityBegin();
void UnityEnd(void);
int UnityGetNumFailures(void);
void UnityPrintChar(char ch);
void UnityPrint(const char *string);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册