mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-05-17 19:41:36 +08:00
针对多文件测试路径显示问题,做了修改
This commit is contained in:
parent
383f9ffe4b
commit
0319209b21
16
3rdparty/unicstl-unity/README.md
vendored
Normal file
16
3rdparty/unicstl-unity/README.md
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
# 问题和解决方案
|
||||
|
||||
## 1. 多文件打印测试文件路径不合理的问题
|
||||
新增宏定义,可放于unity_config.h中,用来让测试文件路径显示为当前测试文件,而不是主test.c文件。
|
||||
方便针对多文件测试,快速定位错误。
|
||||
```c
|
||||
#define RUN_TEST_WITH_CURRENT_FILE 1
|
||||
```
|
||||
|
||||
另外,修改了两个函数,新增文件路径参数。
|
||||
```c
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum, const char* FileName);
|
||||
|
||||
void UnityConcludeTest(const char *FileName);
|
||||
```
|
48
3rdparty/unicstl-unity/src/unity.c
vendored
48
3rdparty/unicstl-unity/src/unity.c
vendored
@ -543,6 +543,7 @@ static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
|
||||
}
|
||||
|
||||
/*-----------------------------------------------*/
|
||||
#ifndef RUN_TEST_WITH_CURRENT_FILE
|
||||
void UnityConcludeTest(void)
|
||||
{
|
||||
if (Unity.CurrentTestIgnored)
|
||||
@ -565,6 +566,31 @@ 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)
|
||||
@ -2190,6 +2216,7 @@ 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;
|
||||
@ -2209,6 +2236,27 @@ 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,4 +5,6 @@
|
||||
#define UNITY_OUTPUT_COLOR 1
|
||||
#define UNITY_USE_FLUSH_STDOUT 1
|
||||
|
||||
#define RUN_TEST_WITH_CURRENT_FILE 1
|
||||
|
||||
#endif
|
||||
|
16
3rdparty/unicstl-unity/src/unity_internals.h
vendored
16
3rdparty/unicstl-unity/src/unity_internals.h
vendored
@ -546,11 +546,19 @@ 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
|
||||
|
||||
@ -817,9 +825,13 @@ 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)
|
||||
#endif
|
||||
#endif
|
||||
#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
|
||||
|
||||
/* Enable default macros for masking param tests test cases */
|
||||
#ifdef UNITY_SUPPORT_TEST_CASES
|
||||
|
@ -48,9 +48,5 @@ static void test_stack_num(void)
|
||||
|
||||
void test_stack(void)
|
||||
{
|
||||
// UNITY_BEGIN();
|
||||
|
||||
RUN_TEST(test_stack_num);
|
||||
|
||||
// UNITY_END();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user