Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
4d3d062b
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看板
提交
4d3d062b
编写于
6月 21, 2016
作者:
M
Mark VanderVoord
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding command line support. Started with -n (test name matching) -x (test name exclusion).
Script verification hasn't been added yet.
上级
b3bc196a
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
141 addition
and
5 deletion
+141
-5
auto/generate_test_runner.rb
auto/generate_test_runner.rb
+16
-5
src/unity.c
src/unity.c
+116
-0
src/unity_internals.h
src/unity_internals.h
+9
-0
未找到文件。
auto/generate_test_runner.rb
浏览文件 @
4d3d062b
...
...
@@ -28,7 +28,9 @@ class UnityTestRunnerGenerator
:test_prefix
=>
"test|spec|should"
,
:setup_name
=>
"setUp"
,
:teardown_name
=>
"tearDown"
,
:main_name
=>
"main"
,
:main_name
=>
"main"
,
#set to nil to automatically generate each time
:cmdline_args
=>
false
,
}
end
...
...
@@ -257,6 +259,7 @@ class UnityTestRunnerGenerator
output
.
puts
(
"{
\\
"
)
output
.
puts
(
" Unity.CurrentTestName = #TestFunc
#{
va_args2
.
empty?
?
''
:
"
\"
(
\"
#
#{
va_args2
}
\"
)
\"
"
}
;
\\
"
)
output
.
puts
(
" Unity.CurrentTestLineNumber = TestLineNum;
\\
"
)
output
.
puts
(
" if (UnityTestMatches()) {
\\
"
)
if
(
@options
[
:cmdline_args
])
output
.
puts
(
" Unity.NumberOfTests++;
\\
"
)
output
.
puts
(
" CMock_Init();
\\
"
)
unless
(
used_mocks
.
empty?
)
output
.
puts
(
" UNITY_CLR_DETAILS();
\\
"
)
unless
(
used_mocks
.
empty?
)
...
...
@@ -275,6 +278,7 @@ class UnityTestRunnerGenerator
output
.
puts
(
" }
\\
"
)
output
.
puts
(
" CMock_Destroy();
\\
"
)
unless
(
used_mocks
.
empty?
)
output
.
puts
(
" UnityConcludeTest();
\\
"
)
output
.
puts
(
" }
\\
"
)
if
(
@options
[
:cmdline_args
])
output
.
puts
(
"}
\n
"
)
end
...
...
@@ -293,11 +297,18 @@ class UnityTestRunnerGenerator
def
create_main
(
output
,
filename
,
tests
,
used_mocks
)
output
.
puts
(
"
\n\n
/*=======MAIN=====*/"
)
if
(
@options
[
:main_name
]
!=
"main"
)
output
.
puts
(
"int
#{
@options
[
:main_name
]
}
(void);"
)
main_name
=
@options
[
:main_name
].
nil?
?
"main_
#{
filename
.
gsub
(
'.c'
,
''
)
}
"
:
"
#{
@options
[
:main_name
]
}
"
if
(
main_name
!=
"main"
)
output
.
puts
(
"int
#{
main_name
}
(void);"
)
end
output
.
puts
(
"int
#{
@options
[
:main_name
]
}
(void)"
)
if
(
@options
[
:cmdline_args
])
output
.
puts
(
"int
#{
main_name
}
(int argc, char** argv)"
)
output
.
puts
(
"{"
)
output
.
puts
(
" UnityParseOptions(argc, argv);"
)
else
output
.
puts
(
"int
#{
main_name
}
(void)"
)
output
.
puts
(
"{"
)
end
output
.
puts
(
" suite_setup();"
)
unless
@options
[
:suite_setup
].
nil?
output
.
puts
(
" UnityBegin(
\"
#{
filename
.
gsub
(
/\\/
,
'\\\\'
)
}
\"
);"
)
if
(
@options
[
:use_param_tests
])
...
...
src/unity.c
浏览文件 @
4d3d062b
...
...
@@ -1300,4 +1300,120 @@ int UnityEnd(void)
return
(
int
)(
Unity
.
TestFailures
);
}
/*-----------------------------------------------
* Command Line Argument Support
*-----------------------------------------------*/
#ifdef UNITY_PARSE_COMMAND_LINE_ARGS
char
*
UnityOptionIncludeNamed
=
NULL
;
char
*
UnityOptionExcludeNamed
=
NULL
;
int
UnityVerbosity
=
1
;
int
UnityParseOptions
(
int
argc
,
char
**
argv
)
{
UnityOptionIncludeNamed
=
NULL
;
UnityOptionExcludeNamed
=
NULL
;
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
{
if
(
argv
[
i
][
0
]
==
'-'
)
{
switch
(
argv
[
i
][
1
])
{
case
'l'
:
/* list tests */
break
;
case
'n'
:
/* include tests with name including this string */
i
++
;
if
(
i
<
argc
)
UnityOptionIncludeNamed
=
argv
[
i
];
else
{
UnityPrint
(
"ERROR: No Test String to Include Matches For"
);
UNITY_PRINT_EOL
();
}
break
;
case
'q'
:
/* quiet */
UnityVerbosity
=
0
;
break
;
case
'v'
:
/* verbose */
UnityVerbosity
=
2
;
break
;
case
'x'
:
/* exclude tests with name including this string */
i
++
;
if
(
i
<
argc
)
UnityOptionExcludeNamed
=
argv
[
i
];
else
{
UnityPrint
(
"ERROR: No Test String to Exclude Matches For"
);
UNITY_PRINT_EOL
();
}
break
;
default:
UnityPrint
(
"ERROR: Unknown Option "
);
UNITY_PRINT_CHAR
(
argv
[
i
][
1
]);
UNITY_PRINT_EOL
();
return
1
;
}
}
}
return
0
;
}
int
UnityTestMatches
(
void
)
{
/* Check if this test name matches the included test pattern */
if
(
UnityOptionsIncludedNamed
)
retval
=
UnityStringArgumentMatches
(
UnityOptionIncludedNamed
);
else
retval
=
1
;
/* Check if this test name matches the excluded test pattern */
if
(
UnityOptionsExcludedNamed
)
if
(
UnityStringArgumentMatches
(
UnityOptionExcludedNamed
))
retval
=
0
;
return
retval
;
}
int
UnityStringArgumentMatches
(
const
char
*
str
)
{
char
*
ptr
=
(
char
*
)
str
;
while
(
*
ptr
)
{
char
*
begin
=
ptr
;
char
*
pattern
=
(
char
*
)
Unity
.
CurrentTestName
;
char
*
prefix
=
(
char
*
)
Unity
.
TestFile
;
/* First, find out if this is the right test case */
while
(
*
ptr
&&
*
prefix
&&
(
*
prefix
==
*
ptr
||
*
prefix
==
'.'
))
{
ptr
++
;
prefix
++
;
if
(
*
ptr
==
'*'
)
return
1
;
}
prefix
++
;
if
(
!*
prefix
)
{
while
(
*
ptr
&&
*
pattern
&&
*
pattern
==
*
ptr
)
{
ptr
++
;
pattern
++
;
if
(
*
ptr
==
'*'
)
return
1
;
}
/* If complete test name match, return true */
if
(
!*
pattern
)
return
1
;
}
ptr
=
begin
+
1
;
}
}
#endif
/* UNITY_PARSE_COMMAND_LINE_ARGS */
/*-----------------------------------------------*/
src/unity_internals.h
浏览文件 @
4d3d062b
...
...
@@ -640,6 +640,15 @@ extern const char UnityStrErr64[];
#define UNITY_UNUSED(x) (void)(sizeof(x))
/*-----------------------------------------------
* Command Line Argument Support
*-----------------------------------------------*/
#ifdef UNITY_PARSE_COMMAND_LINE_ARGS
int
UnityParseOptions
(
int
argc
,
char
**
argv
);
int
UnityTestMatches
(
void
);
#endif
/*-------------------------------------------------------
* Basic Fail and Ignore
*-------------------------------------------------------*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录