mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-06-20 22:13:29 +08:00
Make life easier for those creating their own runners:
* Add UNITY_BEGIN and UNITY_END macros to simplify usage * Improve RUN_TEST to make line_num optional where possible
This commit is contained in:
6
makefile
6
makefile
@ -2,7 +2,7 @@
|
|||||||
# Unity Project - A Test Framework for C
|
# Unity Project - A Test Framework for C
|
||||||
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||||
# [Released under MIT License. Please refer to license.txt for details]
|
# [Released under MIT License. Please refer to license.txt for details]
|
||||||
# ==========================================
|
# ==========================================
|
||||||
|
|
||||||
C_COMPILER=gcc
|
C_COMPILER=gcc
|
||||||
TARGET_BASE = testunity
|
TARGET_BASE = testunity
|
||||||
@ -15,7 +15,7 @@ TARGET = $(TARGET_BASE)$(TARGET_EXTENSION)
|
|||||||
OUT_FILE=-o $(TARGET)
|
OUT_FILE=-o $(TARGET)
|
||||||
SRC_FILES=src/unity.c test/testunity.c build/testunity_Runner.c
|
SRC_FILES=src/unity.c test/testunity.c build/testunity_Runner.c
|
||||||
INC_DIRS=-Isrc
|
INC_DIRS=-Isrc
|
||||||
SYMBOLS=-DTEST -DUNITY_SUPPORT_64
|
SYMBOLS=-DTEST -DUNITY_SUPPORT_64 -DUNITY_INCLUDE_DOUBLE
|
||||||
|
|
||||||
ifeq ($(OSTYPE),cygwin)
|
ifeq ($(OSTYPE),cygwin)
|
||||||
CLEANUP = rm -f build/*.o ; rm -f $(TARGET) ; mkdir -p build
|
CLEANUP = rm -f build/*.o ; rm -f $(TARGET) ; mkdir -p build
|
||||||
@ -34,4 +34,4 @@ default:
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(CLEANUP)
|
$(CLEANUP)
|
||||||
|
|
||||||
|
16
src/unity.c
16
src/unity.c
@ -1,15 +1,15 @@
|
|||||||
/* ==========================================
|
/* =========================================================================
|
||||||
Unity Project - A Test Framework for C
|
Unity Project - A Test Framework for C
|
||||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||||
[Released under MIT License. Please refer to license.txt for details]
|
[Released under MIT License. Please refer to license.txt for details]
|
||||||
========================================== */
|
============================================================================ */
|
||||||
|
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; longjmp(Unity.AbortFrame, 1); }
|
||||||
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); }
|
||||||
/// return prematurely if we are already in failure or ignore state
|
/// return prematurely if we are already in failure or ignore state
|
||||||
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
|
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
|
||||||
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
|
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
|
||||||
@ -276,7 +276,6 @@ void UnityConcludeTest(void)
|
|||||||
{
|
{
|
||||||
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
|
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
|
||||||
UnityPrint("PASS");
|
UnityPrint("PASS");
|
||||||
UNITY_PRINT_EOL;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1128,6 +1127,7 @@ void UnityBegin(void)
|
|||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
int UnityEnd(void)
|
int UnityEnd(void)
|
||||||
{
|
{
|
||||||
|
UNITY_PRINT_EOL;
|
||||||
UnityPrint("-----------------------");
|
UnityPrint("-----------------------");
|
||||||
UNITY_PRINT_EOL;
|
UNITY_PRINT_EOL;
|
||||||
UnityPrintNumber((_U_SINT)(Unity.NumberOfTests));
|
UnityPrintNumber((_U_SINT)(Unity.NumberOfTests));
|
||||||
@ -1148,3 +1148,7 @@ int UnityEnd(void)
|
|||||||
UNITY_PRINT_EOL;
|
UNITY_PRINT_EOL;
|
||||||
return (int)(Unity.TestFailures);
|
return (int)(Unity.TestFailures);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
30
src/unity.h
30
src/unity.h
@ -30,7 +30,7 @@
|
|||||||
// - define UNITY_INCLUDE_DOUBLE to allow double floating point comparisons
|
// - define UNITY_INCLUDE_DOUBLE to allow double floating point comparisons
|
||||||
// - define UNITY_EXCLUDE_DOUBLE to disallow double floating point comparisons (default)
|
// - define UNITY_EXCLUDE_DOUBLE to disallow double floating point comparisons (default)
|
||||||
// - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE
|
// - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE
|
||||||
// - define UNITY_DOUBLE_TYPE to specify something other than double
|
// - define UNITY_DOUBLE_TYPE to specify something other than double
|
||||||
// - define UNITY_DOUBLE_VERBOSE to print floating point values in errors (uses sprintf)
|
// - define UNITY_DOUBLE_VERBOSE to print floating point values in errors (uses sprintf)
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
@ -54,13 +54,39 @@
|
|||||||
|
|
||||||
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
|
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
|
||||||
|
|
||||||
|
//This tricky series of macros gives us an optional line argument to treat it as RUN_TEST(func, num=__LINE__)
|
||||||
#ifndef RUN_TEST
|
#ifndef RUN_TEST
|
||||||
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
|
#ifdef __STDC_VERSION__
|
||||||
|
#if __STDC_VERSION__ >= 199901L
|
||||||
|
#define RUN_TEST(...) UnityDefaultTestRun(RUN_TEST_FIRST(__VA_ARGS__), RUN_TEST_SECOND(__VA_ARGS__))
|
||||||
|
#define RUN_TEST_FIRST(...) RUN_TEST_FIRST_HELPER(__VA_ARGS__, throwaway)
|
||||||
|
#define RUN_TEST_FIRST_HELPER(first,...) first, #first
|
||||||
|
#define RUN_TEST_SECOND(...) RUN_TEST_SECOND_HELPER(__VA_ARGS__, __LINE__, throwaway)
|
||||||
|
#define RUN_TEST_SECOND_HELPER(first,second,...) second
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//If we can't do the tricky version, we'll just have to require them to always include the line number
|
||||||
|
#ifndef RUN_TEST
|
||||||
|
#ifdef CMOCK
|
||||||
|
#define RUN_TEST(func, num) UnityDefaultTestRun(func, #func, num)
|
||||||
|
#else
|
||||||
|
#define RUN_TEST(func) UnityDefaultTestRun(func, #func, __LINE__)
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
|
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
|
||||||
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
|
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
|
||||||
|
|
||||||
|
#ifndef UNITY_BEGIN
|
||||||
|
#define UNITY_BEGIN() {UnityBegin(); Unity.TestFile = __FILE__;}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef UNITY_END
|
||||||
|
#define UNITY_END() UnityEnd()
|
||||||
|
#endif
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
// Basic Fail and Ignore
|
// Basic Fail and Ignore
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user