Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
d9b0edf2
T
Third Party Unity
项目概览
OpenHarmony
/
Third Party Unity
1 年多 前同步成功
通知
36
Star
144
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Unity
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
d9b0edf2
编写于
10月 21, 2019
作者:
M
Mark VanderVoord
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Switch from the inconsistent use of weak symbols to handling setup, etc in script generators
上级
0793de9e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
76 deletion
+48
-76
auto/generate_test_runner.rb
auto/generate_test_runner.rb
+40
-35
src/unity.h
src/unity.h
+8
-25
src/unity_internals.h
src/unity_internals.h
+0
-16
未找到文件。
auto/generate_test_runner.rb
浏览文件 @
d9b0edf2
...
...
@@ -58,6 +58,7 @@ class UnityTestRunnerGenerator
used_mocks
=
find_mocks
(
testfile_includes
)
testfile_includes
=
(
testfile_includes
-
used_mocks
)
testfile_includes
.
delete_if
{
|
inc
|
inc
=~
/(unity|cmock)/
}
find_setup_and_teardown
()
# build runner file
generate
(
input_file
,
output_file
,
tests
,
used_mocks
,
testfile_includes
)
...
...
@@ -165,11 +166,17 @@ class UnityTestRunnerGenerator
mock_headers
end
def
find_setup_and_teardown
(
source
)
@has_setup
=
source
=~
/void\s+
#{
@options
[
setup_name
]
}
\s*\(/
@has_teardown
=
source
=~
/void\s+
#{
@options
[
teardown_name
]
}
\s*\(/
@has_suite_setup
=
(
!
@options
[
:suite_setup
].
nil?
)
||
(
source
=~
/void\s+suiteSetUp\s*\(/
)
@has_suite_teardown
=
(
!
@options
[
:suite_teardown
].
nil?
)
||
(
source
=~
/void\s+suiteTearDown\s*\(/
)
end
def
create_header
(
output
,
mocks
,
testfile_includes
=
[])
output
.
puts
(
'/* AUTOGENERATED FILE. DO NOT EDIT. */'
)
create_runtest
(
output
,
mocks
)
output
.
puts
(
"
\n
/*=======Automagically Detected Files To Include=====*/"
)
output
.
puts
(
'#define UNITY_INCLUDE_SETUP_STUBS'
)
if
@options
[
:suite_setup
].
nil?
output
.
puts
(
"#include
\"
#{
@options
[
:framework
]
}
.h
\"
"
)
output
.
puts
(
'#include "cmock.h"'
)
unless
mocks
.
empty?
output
.
puts
(
'#ifndef UNITY_EXCLUDE_SETJMP_H'
)
...
...
@@ -204,8 +211,8 @@ class UnityTestRunnerGenerator
def
create_externs
(
output
,
tests
,
_mocks
)
output
.
puts
(
"
\n
/*=======External Functions This Runner Calls=====*/"
)
output
.
puts
(
"extern void
#{
@options
[
:setup_name
]
}
(void);"
)
output
.
puts
(
"extern void
#{
@options
[
:teardown_name
]
}
(void);"
)
output
.
puts
(
"extern void
#{
@options
[
:setup_name
]
}
(void);"
)
if
@has_setup
output
.
puts
(
"extern void
#{
@options
[
:teardown_name
]
}
(void);"
)
if
@has_teardown
output
.
puts
(
"
\n
#ifdef __cplusplus
\n
extern
\"
C
\"\n
{
\n
#endif"
)
if
@options
[
:externc
]
tests
.
each
do
|
test
|
output
.
puts
(
"extern void
#{
test
[
:test
]
}
(
#{
test
[
:call
]
||
'void'
}
);"
)
...
...
@@ -252,37 +259,31 @@ class UnityTestRunnerGenerator
end
def
create_suite_setup
(
output
)
output
.
puts
(
"
\n
/*=======Suite Setup=====*/"
)
output
.
puts
(
'static void suite_setup(void)'
)
output
.
puts
(
'{'
)
if
@options
[
:suite_setup
].
nil?
# New style, call suiteSetUp() if we can use weak symbols
output
.
puts
(
'#if defined(UNITY_WEAK_ATTRIBUTE) || defined(UNITY_WEAK_PRAGMA)'
)
output
.
puts
(
' suiteSetUp();'
)
output
.
puts
(
'#endif'
)
else
# Old style, C code embedded in the :suite_setup option
output
.
puts
(
@options
[
:suite_setup
])
if
@has_suite_setup
if
@options
[
:suite_setup
].
nil?
output
.
puts
(
"
\n
/*=======Suite Setup=====*/"
)
output
.
puts
(
'static void suiteSetUp(void)'
)
output
.
puts
(
'{'
)
output
.
puts
(
@options
[
:suite_setup
])
output
.
puts
(
'}'
)
else
output
.
puts
(
'extern void suiteSetUp(void);'
)
end
end
output
.
puts
(
'}'
)
end
def
create_suite_teardown
(
output
)
output
.
puts
(
"
\n
/*=======Suite Teardown=====*/"
)
output
.
puts
(
'static int suite_teardown(int num_failures)'
)
output
.
puts
(
'{'
)
if
@options
[
:suite_teardown
].
nil?
# New style, call suiteTearDown() if we can use weak symbols
output
.
puts
(
'#if defined(UNITY_WEAK_ATTRIBUTE) || defined(UNITY_WEAK_PRAGMA)'
)
output
.
puts
(
' return suiteTearDown(num_failures);'
)
output
.
puts
(
'#else'
)
output
.
puts
(
' return num_failures;'
)
output
.
puts
(
'#endif'
)
else
# Old style, C code embedded in the :suite_teardown option
output
.
puts
(
@options
[
:suite_teardown
])
if
(
@has_suite_teardown
)
if
@options
[
:suite_teardown
].
nil?
output
.
puts
(
"
\n
/*=======Suite Teardown=====*/"
)
output
.
puts
(
'static int suite_teardown(int num_failures)'
)
output
.
puts
(
'{'
)
output
.
puts
(
@options
[
:suite_teardown
])
output
.
puts
(
'}'
)
else
output
.
puts
(
'extern int suite_teardown(int num_failures);'
)
end
end
output
.
puts
(
'}'
)
end
def
create_runtest
(
output
,
used_mocks
)
...
...
@@ -304,13 +305,13 @@ class UnityTestRunnerGenerator
output
.
puts
(
' { \\'
)
output
.
puts
(
' CEXCEPTION_T e; \\'
)
if
cexception
output
.
puts
(
' Try { \\'
)
if
cexception
output
.
puts
(
"
#{
@options
[
:setup_name
]
}
();
\\
"
)
output
.
puts
(
"
#{
@options
[
:setup_name
]
}
();
\\
"
)
if
@has_setup
output
.
puts
(
" TestFunc(
#{
va_args2
}
);
\\
"
)
output
.
puts
(
' } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \\'
)
if
cexception
output
.
puts
(
' } \\'
)
output
.
puts
(
' if (TEST_PROTECT()) \\'
)
output
.
puts
(
' { \\'
)
output
.
puts
(
"
#{
@options
[
:teardown_name
]
}
();
\\
"
)
output
.
puts
(
"
#{
@options
[
:teardown_name
]
}
();
\\
"
)
if
@has_teardown
output
.
puts
(
' CMock_Verify(); \\'
)
unless
used_mocks
.
empty?
output
.
puts
(
' } \\'
)
output
.
puts
(
' CMock_Destroy(); \\'
)
unless
used_mocks
.
empty?
...
...
@@ -327,9 +328,9 @@ class UnityTestRunnerGenerator
output
.
puts
(
'{'
)
output
.
puts
(
' CMock_Verify();'
)
unless
used_mocks
.
empty?
output
.
puts
(
' CMock_Destroy();'
)
unless
used_mocks
.
empty?
output
.
puts
(
"
#{
@options
[
:teardown_name
]
}
();"
)
output
.
puts
(
"
#{
@options
[
:teardown_name
]
}
();"
)
if
@has_teardown
output
.
puts
(
' CMock_Init();'
)
unless
used_mocks
.
empty?
output
.
puts
(
"
#{
@options
[
:setup_name
]
}
();"
)
output
.
puts
(
"
#{
@options
[
:setup_name
]
}
();"
)
if
@has_setup
output
.
puts
(
'}'
)
end
...
...
@@ -375,7 +376,7 @@ class UnityTestRunnerGenerator
output
.
puts
(
"int
#{
main_name
}
(void)"
)
output
.
puts
(
'{'
)
end
output
.
puts
(
' suite
_setup();'
)
output
.
puts
(
' suite
SetUp();'
)
if
@has_suite_setup
output
.
puts
(
" UnityBegin(
\"
#{
filename
.
gsub
(
/\\/
,
'\\\\\\'
)
}
\"
);"
)
if
@options
[
:use_param_tests
]
tests
.
each
do
|
test
|
...
...
@@ -390,7 +391,11 @@ class UnityTestRunnerGenerator
end
output
.
puts
output
.
puts
(
' CMock_Guts_MemFreeFinal();'
)
unless
used_mocks
.
empty?
output
.
puts
(
' return suite_teardown(UnityEnd());'
)
if
(
@has_suite_teardown
)
output
.
puts
(
' return suiteTearDown(UnityEnd());'
)
else
output
.
puts
(
' return UnityEnd();'
)
end
output
.
puts
(
'}'
)
end
...
...
src/unity.h
浏览文件 @
d9b0edf2
...
...
@@ -24,39 +24,22 @@ extern "C"
* Test Setup / Teardown
*-------------------------------------------------------*/
/* These functions are intended to be called before and after each test. */
/* These functions are intended to be called before and after each test.
* If using unity directly, these will need to be provided for each test
* executable built. If you are using the test runner generator and/or
* Ceedling, these are optional. */
void
setUp
(
void
);
void
tearDown
(
void
);
/* These functions are intended to be called at the beginning and end of an
* entire test suite. suiteTearDown() is passed the number of tests that
* failed, and its return value becomes the exit code of main(). */
* failed, and its return value becomes the exit code of main(). If using
* Unity directly, you're in charge of calling these if they are desired.
* If using Ceedling or the test runner generator, these will be called
* automatically if they exist. */
void
suiteSetUp
(
void
);
int
suiteTearDown
(
int
num_failures
);
/* If the compiler supports it, the following block provides stub
* implementations of the above functions as weak symbols. Note that on
* some platforms (MinGW for example), weak function implementations need
* to be in the same translation unit they are called from. This can be
* achieved by defining UNITY_INCLUDE_SETUP_STUBS before including unity.h. */
#ifdef UNITY_INCLUDE_SETUP_STUBS
#ifdef UNITY_WEAK_ATTRIBUTE
UNITY_WEAK_ATTRIBUTE
void
setUp
(
void
)
{
}
UNITY_WEAK_ATTRIBUTE
void
tearDown
(
void
)
{
}
UNITY_WEAK_ATTRIBUTE
void
suiteSetUp
(
void
)
{
}
UNITY_WEAK_ATTRIBUTE
int
suiteTearDown
(
int
num_failures
)
{
return
num_failures
;
}
#elif defined(UNITY_WEAK_PRAGMA)
#pragma weak setUp
void
setUp
(
void
)
{
}
#pragma weak tearDown
void
tearDown
(
void
)
{
}
#pragma weak suiteSetUp
void
suiteSetUp
(
void
)
{
}
#pragma weak suiteTearDown
int
suiteTearDown
(
int
num_failures
)
{
return
num_failures
;
}
#endif
#endif
/*-------------------------------------------------------
* Configuration Options
*-------------------------------------------------------
...
...
src/unity_internals.h
浏览文件 @
d9b0edf2
...
...
@@ -372,22 +372,6 @@ typedef UNITY_FLOAT_TYPE UNITY_FLOAT;
#define UNITY_COUNTER_TYPE UNITY_UINT
#endif
/*-------------------------------------------------------
* Language Features Available
*-------------------------------------------------------*/
#if !defined(UNITY_WEAK_ATTRIBUTE) && !defined(UNITY_WEAK_PRAGMA)
# if defined(__GNUC__) || defined(__ghs__)
/* __GNUC__ includes clang */
# if !(defined(__WIN32__) && defined(__clang__)) && !defined(__TMS470__)
# define UNITY_WEAK_ATTRIBUTE __attribute__((weak))
# endif
# endif
#endif
#ifdef UNITY_NO_WEAK
# undef UNITY_WEAK_ATTRIBUTE
# undef UNITY_WEAK_PRAGMA
#endif
/*-------------------------------------------------------
* Internal Structs Needed
*-------------------------------------------------------*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录