mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-12-18 23:11:11 +08:00
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:
21
makefile
21
makefile
@@ -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
39
src/UnityHelper.c
Normal 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
12
src/UnityHelper.h
Normal 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
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user