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
This commit is contained in:
greg-williams
2008-05-11 19:30:41 +00:00
parent 720acfbb95
commit f39f8a7701
5 changed files with 74 additions and 3 deletions

View File

@@ -1,13 +1,28 @@
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)

39
src/UnityHelper.c Normal file
View File

@@ -0,0 +1,39 @@
#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);
}
}

12
src/UnityHelper.h Normal file
View File

@@ -0,0 +1,12 @@
#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

View File

@@ -334,3 +334,7 @@ void UnityEnd(void)
}
}
int UnityGetNumFailures(void)
{
return Unity.TestFailures;
}

View File

@@ -34,6 +34,7 @@ void CreateResults();
void UnityBegin();
void UnityEnd(void);
int UnityGetNumFailures(void);
void UnityPrintChar(char ch);
void UnityPrint(const char *string);