Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
2a5b24f7
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看板
提交
2a5b24f7
编写于
3月 28, 2017
作者:
M
Mark VanderVoord
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finished updating all Ruby scripts to match our coding standard. Woo!
上级
3e0a7121
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
547 addition
and
790 deletion
+547
-790
auto/colour_prompt.rb
auto/colour_prompt.rb
+6
-7
auto/colour_reporter.rb
auto/colour_reporter.rb
+2
-2
auto/generate_test_runner.rb
auto/generate_test_runner.rb
+76
-71
auto/parse_output.rb
auto/parse_output.rb
+220
-0
auto/stylize_as_junit.rb
auto/stylize_as_junit.rb
+34
-50
auto/test_file_filter.rb
auto/test_file_filter.rb
+9
-8
auto/unity_test_summary.rb
auto/unity_test_summary.rb
+18
-29
examples/example_3/rakefile.rb
examples/example_3/rakefile.rb
+1
-1
examples/example_3/rakefile_helper.rb
examples/example_3/rakefile_helper.rb
+29
-27
extras/fixture/rakefile_helper.rb
extras/fixture/rakefile_helper.rb
+31
-29
test/.rubocop.yml
test/.rubocop.yml
+9
-5
test/.rubocop_todo.yml
test/.rubocop_todo.yml
+0
-443
test/rakefile
test/rakefile
+14
-11
test/rakefile_helper.rb
test/rakefile_helper.rb
+98
-107
未找到文件。
auto/colour_prompt.rb
浏览文件 @
2a5b24f7
...
...
@@ -21,12 +21,11 @@ end
class
ColourCommandLine
def
initialize
if
RUBY_PLATFORM
=~
/(win|w)32$/
get_std_handle
=
Win32API
.
new
(
'kernel32'
,
'GetStdHandle'
,
[
'L'
],
'L'
)
@set_console_txt_attrb
=
Win32API
.
new
(
'kernel32'
,
'SetConsoleTextAttribute'
,
%w(L N)
,
'I'
)
@hout
=
get_std_handle
.
call
(
-
11
)
end
return
unless
RUBY_PLATFORM
=~
/(win|w)32$/
get_std_handle
=
Win32API
.
new
(
'kernel32'
,
'GetStdHandle'
,
[
'L'
],
'L'
)
@set_console_txt_attrb
=
Win32API
.
new
(
'kernel32'
,
'SetConsoleTextAttribute'
,
%w(L N)
,
'I'
)
@hout
=
get_std_handle
.
call
(
-
11
)
end
def
change_to
(
new_colour
)
...
...
@@ -34,7 +33,7 @@ class ColourCommandLine
@set_console_txt_attrb
.
call
(
@hout
,
win32_colour
(
new_colour
))
else
"
\033
[30;
#{
posix_colour
(
new_colour
)
}
;22m"
end
end
end
def
win32_colour
(
colour
)
...
...
auto/colour_reporter.rb
浏览文件 @
2a5b24f7
...
...
@@ -17,7 +17,7 @@ def report(message)
line
.
chomp!
colour
=
case
line
when
/(?:total\s+)?tests:?\s+(\d+)\s+(?:total\s+)?failures:?\s+\d+\s+Ignored:?/i
Regexp
.
last_match
(
1
).
to_i
==
0
?
:green
:
:red
Regexp
.
last_match
(
1
).
to_i
.
zero?
?
:green
:
:red
when
/PASS/
:green
when
/^OK$/
...
...
@@ -30,7 +30,7 @@ def report(message)
:white
else
:silver
end
end
colour_puts
(
colour
,
line
)
end
end
...
...
auto/generate_test_runner.rb
浏览文件 @
2a5b24f7
...
...
@@ -9,11 +9,11 @@ File.expand_path(File.join(File.dirname(__FILE__), 'colour_prompt'))
class
UnityTestRunnerGenerator
def
initialize
(
options
=
nil
)
@options
=
UnityTestRunnerGenerator
.
default_options
case
(
options
)
case
options
when
NilClass
then
@options
when
String
then
@options
.
merge!
(
UnityTestRunnerGenerator
.
grab_config
(
options
))
when
Hash
then
@options
.
merge!
(
options
)
else
raise
'If you specify arguments, it should be a filename or a hash of options'
else
raise
'If you specify arguments, it should be a filename or a hash of options'
end
require
"
#{
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
}
/type_sanitizer"
end
...
...
@@ -43,16 +43,11 @@ class UnityTestRunnerGenerator
options
.
merge!
(
yaml_guts
[
:unity
]
||
yaml_guts
[
:cmock
])
raise
"No :unity or :cmock section found in
#{
config_file
}
"
unless
options
end
(
options
)
options
end
def
run
(
input_file
,
output_file
,
options
=
nil
)
tests
=
[]
testfile_includes
=
[]
used_mocks
=
[]
@options
.
merge!
(
options
)
unless
options
.
nil?
module_name
=
File
.
basename
(
input_file
)
# pull required data from source file
source
=
File
.
read
(
input_file
)
...
...
@@ -80,15 +75,16 @@ class UnityTestRunnerGenerator
create_header
(
output
,
used_mocks
,
testfile_includes
)
create_externs
(
output
,
tests
,
used_mocks
)
create_mock_management
(
output
,
used_mocks
)
create_suite_setup_and_teardown
(
output
)
create_suite_setup
(
output
)
create_suite_teardown
(
output
)
create_reset
(
output
,
used_mocks
)
create_main
(
output
,
input_file
,
tests
,
used_mocks
)
end
if
@options
[
:header_file
]
&&
!
@options
[
:header_file
].
empty?
File
.
open
(
@options
[
:header_file
],
'w'
)
do
|
output
|
create_h_file
(
output
,
@options
[
:header_file
],
tests
,
testfile_includes
,
used_mocks
)
end
return
unless
@options
[
:header_file
]
&&
!
@options
[
:header_file
].
empty?
File
.
open
(
@options
[
:header_file
],
'w'
)
do
|
output
|
create_h_file
(
output
,
@options
[
:header_file
],
tests
,
testfile_includes
,
used_mocks
)
end
end
...
...
@@ -123,7 +119,7 @@ class UnityTestRunnerGenerator
source_index
=
0
tests_and_line_numbers
.
size
.
times
do
|
i
|
source_lines
[
source_index
..-
1
].
each_with_index
do
|
line
,
index
|
next
unless
(
line
=~
/
#{
tests_and_line_numbers
[
i
][
:test
]
}
/
)
next
unless
line
=~
/
#{
tests_and_line_numbers
[
i
][
:test
]
}
/
source_index
+=
index
tests_and_line_numbers
[
i
][
:line_number
]
=
source_index
+
1
break
...
...
@@ -182,12 +178,13 @@ class UnityTestRunnerGenerator
output
.
puts
(
"#include
\"
#{
mock
.
gsub
(
'.h'
,
''
)
}
.h
\"
"
)
end
output
.
puts
(
'#include "CException.h"'
)
if
@options
[
:plugins
].
include?
(
:cexception
)
if
@options
[
:enforce_strict_ordering
]
output
.
puts
(
''
)
output
.
puts
(
'int GlobalExpectCount;'
)
output
.
puts
(
'int GlobalVerifyOrder;'
)
output
.
puts
(
'char* GlobalOrderError;'
)
end
return
unless
@options
[
:enforce_strict_ordering
]
output
.
puts
(
''
)
output
.
puts
(
'int GlobalExpectCount;'
)
output
.
puts
(
'int GlobalVerifyOrder;'
)
output
.
puts
(
'char* GlobalOrderError;'
)
end
def
create_externs
(
output
,
tests
,
_mocks
)
...
...
@@ -201,55 +198,60 @@ class UnityTestRunnerGenerator
end
def
create_mock_management
(
output
,
mock_headers
)
unless
mock_headers
.
empty?
output
.
puts
(
"
\n
/*=======Mock Management=====*/"
)
output
.
puts
(
'static void CMock_Init(void)'
)
output
.
puts
(
'{'
)
if
@options
[
:enforce_strict_ordering
]
output
.
puts
(
' GlobalExpectCount = 0;'
)
output
.
puts
(
' GlobalVerifyOrder = 0;'
)
output
.
puts
(
' GlobalOrderError = NULL;'
)
end
mocks
=
mock_headers
.
map
{
|
mock
|
File
.
basename
(
mock
)
}
mocks
.
each
do
|
mock
|
mock_clean
=
TypeSanitizer
.
sanitize_c_identifier
(
mock
)
output
.
puts
(
"
#{
mock_clean
}
_Init();"
)
end
output
.
puts
(
"}
\n
"
)
return
if
mock_headers
.
empty?
output
.
puts
(
'static void CMock_Verify(void)'
)
output
.
puts
(
'{'
)
mocks
.
each
do
|
mock
|
mock_clean
=
TypeSanitizer
.
sanitize_c_identifier
(
mock
)
output
.
puts
(
"
#{
mock_clean
}
_Verify();"
)
end
output
.
puts
(
"}
\n
"
)
output
.
puts
(
"
\n
/*=======Mock Management=====*/"
)
output
.
puts
(
'static void CMock_Init(void)'
)
output
.
puts
(
'{'
)
output
.
puts
(
'static void CMock_Destroy(void)'
)
output
.
puts
(
'{'
)
mocks
.
each
do
|
mock
|
mock_clean
=
TypeSanitizer
.
sanitize_c_identifier
(
mock
)
output
.
puts
(
"
#{
mock_clean
}
_Destroy();"
)
end
output
.
puts
(
"}
\n
"
)
if
@options
[
:enforce_strict_ordering
]
output
.
puts
(
' GlobalExpectCount = 0;'
)
output
.
puts
(
' GlobalVerifyOrder = 0;'
)
output
.
puts
(
' GlobalOrderError = NULL;'
)
end
end
def
create_suite_setup_and_teardown
(
output
)
unless
@options
[
:suite_setup
].
nil?
output
.
puts
(
"
\n
/*=======Suite Setup=====*/"
)
output
.
puts
(
'static void suite_setup(void)'
)
output
.
puts
(
'{'
)
output
.
puts
(
@options
[
:suite_setup
])
output
.
puts
(
'}'
)
mocks
=
mock_headers
.
map
{
|
mock
|
File
.
basename
(
mock
)
}
mocks
.
each
do
|
mock
|
mock_clean
=
TypeSanitizer
.
sanitize_c_identifier
(
mock
)
output
.
puts
(
"
#{
mock_clean
}
_Init();"
)
end
unless
@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
(
'}'
)
output
.
puts
(
"}
\n
"
)
output
.
puts
(
'static void CMock_Verify(void)'
)
output
.
puts
(
'{'
)
mocks
.
each
do
|
mock
|
mock_clean
=
TypeSanitizer
.
sanitize_c_identifier
(
mock
)
output
.
puts
(
"
#{
mock_clean
}
_Verify();"
)
end
output
.
puts
(
"}
\n
"
)
output
.
puts
(
'static void CMock_Destroy(void)'
)
output
.
puts
(
'{'
)
mocks
.
each
do
|
mock
|
mock_clean
=
TypeSanitizer
.
sanitize_c_identifier
(
mock
)
output
.
puts
(
"
#{
mock_clean
}
_Destroy();"
)
end
output
.
puts
(
"}
\n
"
)
end
def
create_suite_setup
(
output
)
return
if
@options
[
:suite_setup
].
nil?
output
.
puts
(
"
\n
/*=======Suite Setup=====*/"
)
output
.
puts
(
'static void suite_setup(void)'
)
output
.
puts
(
'{'
)
output
.
puts
(
@options
[
:suite_setup
])
output
.
puts
(
'}'
)
end
def
create_suite_teardown
(
output
)
return
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
(
'}'
)
end
def
create_runtest
(
output
,
used_mocks
)
...
...
@@ -384,22 +386,25 @@ class UnityTestRunnerGenerator
end
end
if
$
PROGRAM_NAME
==
__FILE__
if
$
0
==
__FILE__
options
=
{
includes:
[]
}
yaml_file
=
nil
# parse out all the options first (these will all be removed as we go)
ARGV
.
reject!
do
|
arg
|
case
(
arg
)
case
arg
when
'-cexception'
options
[
:plugins
]
=
[
:cexception
];
true
options
[
:plugins
]
=
[
:cexception
]
true
when
/\.*\.ya?ml/
options
=
UnityTestRunnerGenerator
.
grab_config
(
arg
);
true
options
=
UnityTestRunnerGenerator
.
grab_config
(
arg
)
true
when
/--(\w+)=\"?(.*)\"?/
options
[
Regexp
.
last_match
(
1
).
to_sym
]
=
Regexp
.
last_match
(
2
);
true
options
[
Regexp
.
last_match
(
1
).
to_sym
]
=
Regexp
.
last_match
(
2
)
true
when
/\.*\.h/
options
[
:includes
]
<<
arg
;
true
else
false
options
[
:includes
]
<<
arg
true
else
false
end
end
...
...
auto/parse
O
utput.rb
→
auto/parse
_o
utput.rb
浏览文件 @
2a5b24f7
...
...
@@ -17,23 +17,24 @@
#============================================================
class
ParseOutput
# The following flag is set to true when a test is found or false otherwise.
@testFlag
@xmlOut
@arrayList
@totalTests
@classIndex
def
initialize
@test_flag
=
false
@xml_out
=
false
@array_list
=
false
@total_tests
=
false
@class_index
=
false
end
# Set the flag to indicate if there will be an XML output file or not
def
set
XmlO
utput
@xml
O
ut
=
true
def
set
_xml_o
utput
@xml
_o
ut
=
true
end
# if write our output to XML
def
write
XmlOu
put
def
write
_xml_out
put
output
=
File
.
open
(
'report.xml'
,
'w'
)
output
<<
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>
\n
"
@array
L
ist
.
each
do
|
item
|
@array
_l
ist
.
each
do
|
item
|
output
<<
item
<<
"
\n
"
end
output
<<
"</testsuite>
\n
"
...
...
@@ -41,111 +42,113 @@ class ParseOutput
# This function will try and determine when the suite is changed. This is
# is the name that gets added to the classname parameter.
def
test
SuiteVerify
(
testSuiteN
ame
)
if
@testFlag
==
false
@testFlag
=
true
# Split the path nam
e
testName
=
testSuiteName
.
split
(
'/'
)
# Remove the extension
baseName
=
testName
[
testName
.
size
-
1
].
split
(
'.'
)
@testSuite
=
'test.'
+
baseName
[
0
]
printf
"New Test: %s
\n
"
,
@testSuite
end
def
test
_suite_verify
(
test_suite_n
ame
)
return
if
@test_flag
@test_flag
=
tru
e
# Split the path name
test_name
=
test_suite_name
.
split
(
'/'
)
# Remove the extension
base_name
=
test_name
[
test_name
.
size
-
1
].
split
(
'.'
)
@test_suite
=
'test.'
+
base_name
[
0
]
printf
"New Test: %s
\n
"
,
@test_suite
end
# Test was flagged as having passed so format the output
def
testPassed
(
array
)
lastItem
=
array
.
length
-
1
testName
=
array
[
lastItem
-
1
]
testSuiteVerify
(
array
[
@className
])
printf
"%-40s PASS
\n
"
,
testName
if
@xmlOut
==
true
@arrayList
.
push
' <testcase classname="'
+
@testSuite
+
'" name="'
+
testName
+
'"/>'
end
def
test_passed
(
array
)
last_item
=
array
.
length
-
1
test_name
=
array
[
last_item
-
1
]
test_suite_verify
(
array
[
@class_name
])
printf
"%-40s PASS
\n
"
,
test_name
return
unless
@xml_out
@array_list
.
push
' <testcase classname="'
+
@test_suite
+
'" name="'
+
test_name
+
'"/>'
end
# Test was flagged as having passed so format the output.
# This is using the Unity fixture output and not the original Unity output.
def
testPassedUnityFixture
(
array
)
testSuite
=
array
[
0
].
sub
(
'TEST('
,
''
)
testSuite
=
testSuite
.
sub
(
','
,
''
)
testName
=
array
[
1
].
sub
(
')'
,
''
)
if
@xmlOut
==
true
@arrayList
.
push
' <testcase classname="'
+
testSuite
+
'" name="'
+
testName
+
'"/>'
end
def
test_passed_unity_fixture
(
array
)
test_suite
=
array
[
0
].
sub
(
'TEST('
,
''
)
test_suite
=
test_suite
.
sub
(
','
,
''
)
test_name
=
array
[
1
].
sub
(
')'
,
''
)
return
unless
@xml_out
@array_list
.
push
' <testcase classname="'
+
test_suite
+
'" name="'
+
test_name
+
'"/>'
end
# Test was flagged as being ingored so format the output
def
test
I
gnored
(
array
)
last
I
tem
=
array
.
length
-
1
test
Name
=
array
[
lastI
tem
-
2
]
reason
=
array
[
last
I
tem
].
chomp
test
SuiteVerify
(
array
[
@classN
ame
])
printf
"%-40s IGNORED
\n
"
,
test
N
ame
if
test
N
ame
.
start_with?
'TEST('
array2
=
test
N
ame
.
split
(
' '
)
@test
S
uite
=
array2
[
0
].
sub
(
'TEST('
,
''
)
@test
Suite
=
@testS
uite
.
sub
(
','
,
''
)
test
N
ame
=
array2
[
1
].
sub
(
')'
,
''
)
def
test
_i
gnored
(
array
)
last
_i
tem
=
array
.
length
-
1
test
_name
=
array
[
last_i
tem
-
2
]
reason
=
array
[
last
_i
tem
].
chomp
test
_suite_verify
(
array
[
@class_n
ame
])
printf
"%-40s IGNORED
\n
"
,
test
_n
ame
if
test
_n
ame
.
start_with?
'TEST('
array2
=
test
_n
ame
.
split
(
' '
)
@test
_s
uite
=
array2
[
0
].
sub
(
'TEST('
,
''
)
@test
_suite
=
@test_s
uite
.
sub
(
','
,
''
)
test
_n
ame
=
array2
[
1
].
sub
(
')'
,
''
)
end
if
@xmlOut
==
true
@arrayList
.
push
' <testcase classname="'
+
@testSuite
+
'" name="'
+
testName
+
'">'
@arrayList
.
push
' <skipped type="TEST IGNORED"> '
+
reason
+
' </skipped
>'
@arrayList
.
push
' </testcase
>'
end
return
unless
@xml_out
@array_list
.
push
' <testcase classname="'
+
@test_suite
+
'" name="'
+
test_name
+
'"
>'
@array_list
.
push
' <skipped type="TEST IGNORED"> '
+
reason
+
' </skipped
>'
@array_list
.
push
' </testcase>'
end
# Test was flagged as having failed so format the line
def
test
F
ailed
(
array
)
last
I
tem
=
array
.
length
-
1
test
Name
=
array
[
lastI
tem
-
2
]
reason
=
array
[
last
Item
].
chomp
+
' at line: '
+
array
[
lastI
tem
-
3
]
test
SuiteVerify
(
array
[
@classN
ame
])
printf
"%-40s FAILED
\n
"
,
test
N
ame
if
test
N
ame
.
start_with?
'TEST('
array2
=
test
N
ame
.
split
(
' '
)
@test
S
uite
=
array2
[
0
].
sub
(
'TEST('
,
''
)
@test
Suite
=
@testS
uite
.
sub
(
','
,
''
)
test
N
ame
=
array2
[
1
].
sub
(
')'
,
''
)
def
test
_f
ailed
(
array
)
last
_i
tem
=
array
.
length
-
1
test
_name
=
array
[
last_i
tem
-
2
]
reason
=
array
[
last
_item
].
chomp
+
' at line: '
+
array
[
last_i
tem
-
3
]
test
_suite_verify
(
array
[
@class_n
ame
])
printf
"%-40s FAILED
\n
"
,
test
_n
ame
if
test
_n
ame
.
start_with?
'TEST('
array2
=
test
_n
ame
.
split
(
' '
)
@test
_s
uite
=
array2
[
0
].
sub
(
'TEST('
,
''
)
@test
_suite
=
@test_s
uite
.
sub
(
','
,
''
)
test
_n
ame
=
array2
[
1
].
sub
(
')'
,
''
)
end
if
@xmlOut
==
true
@arrayList
.
push
' <testcase classname="'
+
@testSuite
+
'" name="'
+
testName
+
'">'
@arrayList
.
push
' <failure type="ASSERT FAILED"> '
+
reason
+
' </failure
>'
@arrayList
.
push
' </testcas
e>'
end
return
unless
@xml_out
@array_list
.
push
' <testcase classname="'
+
@test_suite
+
'" name="'
+
test_name
+
'"
>'
@array_list
.
push
' <failure type="ASSERT FAILED"> '
+
reason
+
' </failur
e>'
@array_list
.
push
' </testcase>'
end
# Figure out what OS we are running on. For now we are assuming if it's not Windows it must
# be Unix based.
def
detect
OS
myOS
=
RUBY_PLATFORM
.
split
(
'-'
)
@class
Name
=
if
myOS
.
size
==
2
if
myOS
[
1
]
==
'mingw32'
1
else
0
end
else
0
end
def
detect
_os
os
=
RUBY_PLATFORM
.
split
(
'-'
)
@class
_name
=
if
os
.
size
==
2
if
os
[
1
]
==
'mingw32'
1
else
0
end
else
0
end
end
# Main function used to parse the file that was captured.
def
process
(
name
)
@test
F
lag
=
false
@array
L
ist
=
[]
@test
_f
lag
=
false
@array
_l
ist
=
[]
detect
OS
detect
_os
puts
'Parsing file: '
+
name
test
P
ass
=
0
test
F
ail
=
0
test
I
gnore
=
0
test
_p
ass
=
0
test
_f
ail
=
0
test
_i
gnore
=
0
puts
''
puts
'=================== RESULTS ====================='
puts
''
...
...
@@ -156,62 +159,61 @@ class ParseOutput
# <path>/<test_file>.c:115:test_tc5100_initCanVoidPtrs:PASS
#
# where path is different on Unix vs Windows devices (Windows leads with a drive letter)
line
A
rray
=
line
.
split
(
':'
)
lineSize
=
lineArray
.
size
line
_a
rray
=
line
.
split
(
':'
)
# If we were able to split the line then we can look to see if any of our target words
# were found. Case is important.
if
(
line
S
ize
>=
4
)
||
(
line
.
start_with?
'TEST('
)
if
(
line
_array
.
s
ize
>=
4
)
||
(
line
.
start_with?
'TEST('
)
# Determine if this test passed
if
line
.
include?
':PASS'
test
Passed
(
lineA
rray
)
test
P
ass
+=
1
test
_passed
(
line_a
rray
)
test
_p
ass
+=
1
elsif
line
.
include?
':FAIL:'
test
Failed
(
lineA
rray
)
test
F
ail
+=
1
test
_failed
(
line_a
rray
)
test
_f
ail
+=
1
elsif
line
.
include?
':IGNORE:'
test
Ignored
(
lineA
rray
)
test
I
gnore
+=
1
test
_ignored
(
line_a
rray
)
test
_i
gnore
+=
1
elsif
line
.
start_with?
'TEST('
if
line
.
include?
' PASS'
line
A
rray
=
line
.
split
(
' '
)
test
PassedUnityFixture
(
lineA
rray
)
test
P
ass
+=
1
line
_a
rray
=
line
.
split
(
' '
)
test
_passed_unity_fixture
(
line_a
rray
)
test
_p
ass
+=
1
end
# If none of the keywords are found there are no more tests for this suite so clear
# the test flag
else
@test
F
lag
=
false
@test
_f
lag
=
false
end
else
@test
F
lag
=
false
end
@test
_f
lag
=
false
end
end
puts
''
puts
'=================== SUMMARY ====================='
puts
''
puts
'Tests Passed : '
+
testPass
.
to_s
puts
'Tests Failed : '
+
testFail
.
to_s
puts
'Tests Ignored : '
+
testIgnore
.
to_s
@totalTests
=
testPass
+
testFail
+
testIgnore
if
@xmlOut
==
true
heading
=
'<testsuite tests="'
+
@totalTests
.
to_s
+
'" failures="'
+
testFail
.
to_s
+
'"'
+
' skips="'
+
testIgnore
.
to_s
+
'">'
@arrayList
.
insert
(
0
,
heading
)
writeXmlOuput
end
puts
'Tests Passed : '
+
test_pass
.
to_s
puts
'Tests Failed : '
+
test_fail
.
to_s
puts
'Tests Ignored : '
+
test_ignore
.
to_s
@total_tests
=
test_pass
+
test_fail
+
test_ignore
# return result
return
unless
@xml_out
heading
=
'<testsuite tests="'
+
@total_tests
.
to_s
+
'" failures="'
+
test_fail
.
to_s
+
'"'
+
' skips="'
+
test_ignore
.
to_s
+
'">'
@array_list
.
insert
(
0
,
heading
)
write_xml_output
end
end
end
# If the command line has no values in, used a default value of Output.txt
parse
MyF
ile
=
ParseOutput
.
new
parse
_my_f
ile
=
ParseOutput
.
new
if
ARGV
.
size
>=
1
ARGV
.
each
do
|
a
|
if
a
==
'-xml'
parse
MyFile
.
setXmlO
utput
parse
_my_file
.
set_xml_o
utput
else
parse
MyF
ile
.
process
(
a
)
parse
_my_f
ile
.
process
(
a
)
break
end
end
...
...
auto/stylize_as_junit.rb
浏览文件 @
2a5b24f7
...
...
@@ -23,37 +23,37 @@ class ArgvParser
options
.
root_path
=
'.'
options
.
out_file
=
'results.xml'
opts
=
OptionParser
.
new
do
|
o
pts
|
o
pts
.
banner
=
'Usage: unity_to_junit.rb [options]'
opts
=
OptionParser
.
new
do
|
o
|
o
.
banner
=
'Usage: unity_to_junit.rb [options]'
o
pts
.
separator
''
o
pts
.
separator
'Specific options:'
o
.
separator
''
o
.
separator
'Specific options:'
o
pts
.
on
(
'-r'
,
'--results <dir>'
,
'Look for Unity Results files here.'
)
do
|
results
|
o
.
on
(
'-r'
,
'--results <dir>'
,
'Look for Unity Results files here.'
)
do
|
results
|
# puts "results #{results}"
options
.
results_dir
=
results
end
o
pts
.
on
(
'-p'
,
'--root_path <path>'
,
'Prepend this path to files in results.'
)
do
|
root_path
|
o
.
on
(
'-p'
,
'--root_path <path>'
,
'Prepend this path to files in results.'
)
do
|
root_path
|
options
.
root_path
=
root_path
end
o
pts
.
on
(
'-o'
,
'--output <filename>'
,
'XML file to generate.'
)
do
|
out_file
|
o
.
on
(
'-o'
,
'--output <filename>'
,
'XML file to generate.'
)
do
|
out_file
|
# puts "out_file: #{out_file}"
options
.
out_file
=
out_file
end
o
pts
.
separator
''
o
pts
.
separator
'Common options:'
o
.
separator
''
o
.
separator
'Common options:'
# No argument, shows at tail. This will print an options summary.
o
pts
.
on_tail
(
'-h'
,
'--help'
,
'Show this message'
)
do
puts
o
pts
o
.
on_tail
(
'-h'
,
'--help'
,
'Show this message'
)
do
puts
o
exit
end
# Another typical switch to print the version.
o
pts
.
on_tail
(
'--version'
,
'Show version'
)
do
o
.
on_tail
(
'--version'
,
'Show version'
)
do
puts
"unity_to_junit.rb version
#{
VERSION
}
"
exit
end
...
...
@@ -67,6 +67,7 @@ end # class OptparseExample
class
UnityToJUnit
include
FileUtils
::
Verbose
attr_reader
:report
,
:total_tests
,
:failures
,
:ignored
attr_writer
:targets
,
:root
,
:out_file
def
initialize
@report
=
''
...
...
@@ -82,16 +83,16 @@ class UnityToJUnit
write_suites_header
(
f
)
results
.
each
do
|
result_file
|
lines
=
File
.
readlines
(
result_file
).
map
(
&
:chomp
)
if
lines
.
empty?
raise
"Empty test result file:
#{
result_file
}
"
else
result_output
=
get_details
(
result_file
,
lines
)
tests
,
failures
,
ignored
=
parse_test_summary
(
lines
)
result_output
[
:counts
][
:total
]
=
tests
result_output
[
:counts
][
:failed
]
=
failures
result_output
[
:counts
][
:ignored
]
=
ignored
result_output
[
:counts
][
:passed
]
=
(
result_output
[
:counts
][
:total
]
-
result_output
[
:counts
][
:failed
]
-
result_output
[
:counts
][
:ignored
])
end
raise
"Empty test result file:
#{
result_file
}
"
if
lines
.
empty?
result_output
=
get_details
(
result_file
,
lines
)
tests
,
failures
,
ignored
=
parse_test_summary
(
lines
)
result_output
[
:counts
][
:total
]
=
tests
result_output
[
:counts
][
:failed
]
=
failures
result_output
[
:counts
][
:ignored
]
=
ignored
result_output
[
:counts
][
:passed
]
=
(
result_output
[
:counts
][
:total
]
-
result_output
[
:counts
][
:failed
]
-
result_output
[
:counts
][
:ignored
])
# use line[0] from the test output to get the test_file path and name
test_file_str
=
lines
[
0
].
tr
(
'\\'
,
'/'
)
test_file_str
=
test_file_str
.
split
(
':'
)
...
...
@@ -99,7 +100,7 @@ class UnityToJUnit
result_file
else
test_file_str
[
0
]
+
':'
+
test_file_str
[
1
]
end
end
result_output
[
:source
][
:path
]
=
File
.
dirname
(
test_file
)
result_output
[
:source
][
:file
]
=
File
.
basename
(
test_file
)
...
...
@@ -116,18 +117,6 @@ class UnityToJUnit
f
.
close
end
def
set_targets
(
target_array
)
@targets
=
target_array
end
def
set_root_path
(
path
)
@root
=
path
end
def
set_out_file
(
filename
)
@out_file
=
filename
end
def
usage
(
err_msg
=
nil
)
puts
"
\n
ERROR: "
puts
err_msg
if
err_msg
...
...
@@ -148,11 +137,10 @@ class UnityToJUnit
protected
def
get_details
(
_result_file
,
lines
)
results
=
get_
results_structure
results
=
results_structure
lines
.
each
do
|
line
|
line
=
line
.
tr
(
'\\'
,
'/'
)
src_file
,
src_line
,
test_name
,
status
,
msg
=
line
.
split
(
/:/
)
line_out
=
(
@root
&&
(
@root
!=
0
)
?
"
#{
@root
}#{
line
}
"
:
line
).
gsub
(
/\//
,
'\\'
)
_src_file
,
src_line
,
test_name
,
status
,
msg
=
line
.
split
(
/:/
)
case
status
when
'IGNORE'
then
results
[
:ignores
]
<<
{
test:
test_name
,
line:
src_line
,
message:
msg
}
when
'FAIL'
then
results
[
:failures
]
<<
{
test:
test_name
,
line:
src_line
,
message:
msg
}
...
...
@@ -163,11 +151,8 @@ class UnityToJUnit
end
def
parse_test_summary
(
summary
)
if
summary
.
find
{
|
v
|
v
=~
/(\d+) Tests (\d+) Failures (\d+) Ignored/
}
[
Regexp
.
last_match
(
1
).
to_i
,
Regexp
.
last_match
(
2
).
to_i
,
Regexp
.
last_match
(
3
).
to_i
]
else
raise
"Couldn't parse test results:
#{
summary
}
"
end
raise
"Couldn't parse test results:
#{
summary
}
"
unless
summary
.
find
{
|
v
|
v
=~
/(\d+) Tests (\d+) Failures (\d+) Ignored/
}
[
Regexp
.
last_match
(
1
).
to_i
,
Regexp
.
last_match
(
2
).
to_i
,
Regexp
.
last_match
(
3
).
to_i
]
end
def
here
...
...
@@ -176,7 +161,7 @@ class UnityToJUnit
private
def
get_
results_structure
def
results_structure
{
source:
{
path:
''
,
file:
''
},
successes:
[],
...
...
@@ -213,7 +198,6 @@ class UnityToJUnit
def
write_tests
(
results
,
stream
)
result
=
results
[
:successes
]
result
.
each
do
|
item
|
filename
=
File
.
join
(
results
[
:source
][
:path
],
File
.
basename
(
results
[
:source
][
:file
],
'.*'
))
stream
.
puts
"
\t\t
<testcase classname=
\"
#{
@unit_name
}
\"
name=
\"
#{
item
[
:test
]
}
\"
time=
\"
0
\"
/>"
end
end
...
...
@@ -239,7 +223,7 @@ class UnityToJUnit
end
end
# UnityToJUnit
if
__FILE__
==
$
PROGRAM_NAME
if
__FILE__
==
$
0
# parse out the command options
options
=
ArgvParser
.
parse
(
ARGV
)
...
...
@@ -251,18 +235,18 @@ if __FILE__ == $PROGRAM_NAME
results
=
Dir
[
targets
]
raise
"No *.testpass, *.testfail, or *.testresults files found in '
#{
targets
}
'"
if
results
.
empty?
utj
.
set_targets
(
results
)
utj
.
targets
=
results
# set the root path
utj
.
set_root_path
(
options
.
root_path
)
utj
.
root
=
options
.
root_path
# set the output XML file name
# puts "Output File from options: #{options.out_file}"
utj
.
set_out_file
(
options
.
out_file
)
utj
.
out_file
=
options
.
out_file
# run the summarizer
puts
utj
.
run
rescue
Exception
=>
e
rescue
StandardError
=>
e
utj
.
usage
e
.
message
end
end
auto/test_file_filter.rb
浏览文件 @
2a5b24f7
...
...
@@ -10,15 +10,16 @@ module RakefileHelpers
class
TestFileFilter
def
initialize
(
all_files
=
false
)
@all_files
=
all_files
if
@all_files
!=
true
if
File
.
exist?
(
'test_file_filter.yml'
)
filters
=
YAML
.
load_file
(
'test_file_filter.yml'
)
@all_files
=
filters
[
:all_files
]
@only_files
=
filters
[
:only_files
]
@exclude_files
=
filters
[
:exclude
_files
]
end
end
return
false
unless
@all_files
return
false
unless
File
.
exist?
(
'test_file_filter.yml'
)
filters
=
YAML
.
load_file
(
'test_file_filter.yml'
)
@all_files
=
filters
[
:all
_files
]
@only_files
=
filters
[
:only_files
]
@exclude_files
=
filters
[
:exclude_files
]
end
attr_accessor
:all_files
,
:only_files
,
:exclude_files
end
end
auto/unity_test_summary.rb
浏览文件 @
2a5b24f7
...
...
@@ -15,6 +15,7 @@ class UnityTestSummary
include
FileUtils
::
Verbose
attr_reader
:report
,
:total_tests
,
:failures
,
:ignored
attr_writer
:targets
,
:root
def
initialize
(
_opts
=
{})
@report
=
''
...
...
@@ -33,17 +34,16 @@ class UnityTestSummary
results
.
each
do
|
result_file
|
lines
=
File
.
readlines
(
result_file
).
map
(
&
:chomp
)
if
lines
.
empty?
raise
"Empty test result file:
#{
result_file
}
"
else
output
=
get_details
(
result_file
,
lines
)
failure_output
<<
output
[
:failures
]
unless
output
[
:failures
].
empty?
ignore_output
<<
output
[
:ignores
]
unless
output
[
:ignores
].
empty?
tests
,
failures
,
ignored
=
parse_test_summary
(
lines
)
@total_tests
+=
tests
@failures
+=
failures
@ignored
+=
ignored
end
raise
"Empty test result file:
#{
result_file
}
"
if
lines
.
empty?
output
=
get_details
(
result_file
,
lines
)
failure_output
<<
output
[
:failures
]
unless
output
[
:failures
].
empty?
ignore_output
<<
output
[
:ignores
]
unless
output
[
:ignores
].
empty?
tests
,
failures
,
ignored
=
parse_test_summary
(
lines
)
@total_tests
+=
tests
@failures
+=
failures
@ignored
+=
ignored
end
if
@ignored
>
0
...
...
@@ -70,14 +70,6 @@ class UnityTestSummary
@report
+=
"
\n
"
end
def
set_targets
(
target_array
)
@targets
=
target_array
end
def
set_root_path
(
path
)
@root
=
path
end
def
usage
(
err_msg
=
nil
)
puts
"
\n
ERROR: "
puts
err_msg
if
err_msg
...
...
@@ -94,7 +86,7 @@ class UnityTestSummary
def
get_details
(
_result_file
,
lines
)
results
=
{
failures:
[],
ignores:
[],
successes:
[]
}
lines
.
each
do
|
line
|
src_file
,
src_line
,
test_name
,
status
,
msg
=
line
.
split
(
/:/
)
_src_file
,
_src_line
,
_test_name
,
status
,
_
msg
=
line
.
split
(
/:/
)
line_out
=
(
@root
&&
(
@root
!=
0
)
?
"
#{
@root
}#{
line
}
"
:
line
).
gsub
(
/\//
,
'\\'
)
case
status
when
'IGNORE'
then
results
[
:ignores
]
<<
line_out
...
...
@@ -106,11 +98,8 @@ class UnityTestSummary
end
def
parse_test_summary
(
summary
)
if
summary
.
find
{
|
v
|
v
=~
/(\d+) Tests (\d+) Failures (\d+) Ignored/
}
[
Regexp
.
last_match
(
1
).
to_i
,
Regexp
.
last_match
(
2
).
to_i
,
Regexp
.
last_match
(
3
).
to_i
]
else
raise
"Couldn't parse test results:
#{
summary
}
"
end
raise
"Couldn't parse test results:
#{
summary
}
"
unless
summary
.
find
{
|
v
|
v
=~
/(\d+) Tests (\d+) Failures (\d+) Ignored/
}
[
Regexp
.
last_match
(
1
).
to_i
,
Regexp
.
last_match
(
2
).
to_i
,
Regexp
.
last_match
(
3
).
to_i
]
end
def
here
...
...
@@ -118,7 +107,7 @@ class UnityTestSummary
end
end
if
$
PROGRAM_NAME
==
__FILE__
if
$
0
==
__FILE__
# parse out the command options
opts
,
args
=
ARGV
.
partition
{
|
v
|
v
=~
/^--\w+/
}
...
...
@@ -133,15 +122,15 @@ if $PROGRAM_NAME == __FILE__
targets
=
"
#{
ARGV
[
0
].
tr
(
'\\'
,
'/'
)
}
**/*.test*"
results
=
Dir
[
targets
]
raise
"No *.testpass, *.testfail, or *.testresults files found in '
#{
targets
}
'"
if
results
.
empty?
uts
.
set_targets
(
results
)
uts
.
targets
=
results
# set the root path
args
[
1
]
||=
Dir
.
pwd
+
'/'
uts
.
set_root_path
(
ARGV
[
1
])
uts
.
root
=
ARGV
[
1
]
# run the summarizer
puts
uts
.
run
rescue
Exception
=>
e
rescue
StandardError
=>
e
uts
.
usage
e
.
message
end
end
examples/example_3/rakefile.rb
浏览文件 @
2a5b24f7
...
...
@@ -23,7 +23,7 @@ DEFAULT_CONFIG_FILE = 'target_gcc_32.yml'.freeze
configure_toolchain
(
DEFAULT_CONFIG_FILE
)
task
unit:
[
:prepare_for_tests
]
do
run_tests
get_
unit_test_files
run_tests
unit_test_files
end
desc
'Generate test summary'
...
...
examples/example_3/rakefile_helper.rb
浏览文件 @
2a5b24f7
...
...
@@ -22,13 +22,13 @@ module RakefileHelpers
configure_clean
end
def
get_
unit_test_files
def
unit_test_files
path
=
$cfg
[
'compiler'
][
'unit_tests_path'
]
+
'Test*'
+
C_EXTENSION
path
.
tr!
(
'\\'
,
'/'
)
FileList
.
new
(
path
)
end
def
get_
local_include_dirs
def
local_include_dirs
include_dirs
=
$cfg
[
'compiler'
][
'includes'
][
'items'
].
dup
include_dirs
.
delete_if
{
|
dir
|
dir
.
is_a?
(
Array
)
}
include_dirs
...
...
@@ -69,14 +69,15 @@ module RakefileHelpers
def
build_compiler_fields
command
=
tackit
(
$cfg
[
'compiler'
][
'path'
])
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
defines
=
''
else
defines
=
squash
(
$cfg
[
'compiler'
][
'defines'
][
'prefix'
],
$cfg
[
'compiler'
][
'defines'
][
'items'
])
end
defines
=
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
''
else
squash
(
$cfg
[
'compiler'
][
'defines'
][
'prefix'
],
$cfg
[
'compiler'
][
'defines'
][
'items'
])
end
options
=
squash
(
''
,
$cfg
[
'compiler'
][
'options'
])
includes
=
squash
(
$cfg
[
'compiler'
][
'includes'
][
'prefix'
],
$cfg
[
'compiler'
][
'includes'
][
'items'
])
includes
=
includes
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
{
command:
command
,
defines:
defines
,
options:
options
,
includes:
includes
}
end
...
...
@@ -96,12 +97,12 @@ module RakefileHelpers
else
squash
(
''
,
$cfg
[
'linker'
][
'options'
])
end
if
$cfg
[
'linker'
][
'includes'
].
nil?
||
$cfg
[
'linker'
][
'includes'
][
'items'
].
nil?
includes
=
''
else
includes
=
squash
(
$cfg
[
'linker'
][
'includes'
][
'prefix'
],
$cfg
[
'linker'
][
'includes'
][
'items'
])
end
includes
=
includes
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
i
ncludes
=
i
f
$cfg
[
'linker'
][
'includes'
].
nil?
||
$cfg
[
'linker'
][
'includes'
][
'items'
].
nil?
''
else
squash
(
$cfg
[
'linker'
][
'includes'
][
'prefix'
],
$cfg
[
'linker'
][
'includes'
][
'items'
])
end
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
{
command:
command
,
options:
options
,
includes:
includes
}
end
...
...
@@ -127,11 +128,12 @@ module RakefileHelpers
else
squash
(
''
,
$cfg
[
'simulator'
][
'pre_support'
])
end
if
$cfg
[
'simulator'
][
'post_support'
].
nil?
post_support
=
''
else
post_support
=
squash
(
''
,
$cfg
[
'simulator'
][
'post_support'
])
end
post_support
=
if
$cfg
[
'simulator'
][
'post_support'
].
nil?
''
else
squash
(
''
,
$cfg
[
'simulator'
][
'post_support'
])
end
{
command:
command
,
pre_support:
pre_support
,
post_support:
post_support
}
end
...
...
@@ -139,7 +141,7 @@ module RakefileHelpers
report
command_string
output
=
`
#{
command_string
}
`
.
chomp
report
(
output
)
if
verbose
&&
!
output
.
nil?
&&
!
output
.
empty?
if
(
$?
.
exitstatus
!=
0
)
&&
raise_on_fail
if
!
$?
.
exitstatus
.
zero?
&&
raise_on_fail
raise
"Command failed. (Returned
#{
$?
.
exitstatus
}
)"
end
output
...
...
@@ -147,11 +149,11 @@ module RakefileHelpers
def
report_summary
summary
=
UnityTestSummary
.
new
summary
.
set_root_path
(
HERE
)
summary
.
root
=
HERE
results_glob
=
"
#{
$cfg
[
'compiler'
][
'build_path'
]
}
*.test*"
results_glob
.
tr!
(
'\\'
,
'/'
)
results
=
Dir
[
results_glob
]
summary
.
set_targets
(
results
)
summary
.
targets
=
results
summary
.
run
fail_out
'FAIL: There were failures'
if
summary
.
failures
>
0
end
...
...
@@ -165,7 +167,7 @@ module RakefileHelpers
$cfg
[
'compiler'
][
'defines'
][
'items'
]
=
[]
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
$cfg
[
'compiler'
][
'defines'
][
'items'
]
<<
'TEST'
include_dirs
=
get_
local_include_dirs
include_dirs
=
local_include_dirs
# Build and execute each unit test
test_files
.
each
do
|
test
|
...
...
@@ -200,11 +202,11 @@ module RakefileHelpers
# Execute unit test and generate results file
simulator
=
build_simulator_fields
executable
=
$cfg
[
'linker'
][
'bin_files'
][
'destination'
]
+
test_base
+
$cfg
[
'linker'
][
'bin_files'
][
'extension'
]
if
simulator
.
nil?
cmd_str
=
executable
else
cmd_str
=
"
#{
simulator
[
:command
]
}
#{
simulator
[
:pre_support
]
}
#{
executable
}
#{
simulator
[
:post_support
]
}
"
end
cmd_str
=
if
simulator
.
nil?
executable
else
"
#{
simulator
[
:command
]
}
#{
simulator
[
:pre_support
]
}
#{
executable
}
#{
simulator
[
:post_support
]
}
"
end
output
=
execute
(
cmd_str
,
true
,
false
)
test_results
=
$cfg
[
'compiler'
][
'build_path'
]
+
test_base
test_results
+=
if
output
.
match
(
/OK$/m
).
nil?
...
...
extras/fixture/rakefile_helper.rb
浏览文件 @
2a5b24f7
...
...
@@ -14,12 +14,12 @@ module RakefileHelpers
C_EXTENSION
=
'.c'
.
freeze
def
load_configuration
(
config_file
)
unless
$configured
$cfg_file
=
HERE
+
"../../test/targets/
#{
config_file
}
"
unless
config_file
=~
/[\\|\/]/
$cfg
=
YAML
.
load
(
File
.
read
(
$cfg_file
))
$colour_output
=
false
unless
$cfg
[
'colour'
]
$configured
=
true
if
config_file
!=
DEFAULT_CONFIG_FILE
end
return
if
$configured
$cfg_file
=
HERE
+
"../../test/targets/
#{
config_file
}
"
unless
config_file
=~
/[\\|\/]/
$cfg
=
YAML
.
load
(
File
.
read
(
$cfg_file
))
$colour_output
=
false
unless
$cfg
[
'colour'
]
$configured
=
true
if
config_file
!=
DEFAULT_CONFIG_FILE
end
def
configure_clean
...
...
@@ -50,14 +50,15 @@ module RakefileHelpers
def
build_compiler_fields
command
=
tackit
(
$cfg
[
'compiler'
][
'path'
])
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
defines
=
''
else
defines
=
squash
(
$cfg
[
'compiler'
][
'defines'
][
'prefix'
],
$cfg
[
'compiler'
][
'defines'
][
'items'
]
+
[
'UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar'
])
end
defines
=
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
''
else
squash
(
$cfg
[
'compiler'
][
'defines'
][
'prefix'
],
$cfg
[
'compiler'
][
'defines'
][
'items'
]
+
[
'UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar'
])
end
options
=
squash
(
''
,
$cfg
[
'compiler'
][
'options'
])
includes
=
squash
(
$cfg
[
'compiler'
][
'includes'
][
'prefix'
],
$cfg
[
'compiler'
][
'includes'
][
'items'
])
includes
=
includes
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
{
command:
command
,
defines:
defines
,
options:
options
,
includes:
includes
}
end
...
...
@@ -67,6 +68,7 @@ module RakefileHelpers
cmd_str
=
"
#{
compiler
[
:command
]
}#{
compiler
[
:defines
]
}#{
compiler
[
:options
]
}#{
compiler
[
:includes
]
}
#{
unity_include
}
#{
file
}
"
\
"
#{
$cfg
[
'compiler'
][
'object_files'
][
'prefix'
]
}#{
$cfg
[
'compiler'
][
'object_files'
][
'destination'
]
}
"
\
"
#{
File
.
basename
(
file
,
C_EXTENSION
)
}#{
$cfg
[
'compiler'
][
'object_files'
][
'extension'
]
}
"
execute
(
cmd_str
)
end
...
...
@@ -77,12 +79,12 @@ module RakefileHelpers
else
squash
(
''
,
$cfg
[
'linker'
][
'options'
])
end
if
$cfg
[
'linker'
][
'includes'
].
nil?
||
$cfg
[
'linker'
][
'includes'
][
'items'
].
nil?
includes
=
''
else
includes
=
squash
(
$cfg
[
'linker'
][
'includes'
][
'prefix'
],
$cfg
[
'linker'
][
'includes'
][
'items'
])
end
includes
=
includes
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
i
ncludes
=
i
f
$cfg
[
'linker'
][
'includes'
].
nil?
||
$cfg
[
'linker'
][
'includes'
][
'items'
].
nil?
''
else
squash
(
$cfg
[
'linker'
][
'includes'
][
'prefix'
],
$cfg
[
'linker'
][
'includes'
][
'items'
])
end
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
{
command:
command
,
options:
options
,
includes:
includes
}
end
...
...
@@ -108,11 +110,11 @@ module RakefileHelpers
else
squash
(
''
,
$cfg
[
'simulator'
][
'pre_support'
])
end
if
$cfg
[
'simulator'
][
'post_support'
].
nil?
post_support
=
''
else
post_support
=
squash
(
''
,
$cfg
[
'simulator'
][
'post_support'
])
end
post_support
=
if
$cfg
[
'simulator'
][
'post_support'
].
nil?
''
else
squash
(
''
,
$cfg
[
'simulator'
][
'post_support'
])
end
{
command:
command
,
pre_support:
pre_support
,
post_support:
post_support
}
end
...
...
@@ -126,11 +128,11 @@ module RakefileHelpers
def
report_summary
summary
=
UnityTestSummary
.
new
summary
.
set_root_path
(
HERE
)
summary
.
root
=
HERE
results_glob
=
"
#{
$cfg
[
'compiler'
][
'build_path'
]
}
*.test*"
results_glob
.
tr!
(
'\\'
,
'/'
)
results
=
Dir
[
results_glob
]
summary
.
set_targets
(
results
)
summary
.
targets
=
results
summary
.
run
end
...
...
@@ -159,11 +161,11 @@ module RakefileHelpers
# Execute unit test and generate results file
simulator
=
build_simulator_fields
executable
=
$cfg
[
'linker'
][
'bin_files'
][
'destination'
]
+
test_base
+
$cfg
[
'linker'
][
'bin_files'
][
'extension'
]
if
simulator
.
nil?
cmd_str
=
executable
+
' -v -r'
else
cmd_str
=
"
#{
simulator
[
:command
]
}
#{
simulator
[
:pre_support
]
}
#{
executable
}
#{
simulator
[
:post_support
]
}
"
end
cmd_str
=
if
simulator
.
nil?
executable
+
' -v -r'
else
"
#{
simulator
[
:command
]
}
#{
simulator
[
:pre_support
]
}
#{
executable
}
#{
simulator
[
:post_support
]
}
"
end
output
=
execute
(
cmd_str
)
test_results
=
$cfg
[
'compiler'
][
'build_path'
]
+
test_base
test_results
+=
if
output
.
match
(
/OK$/m
).
nil?
...
...
test/.rubocop.yml
浏览文件 @
2a5b24f7
# This is the configuration used to check the rubocop source code.
inherit_from
:
.rubocop_todo.yml
#
inherit_from: .rubocop_todo.yml
AllCops
:
TargetRubyVersion
:
2.1
# These are areas where ThrowTheSwitch's coding style diverges from the Ruby standard
# (Maybe we will make these conform over time)
Style/SpecialGlobalVars
:
SupportedStyles
:
-
use_perl_names
-
use_english_names
EnforcedStyle
:
use_perl_names
Style/FormatString
:
Enabled
:
false
Style/GlobalVars
:
Enabled
:
false
Style/RegexpLiteral
:
AllowInnerSlashes
:
true
Style/HashSyntax
:
EnforcedStyle
:
no_mixed_keys
# This is disabled because it seems to get confused over nested hashes
Style/AlignHash
:
...
...
@@ -48,6 +50,8 @@ Metrics/LineLength:
Enabled
:
false
Metrics/MethodLength
:
Enabled
:
false
Metrics/ModuleLength
:
Enabled
:
false
Metrics/ParameterLists
:
Enabled
:
false
Metrics/PerceivedComplexity
:
...
...
test/.rubocop_todo.yml
已删除
100644 → 0
浏览文件 @
3e0a7121
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2017-03-28 15:45:51 -0400 using RuboCop version 0.48.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# Cop supports --auto-correct.
Lint/DeprecatedClassMethods
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Lint/EndAlignment
:
Exclude
:
-
'
../auto/colour_prompt.rb'
-
'
../auto/colour_reporter.rb'
-
'
../auto/parseOutput.rb'
-
'
../auto/stylize_as_junit.rb'
# Offense count: 2
Lint/RescueException
:
Exclude
:
-
'
../auto/stylize_as_junit.rb'
-
'
../auto/unity_test_summary.rb'
# Offense count: 1
Lint/ShadowingOuterLocalVariable
:
Exclude
:
-
'
../auto/stylize_as_junit.rb'
# Offense count: 3
# Cop supports --auto-correct.
Lint/StringConversionInInterpolation
:
Exclude
:
-
'
tests/test_generate_test_runner.rb'
# Offense count: 13
Lint/UselessAssignment
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
-
'
../auto/stylize_as_junit.rb'
-
'
../auto/unity_test_summary.rb'
-
'
rakefile_helper.rb'
# Offense count: 5
Lint/Void
:
Exclude
:
-
'
../auto/parseOutput.rb'
# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ModuleLength
:
Max
:
204
# Offense count: 2
# Cop supports --auto-correct.
Performance/StringReplacement
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 10
Style/AccessorMethodName
:
Exclude
:
-
'
../auto/stylize_as_junit.rb'
-
'
../auto/unity_test_summary.rb'
-
'
../examples/example_3/rakefile_helper.rb'
-
'
rakefile_helper.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters
:
Exclude
:
-
'
spec/generate_module_existing_file_spec.rb'
# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment
:
Exclude
:
-
'
../examples/example_3/rakefile_helper.rb'
-
'
../extras/fixture/rakefile_helper.rb'
-
'
rakefile_helper.rb'
# Offense count: 2
# Cop supports --auto-correct.
Style/ElseAlignment
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
# Offense count: 3
# Cop supports --auto-correct.
Style/EmptyLines
:
Exclude
:
-
'
tests/test_generate_test_runner.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, no_empty_lines
Style/EmptyLinesAroundBlockBody
:
Exclude
:
-
'
rakefile_helper.rb'
-
'
spec/generate_module_existing_file_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Style/EmptyLinesAroundModuleBody
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 14
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Style/ExtraSpacing
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 1
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
Style/FileName
:
Exclude
:
-
'
../auto/parseOutput.rb'
# Offense count: 164
# Configuration parameters: AllowedVariables.
Style/GlobalVars
:
Exclude
:
-
'
../auto/colour_reporter.rb'
-
'
../examples/example_3/rakefile_helper.rb'
-
'
../extras/fixture/rakefile.rb'
-
'
../extras/fixture/rakefile_helper.rb'
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 20
# Configuration parameters: MinBodyLength.
Style/GuardClause
:
Exclude
:
-
'
../auto/colour_prompt.rb'
-
'
../auto/generate_test_runner.rb'
-
'
../auto/parseOutput.rb'
-
'
../auto/stylize_as_junit.rb'
-
'
../auto/test_file_filter.rb'
-
'
../auto/unity_test_summary.rb'
-
'
../extras/fixture/rakefile_helper.rb'
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 630
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Style/HashSyntax
:
Exclude
:
-
'
rakefile_helper.rb'
-
'
spec/generate_module_existing_file_spec.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IndentationWidth.
Style/IndentAssignment
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: Width, IgnoredPatterns.
Style/IndentationWidth
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
-
'
spec/generate_module_existing_file_spec.rb'
# Offense count: 17
# Cop supports --auto-correct.
Style/LeadingCommentSpace
:
Exclude
:
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/LineEndConcatenation
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 8
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase
Style/MethodName
:
Exclude
:
-
'
../auto/parseOutput.rb'
# Offense count: 40
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Style/MultilineArrayBraceLayout
:
Exclude
:
-
'
tests/test_generate_test_runner.rb'
# Offense count: 63
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: symmetrical, new_line, same_line
Style/MultilineHashBraceLayout
:
Exclude
:
-
'
tests/test_generate_test_runner.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
# SupportedStyles: aligned, indented
Style/MultilineOperationIndentation
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 3
# Cop supports --auto-correct.
Style/MutableConstant
:
Exclude
:
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: both, prefix, postfix
Style/NegatedIf
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/Not
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
# SupportedStyles: predicate, comparison
Style/NumericPredicate
:
Exclude
:
-
'
spec/**/*'
-
'
../auto/colour_reporter.rb'
# Offense count: 17
# Cop supports --auto-correct.
# Configuration parameters: AllowSafeAssignment.
Style/ParenthesesAroundCondition
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 7
# Cop supports --auto-correct.
Style/RedundantParentheses
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn
:
Exclude
:
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
-
'
../auto/stylize_as_junit.rb'
-
'
../auto/type_sanitizer.rb'
-
'
../auto/unity_test_summary.rb'
-
'
../extras/fixture/rakefile_helper.rb'
-
'
rakefile_helper.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
# Offense count: 5
# Cop supports --auto-correct.
Style/SpaceAfterComma
:
Exclude
:
-
'
tests/test_generate_test_runner.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleInsidePipes, SupportedStylesInsidePipes.
# SupportedStylesInsidePipes: space, no_space
Style/SpaceAroundBlockParameters
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceAroundEqualsInParameterDefault
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment.
Style/SpaceAroundOperators
:
Exclude
:
-
'
rakefile_helper.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: space, no_space
Style/SpaceBeforeBlockBraces
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Style/SpaceInsideBlockBraces
:
Exclude
:
-
'
rakefile_helper.rb'
-
'
spec/generate_module_existing_file_spec.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 295
# Cop supports --auto-correct.
Style/SpaceInsideBrackets
:
Exclude
:
-
'
tests/test_generate_test_runner.rb'
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Style/SpaceInsideHashLiteralBraces
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 5
# Cop supports --auto-correct.
Style/SpaceInsideParens
:
Exclude
:
-
'
tests/test_generate_test_runner.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars
:
Exclude
:
-
'
../auto/generate_test_runner.rb'
-
'
../auto/stylize_as_junit.rb'
-
'
../auto/unity_test_summary.rb'
# Offense count: 167
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals
:
Exclude
:
-
'
rakefile_helper.rb'
-
'
spec/generate_module_existing_file_spec.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
Style/TernaryParentheses
:
Exclude
:
-
'
rakefile_helper.rb'
# Offense count: 152
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInLiteral
:
Exclude
:
-
'
spec/generate_module_existing_file_spec.rb'
-
'
tests/test_generate_test_runner.rb'
# Offense count: 39
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase
Style/VariableName
:
Exclude
:
-
'
../auto/parseOutput.rb'
# Offense count: 69
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, WordRegex.
# SupportedStyles: percent, brackets
Style/WordArray
:
EnforcedStyle
:
percent
MinSize
:
12
# Offense count: 1
# Cop supports --auto-correct.
Style/ZeroLengthPredicate
:
Exclude
:
-
'
rakefile_helper.rb'
test/rakefile
浏览文件 @
2a5b24f7
...
...
@@ -32,7 +32,7 @@ configure_toolchain(DEFAULT_CONFIG_FILE)
desc
"Test unity with its own unit tests"
task
:unit
=>
[
:prepare_for_tests
]
do
run_tests
get_
unit_test_files
run_tests
unit_test_files
end
desc
"Test unity's helper scripts"
...
...
@@ -74,32 +74,35 @@ end
namespace
:style
do
desc
"Check style"
task
:check
do
report
execute
(
"rubocop ../ --config .rubocop.yml"
,
true
)
report
"Style Checked."
report
"
\n
VERIFYING RUBY STYLE"
report
execute
(
"rubocop ../auto ../examples ../extras --config .rubocop.yml"
,
true
)
report
"Style PASSED."
end
namespace
:check
do
Dir
[
'../**/*.rb'
].
each
do
|
f
|
task
File
.
basename
(
f
,
'.rb'
).
to_sym
do
task
File
.
basename
(
f
,
'.rb'
).
to_sym
=>
[
'style:clean'
]
do
report
execute
(
"rubocop
#{
f
}
--color --config .rubocop.yml"
,
true
)
report
"Style Checked
.
"
report
"Style Checked
for
#{
f
}
"
end
end
end
desc
"Attempt to Autocorrect style"
task
:auto
do
File
.
delete
(
".rubocop_todo.yml"
)
execute
(
"rubocop ../ --auto-correct --config .rubocop.yml"
)
task
:auto
=>
[
'style:clean'
]
do
execute
(
"rubocop ../auto ../examples ../extras --auto-correct --config .rubocop.yml"
)
report
"Autocorrected What We Could."
end
desc
"Update style todo list"
task
:todo
do
File
.
delete
(
".rubocop_todo.yml"
)
execute
(
"rubocop ../ --auto-gen-config --config .rubocop.yml"
)
task
:todo
=>
[
'style:clean'
]
do
execute
(
"rubocop ../auto ../examples ../extras --auto-gen-config --config .rubocop.yml"
)
report
"Updated Style TODO List."
end
task
:clean
do
File
.
delete
(
".rubocop_todo.yml"
)
if
File
.
exists?
(
".rubocop_todo.yml"
)
end
end
task
:style
=>
[
'style:check'
]
test/rakefile_helper.rb
浏览文件 @
2a5b24f7
...
...
@@ -11,39 +11,37 @@ require UNITY_ROOT + '../auto/generate_test_runner'
require
UNITY_ROOT
+
'../auto/colour_reporter'
module
RakefileHelpers
C_EXTENSION
=
'.c'
C_EXTENSION
=
'.c'
.
freeze
def
load_configuration
(
config_file
)
unless
(
$configured
)
$cfg_file
=
"targets/
#{
config_file
}
"
unless
(
config_file
=~
/[\\|\/]/
)
$cfg
=
YAML
.
load
(
File
.
read
(
$cfg_file
))
$colour_output
=
false
unless
$cfg
[
'colour'
]
$configured
=
true
if
(
config_file
!=
DEFAULT_CONFIG_FILE
)
end
return
if
$configured
$cfg_file
=
"targets/
#{
config_file
}
"
unless
config_file
=~
/[\\|\/]/
$cfg
=
YAML
.
load
(
File
.
read
(
$cfg_file
))
$colour_output
=
false
unless
$cfg
[
'colour'
]
$configured
=
true
if
config_file
!=
DEFAULT_CONFIG_FILE
end
def
configure_clean
CLEAN
.
include
(
$cfg
[
'compiler'
][
'build_path'
]
+
'*.*'
)
unless
$cfg
[
'compiler'
][
'build_path'
].
nil?
end
def
configure_toolchain
(
config_file
=
DEFAULT_CONFIG_FILE
)
def
configure_toolchain
(
config_file
=
DEFAULT_CONFIG_FILE
)
config_file
+=
'.yml'
unless
config_file
=~
/\.yml$/
config_file
=
config_file
unless
config_file
=~
/[\\|\/]/
load_configuration
(
config_file
)
configure_clean
end
def
get_
unit_test_files
def
unit_test_files
path
=
$cfg
[
'compiler'
][
'unit_tests_path'
]
+
'test*'
+
C_EXTENSION
path
.
gsub!
(
/\\/
,
'/'
)
path
.
tr!
(
'\\'
,
'/'
)
FileList
.
new
(
path
)
end
def
get_
local_include_dirs
def
local_include_dirs
include_dirs
=
$cfg
[
'compiler'
][
'includes'
][
'items'
].
dup
include_dirs
.
delete_if
{
|
dir
|
dir
.
is_a?
(
Array
)
}
return
include_dirs
include_dirs
.
delete_if
{
|
dir
|
dir
.
is_a?
(
Array
)
}
include_dirs
end
def
extract_headers
(
filename
)
...
...
@@ -51,41 +49,37 @@ module RakefileHelpers
lines
=
File
.
readlines
(
filename
)
lines
.
each
do
|
line
|
m
=
line
.
match
(
/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/
)
if
not
m
.
nil?
includes
<<
m
[
1
]
end
includes
<<
m
[
1
]
unless
m
.
nil?
end
return
includes
includes
end
def
find_source_file
(
header
,
paths
)
paths
.
each
do
|
dir
|
src_file
=
dir
+
header
.
ext
(
C_EXTENSION
)
if
(
File
.
exists?
(
src_file
))
return
src_file
end
return
src_file
if
File
.
exist?
(
src_file
)
end
return
nil
nil
end
def
tackit
(
strings
)
if
strings
.
is_a?
(
Array
)
result
=
"
\"
#{
strings
.
join
}
\"
"
else
result
=
strings
end
re
turn
re
sult
result
=
if
strings
.
is_a?
(
Array
)
"
\"
#{
strings
.
join
}
\"
"
else
strings
end
result
end
def
squash
(
prefix
,
items
)
result
=
''
items
.
each
{
|
item
|
result
+=
"
#{
prefix
}#{
tackit
(
item
)
}
"
}
re
turn
re
sult
result
end
def
should
(
behave
,
&
block
)
if
block
puts
"Should "
+
behave
puts
'Should '
+
behave
yield
block
else
puts
"UNIMPLEMENTED CASE: Should
#{
behave
}
"
...
...
@@ -93,91 +87,91 @@ module RakefileHelpers
end
def
build_compiler_fields
(
inject_defines
)
command
=
tackit
(
$cfg
[
'compiler'
][
'path'
])
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
defines
=
''
else
defines
=
squash
(
$cfg
[
'compiler'
][
'defines'
][
'prefix'
],
$cfg
[
'compiler'
][
'defines'
][
'items'
]
+
[
'UNITY_OUTPUT_CHAR=putcharSpy'
]
+
inject_defines
)
end
options
=
squash
(
''
,
$cfg
[
'compiler'
][
'options'
])
command
=
tackit
(
$cfg
[
'compiler'
][
'path'
])
defines
=
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
''
else
squash
(
$cfg
[
'compiler'
][
'defines'
][
'prefix'
],
$cfg
[
'compiler'
][
'defines'
][
'items'
]
+
[
'UNITY_OUTPUT_CHAR=putcharSpy'
]
+
inject_defines
)
end
options
=
squash
(
''
,
$cfg
[
'compiler'
][
'options'
])
includes
=
squash
(
$cfg
[
'compiler'
][
'includes'
][
'prefix'
],
$cfg
[
'compiler'
][
'includes'
][
'items'
])
includes
=
includes
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
return
{
:command
=>
command
,
:defines
=>
defines
,
:options
=>
options
,
:includes
=>
includes
}
{
:command
=>
command
,
:defines
=>
defines
,
:options
=>
options
,
:includes
=>
includes
}
end
def
compile
(
file
,
defines
=
[])
def
compile
(
file
,
defines
=
[])
compiler
=
build_compiler_fields
(
defines
)
defines
=
cmd_str
=
"
#{
compiler
[
:command
]
}#{
compiler
[
:defines
]
}#{
compiler
[
:options
]
}#{
compiler
[
:includes
]
}
#{
file
}
"
+
cmd_str
=
"
#{
compiler
[
:command
]
}#{
compiler
[
:defines
]
}#{
compiler
[
:options
]
}#{
compiler
[
:includes
]
}
#{
file
}
"
\
"
#{
$cfg
[
'compiler'
][
'object_files'
][
'prefix'
]
}#{
$cfg
[
'compiler'
][
'object_files'
][
'destination'
]
}
"
obj_file
=
"
#{
File
.
basename
(
file
,
C_EXTENSION
)
}#{
$cfg
[
'compiler'
][
'object_files'
][
'extension'
]
}
"
execute
(
cmd_str
+
obj_file
)
return
obj_file
obj_file
end
def
build_linker_fields
command
=
tackit
(
$cfg
[
'linker'
][
'path'
])
if
$cfg
[
'linker'
][
'options'
].
nil?
options
=
''
else
options
=
squash
(
''
,
$cfg
[
'linker'
][
'options'
])
end
i
f
(
$cfg
[
'linker'
][
'includes'
].
nil?
||
$cfg
[
'linker'
][
'includes'
][
'items'
].
nil?
)
includes
=
''
else
includes
=
squash
(
$cfg
[
'linker'
][
'includes'
][
'prefix'
],
$cfg
[
'linker'
][
'includes'
][
'items'
])
end
includes
=
includes
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
return
{
:command
=>
command
,
:options
=>
options
,
:includes
=>
includes
}
command
=
tackit
(
$cfg
[
'linker'
][
'path'
])
options
=
if
$cfg
[
'linker'
][
'options'
].
nil?
''
else
squash
(
''
,
$cfg
[
'linker'
][
'options'
])
end
i
ncludes
=
if
$cfg
[
'linker'
][
'includes'
].
nil?
||
$cfg
[
'linker'
][
'includes'
][
'items'
].
nil?
''
else
squash
(
$cfg
[
'linker'
][
'includes'
][
'prefix'
],
$cfg
[
'linker'
][
'includes'
][
'items'
])
end
.
gsub
(
/\\ /
,
' '
).
gsub
(
/\\\"/
,
'"'
).
gsub
(
/\\$/
,
''
)
# Remove trailing slashes (for IAR)
{
:command
=>
command
,
:options
=>
options
,
:includes
=>
includes
}
end
def
link_it
(
exe_name
,
obj_list
)
linker
=
build_linker_fields
cmd_str
=
"
#{
linker
[
:command
]
}#{
linker
[
:options
]
}#{
linker
[
:includes
]
}
"
+
(
obj_list
.
map
{
|
obj
|
"
#{
$cfg
[
'linker'
][
'object_files'
][
'path'
]
}#{
obj
}
"
}).
join
+
$cfg
[
'linker'
][
'bin_files'
][
'prefix'
]
+
' '
+
$cfg
[
'linker'
][
'bin_files'
][
'destination'
]
+
exe_name
+
$cfg
[
'linker'
][
'bin_files'
][
'extension'
]
(
obj_list
.
map
{
|
obj
|
"
#{
$cfg
[
'linker'
][
'object_files'
][
'path'
]
}#{
obj
}
"
}).
join
+
$cfg
[
'linker'
][
'bin_files'
][
'prefix'
]
+
' '
+
$cfg
[
'linker'
][
'bin_files'
][
'destination'
]
+
exe_name
+
$cfg
[
'linker'
][
'bin_files'
][
'extension'
]
execute
(
cmd_str
)
end
def
build_simulator_fields
return
nil
if
$cfg
[
'simulator'
].
nil?
if
$cfg
[
'simulator'
][
'path'
].
nil?
command
=
''
else
command
=
(
tackit
(
$cfg
[
'simulator'
][
'path'
])
+
' '
)
end
if
$cfg
[
'simulator'
][
'pre_support'
].
nil?
pre_support
=
''
else
pre_support
=
squash
(
''
,
$cfg
[
'simulator'
][
'pre_support'
])
end
if
$cfg
[
'simulator'
][
'post_support'
].
nil?
post_support
=
''
else
post_support
=
squash
(
''
,
$cfg
[
'simulator'
][
'post_support'
])
end
return
{
:command
=>
command
,
:pre_support
=>
pre_support
,
:post_support
=>
post_support
}
end
def
execute
(
command_string
,
ok_to_fail
=
false
)
command
=
if
$cfg
[
'simulator'
][
'path'
].
nil?
''
else
(
tackit
(
$cfg
[
'simulator'
][
'path'
])
+
' '
)
end
pre_support
=
if
$cfg
[
'simulator'
][
'pre_support'
].
nil?
''
else
squash
(
''
,
$cfg
[
'simulator'
][
'pre_support'
])
end
post_support
=
if
$cfg
[
'simulator'
][
'post_support'
].
nil?
''
else
squash
(
''
,
$cfg
[
'simulator'
][
'post_support'
])
end
{
:command
=>
command
,
:pre_support
=>
pre_support
,
:post_support
=>
post_support
}
end
def
execute
(
command_string
,
ok_to_fail
=
false
)
report
command_string
if
$verbose
output
=
`
#{
command_string
}
`
.
chomp
report
(
output
)
if
(
$verbose
&&
!
output
.
nil?
&&
(
output
.
length
>
0
))
if
((
$?
.
exitstatus
!=
0
)
&&
!
ok_to_fail
)
raise
"Command failed. (Returned
#{
$?
.
exitstatus
}
)"
end
return
output
report
(
output
)
if
$verbose
&&
!
output
.
nil?
&&
!
output
.
empty?
raise
"Command failed. (Returned
#{
$?
.
exitstatus
}
)"
if
!
$?
.
exitstatus
.
zero?
&&
!
ok_to_fail
output
end
def
report_summary
summary
=
UnityTestSummary
.
new
summary
.
set_root_path
(
UNITY_ROOT
)
summary
.
root
=
UNITY_ROOT
results_glob
=
"
#{
$cfg
[
'compiler'
][
'build_path'
]
}
*.test*"
results_glob
.
gsub!
(
/\\/
,
'/'
)
results_glob
.
tr!
(
'\\'
,
'/'
)
results
=
Dir
[
results_glob
]
summary
.
set_targets
(
results
)
summary
.
targets
=
results
report
summary
.
run
end
...
...
@@ -187,16 +181,16 @@ module RakefileHelpers
# Tack on TEST define for compiling unit tests
load_configuration
(
$cfg_file
)
test_defines
=
[
'TEST'
]
$cfg
[
'compiler'
][
'defines'
][
'items'
]
=
[]
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
$cfg
[
'compiler'
][
'defines'
][
'items'
]
||=
[]
$cfg
[
'compiler'
][
'defines'
][
'items'
]
<<
'TEST'
include_dirs
=
get_
local_include_dirs
include_dirs
=
local_include_dirs
# Build and execute each unit test
test_files
.
each
do
|
test
|
obj_list
=
[]
if
!
$cfg
[
'compiler'
][
'aux_sources'
].
nil?
unless
$cfg
[
'compiler'
][
'aux_sources'
].
nil?
$cfg
[
'compiler'
][
'aux_sources'
].
each
do
|
aux
|
obj_list
<<
compile
(
aux
,
test_defines
)
end
...
...
@@ -206,25 +200,23 @@ module RakefileHelpers
extract_headers
(
test
).
each
do
|
header
|
# Compile corresponding source file if it exists
src_file
=
find_source_file
(
header
,
include_dirs
)
if
!
src_file
.
nil?
obj_list
<<
compile
(
src_file
,
test_defines
)
end
obj_list
<<
compile
(
src_file
,
test_defines
)
unless
src_file
.
nil?
end
# Build the test runner (generate if configured to do so)
test_base
=
File
.
basename
(
test
,
C_EXTENSION
)
runner_name
=
test_base
+
'_Runner.c'
runner_path
=
''
if
$cfg
[
'compiler'
][
'runner_path'
].
nil?
runner_path
=
$cfg
[
'compiler'
][
'build_path'
]
+
runner_name
else
runner_path
=
$cfg
[
'compiler'
][
'runner_path'
]
+
runner_name
end
runner_path
=
if
$cfg
[
'compiler'
][
'runner_path'
].
nil?
$cfg
[
'compiler'
][
'build_path'
]
+
runner_name
else
$cfg
[
'compiler'
][
'runner_path'
]
+
runner_name
end
options
=
$cfg
[
:unity
]
options
[
:use_param_tests
]
=
(
test
=~
/parameterized/
)
?
true
:
false
options
[
:use_param_tests
]
=
test
=~
/parameterized/
?
true
:
false
UnityTestRunnerGenerator
.
new
(
options
).
run
(
test
,
runner_path
)
obj_list
<<
compile
(
runner_path
,
test_defines
)
...
...
@@ -237,21 +229,20 @@ module RakefileHelpers
# Execute unit test and generate results file
simulator
=
build_simulator_fields
executable
=
$cfg
[
'linker'
][
'bin_files'
][
'destination'
]
+
test_base
+
$cfg
[
'linker'
][
'bin_files'
][
'extension'
]
if
simulator
.
nil?
cmd_str
=
executable
else
cmd_str
=
"
#{
simulator
[
:command
]
}
#{
simulator
[
:pre_support
]
}
#{
executable
}
#{
simulator
[
:post_support
]
}
"
end
cmd_str
=
if
simulator
.
nil?
executable
else
"
#{
simulator
[
:command
]
}
#{
simulator
[
:pre_support
]
}
#{
executable
}
#{
simulator
[
:post_support
]
}
"
end
output
=
execute
(
cmd_str
)
test_results
=
$cfg
[
'compiler'
][
'build_path'
]
+
test_base
if
output
.
match
(
/OK$/m
).
nil?
test_results
+=
'.testfail'
else
report
output
if
(
!
$verbose
)
#v
erbose already prints this line, as does a failure
report
output
unless
$verbose
# V
erbose already prints this line, as does a failure
test_results
+=
'.testpass'
end
File
.
open
(
test_results
,
'w'
)
{
|
f
|
f
.
print
output
}
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录