mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-18 03:51:35 +08:00
放弃新增的代码,直接采用现有结构。在头文件宏定义中添加__FILE__结果符合预期。不能在unity.c文件中这样做。否则所有的测试汇总信息都定位到了unity。
This commit is contained in:
parent
f87dc997eb
commit
18a14d6d03
16
3rdparty/unicstl-unity/README.md
vendored
16
3rdparty/unicstl-unity/README.md
vendored
@ -1,16 +1,12 @@
|
||||
|
||||
# 问题和解决方案
|
||||
|
||||
## 1. 多文件打印测试文件路径不合理的问题
|
||||
新增宏定义,可放于unity_config.h中,用来让测试文件路径显示为当前测试文件,而不是主test.c文件。
|
||||
方便针对多文件测试,快速定位错误。
|
||||
## 1. 添加配置文件
|
||||
在unity_internals.h文件中添加了宏定义,方便使用unity_config.h文件。
|
||||
```c
|
||||
#define RUN_TEST_WITH_CURRENT_FILE 1
|
||||
#define UNITY_INCLUDE_CONFIG_H
|
||||
```
|
||||
|
||||
另外,修改了两个函数,新增文件路径参数。
|
||||
```c
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum, const char* FileName);
|
||||
|
||||
void UnityConcludeTest(const char *FileName);
|
||||
```
|
||||
## 2. 多文件打印测试文件路径不合理的问题
|
||||
修改`RUN_TEST`宏,在测试文件路径前添加`__FILE__`。
|
||||
借助`UnitySetTestFile`函数,打印的路径信息对多文件测试也有效。
|
||||
|
48
3rdparty/unicstl-unity/src/unity.c
vendored
48
3rdparty/unicstl-unity/src/unity.c
vendored
@ -543,7 +543,6 @@ static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
#ifndef RUN_TEST_WITH_CURRENT_FILE
|
||||
void UnityConcludeTest(void)
|
||||
{
|
||||
if (Unity.CurrentTestIgnored)
|
||||
@ -566,31 +565,6 @@ void UnityConcludeTest(void)
|
||||
UNITY_PRINT_EOL();
|
||||
UNITY_FLUSH_CALL();
|
||||
}
|
||||
#else
|
||||
void UnityConcludeTest(const char *FileName)
|
||||
{
|
||||
if (Unity.CurrentTestIgnored)
|
||||
{
|
||||
Unity.TestIgnores++;
|
||||
}
|
||||
else if (!Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsBegin(FileName, Unity.CurrentTestLineNumber);
|
||||
UnityPrint(UnityStrPass);
|
||||
}
|
||||
else
|
||||
{
|
||||
Unity.TestFailures++;
|
||||
}
|
||||
|
||||
Unity.CurrentTestFailed = 0;
|
||||
Unity.CurrentTestIgnored = 0;
|
||||
UNITY_PRINT_EXEC_TIME();
|
||||
UNITY_PRINT_EOL();
|
||||
UNITY_FLUSH_CALL();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
static void UnityAddMsgIfSpecified(const char* msg)
|
||||
@ -2216,7 +2190,6 @@ void UnityMessage(const char* msg, const UNITY_LINE_TYPE line)
|
||||
/*-----------------------------------------------*/
|
||||
/* If we have not defined our own test runner, then include our default test runner to make life easier */
|
||||
#ifndef UNITY_SKIP_DEFAULT_RUNNER
|
||||
#ifndef RUN_TEST_WITH_CURRENT_FILE
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
|
||||
{
|
||||
Unity.CurrentTestName = FuncName;
|
||||
@ -2236,27 +2209,6 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int
|
||||
UNITY_EXEC_TIME_STOP();
|
||||
UnityConcludeTest();
|
||||
}
|
||||
#else
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum, const char* FileName)
|
||||
{
|
||||
Unity.CurrentTestName = FuncName;
|
||||
Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
|
||||
Unity.NumberOfTests++;
|
||||
UNITY_CLR_DETAILS();
|
||||
UNITY_EXEC_TIME_START();
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
setUp();
|
||||
Func();
|
||||
}
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
tearDown();
|
||||
}
|
||||
UNITY_EXEC_TIME_STOP();
|
||||
UnityConcludeTest(FileName);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
|
2
3rdparty/unicstl-unity/src/unity_config.h
vendored
2
3rdparty/unicstl-unity/src/unity_config.h
vendored
@ -5,6 +5,4 @@
|
||||
#define UNITY_OUTPUT_COLOR 1
|
||||
#define UNITY_USE_FLUSH_STDOUT 1
|
||||
|
||||
#define RUN_TEST_WITH_CURRENT_FILE 1
|
||||
|
||||
#endif
|
||||
|
20
3rdparty/unicstl-unity/src/unity_internals.h
vendored
20
3rdparty/unicstl-unity/src/unity_internals.h
vendored
@ -8,7 +8,7 @@
|
||||
#ifndef UNITY_INTERNALS_H
|
||||
#define UNITY_INTERNALS_H
|
||||
|
||||
#define UNITY_INCLUDE_CONFIG_H 1
|
||||
#define UNITY_INCLUDE_CONFIG_H
|
||||
|
||||
#ifdef UNITY_INCLUDE_CONFIG_H
|
||||
#include "unity_config.h"
|
||||
@ -546,19 +546,11 @@ extern struct UNITY_STORAGE_T Unity;
|
||||
void UnityBegin(const char* filename);
|
||||
int UnityEnd(void);
|
||||
void UnitySetTestFile(const char* filename);
|
||||
#ifndef RUN_TEST_WITH_CURRENT_FILE
|
||||
void UnityConcludeTest(void);
|
||||
#else
|
||||
void UnityConcludeTest(const char *FileName);
|
||||
#endif
|
||||
|
||||
#ifndef RUN_TEST
|
||||
#ifndef RUN_TEST_WITH_CURRENT_FILE
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
|
||||
#else
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum, const char* FileName);
|
||||
#endif
|
||||
#else
|
||||
#define UNITY_SKIP_DEFAULT_RUNNER
|
||||
#endif
|
||||
|
||||
@ -825,13 +817,9 @@ extern const char UnityStrErrShorthand[];
|
||||
#ifndef RUN_TEST
|
||||
#ifdef UNITY_SUPPORT_VARIADIC_MACROS
|
||||
#define RUN_TEST(...) RUN_TEST_AT_LINE(__VA_ARGS__, __LINE__, throwaway)
|
||||
#ifndef RUN_TEST_WITH_CURRENT_FILE
|
||||
#define RUN_TEST_AT_LINE(func, line, ...) UnityDefaultTestRun(func, #func, line)
|
||||
#else
|
||||
#define RUN_TEST_AT_LINE(func, line, ...) UnityDefaultTestRun(func, #func, line, __FILE__)
|
||||
#endif // RUN_TEST_WITH_CURRENT_FILE
|
||||
#endif // UNITY_SUPPORT_VARIADIC_MACROS
|
||||
#endif // RUN_TEST
|
||||
#define RUN_TEST_AT_LINE(func, line, ...) UnitySetTestFile(__FILE__);UnityDefaultTestRun(func, #func, line)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Enable default macros for masking param tests test cases */
|
||||
#ifdef UNITY_SUPPORT_TEST_CASES
|
||||
|
@ -14,9 +14,11 @@ static void test_queue_destory(void)
|
||||
{
|
||||
queue_t queue = NULL;
|
||||
queue = queue_new();
|
||||
TEST_ASSERT_TRUE(queue_init(queue, sizeof(int)));
|
||||
TEST_ASSERT_NOT_NULL(queue);
|
||||
|
||||
TEST_ASSERT_TRUE(queue_init(queue, sizeof(int)));
|
||||
TEST_ASSERT_NULL(queue);
|
||||
|
||||
queue_free(&queue);
|
||||
TEST_ASSERT_NULL(queue);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user