Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
e9f96384
T
Third Party Unity
项目概览
OpenHarmony
/
Third Party Unity
大约 1 年 前同步成功
通知
34
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e9f96384
编写于
5月 04, 2019
作者:
M
Mark VanderVoord
提交者:
GitHub
5月 04, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' into issue-#346-documentation-improvement
上级
ea5e51ff
071044bd
变更
33
展开全部
隐藏空白更改
内联
并排
Showing
33 changed file
with
3801 addition
and
584 deletion
+3801
-584
.travis.yml
.travis.yml
+1
-1
CMakeLists.txt
CMakeLists.txt
+70
-0
LICENSE.txt
LICENSE.txt
+0
-0
README.md
README.md
+8
-8
auto/colour_prompt.rb
auto/colour_prompt.rb
+2
-2
auto/colour_reporter.rb
auto/colour_reporter.rb
+1
-1
auto/generate_module.rb
auto/generate_module.rb
+6
-8
auto/generate_test_runner.rb
auto/generate_test_runner.rb
+26
-11
auto/parse_output.rb
auto/parse_output.rb
+28
-29
auto/stylize_as_junit.rb
auto/stylize_as_junit.rb
+4
-8
auto/test_file_filter.rb
auto/test_file_filter.rb
+2
-2
auto/unity_test_summary.py
auto/unity_test_summary.py
+1
-1
auto/unity_test_summary.rb
auto/unity_test_summary.rb
+0
-4
docs/UnityAssertionsReference.md
docs/UnityAssertionsReference.md
+36
-1
docs/UnityConfigurationGuide.md
docs/UnityConfigurationGuide.md
+138
-51
examples/example_1/src/ProductionCode.c
examples/example_1/src/ProductionCode.c
+4
-4
examples/example_1/test/TestProductionCode.c
examples/example_1/test/TestProductionCode.c
+6
-6
examples/example_2/test/TestProductionCode.c
examples/example_2/test/TestProductionCode.c
+1
-1
examples/example_3/rakefile.rb
examples/example_3/rakefile.rb
+4
-7
examples/example_3/rakefile_helper.rb
examples/example_3/rakefile_helper.rb
+4
-4
examples/example_3/target_gcc_32.yml
examples/example_3/target_gcc_32.yml
+4
-3
examples/unity_config.h
examples/unity_config.h
+16
-0
extras/fixture/rakefile.rb
extras/fixture/rakefile.rb
+6
-8
extras/fixture/rakefile_helper.rb
extras/fixture/rakefile_helper.rb
+8
-8
extras/fixture/src/unity_fixture.c
extras/fixture/src/unity_fixture.c
+2
-1
src/unity.c
src/unity.c
+511
-98
src/unity.h
src/unity.h
+37
-1
src/unity_internals.h
src/unity_internals.h
+125
-59
test/.rubocop.yml
test/.rubocop.yml
+1
-1
test/rakefile
test/rakefile
+3
-4
test/rakefile_helper.rb
test/rakefile_helper.rb
+4
-4
test/tests/testparameterized.c
test/tests/testparameterized.c
+61
-0
test/tests/testunity.c
test/tests/testunity.c
+2681
-248
未找到文件。
.travis.yml
浏览文件 @
e9f96384
...
...
@@ -10,7 +10,7 @@ matrix:
compiler
:
gcc
before_install
:
-
if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.
1 && rvm use 2.1
&& ruby -v; fi
-
if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.
3 && rvm use 2.3
&& ruby -v; fi
-
if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi
install
:
-
gem install rspec
...
...
CMakeLists.txt
0 → 100644
浏览文件 @
e9f96384
#####################################################
# FILE NAME CMakeLists.txt #
# #
# WRITTEN BY Michael Brockus. #
# #
# PURPOSE contains CMake statements. #
# #
#####################################################
cmake_minimum_required
(
VERSION 3.13.2.0 FATAL_ERROR
)
#
# CMake: Declare project
#
project
(
unity LANGUAGES C DESCRIPTION
"C Unit testing framework."
)
#
# CMake: Creation of library
#
add_library
(
"unity"
STATIC
)
#
# CMake: Adding source to target
#
target_sources
(
"unity"
PRIVATE
"src/unity.c"
)
#
# CMake: Including directories to target
#
target_include_directories
(
"unity"
PUBLIC
"$<BUILD_INTERFACE:
${
CMAKE_CURRENT_SOURCE_DIR
}
/src>"
"$<INSTALL_INTERFACE:src>"
PRIVATE
"src"
)
#
# CMake: Give target an alias
#
add_library
(
"unity::framework"
ALIAS
"unity"
)
#
# CMake: export project
#
install
(
TARGETS
"unity"
EXPORT
"unityConfig"
ARCHIVE DESTINATION
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
CMAKE_INSTALL_LIBDIR
}
"
LIBRARY DESTINATION
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
CMAKE_INSTALL_LIBDIR
}
"
RUNTIME DESTINATION
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
CMAKE_INSTALL_BINDIR
}
"
INCLUDES DESTINATION
"
${
CMAKE_INSTALL_LIBDIR
}
"
)
install
(
DIRECTORY src/ DESTINATION src
)
install
(
EXPORT unityConfig DESTINATION share/unityConfig/cmake
)
# This makes the project importable from the build directory
export
(
TARGETS unity FILE unityConfig.cmake
)
docs/license
.txt
→
LICENSE
.txt
浏览文件 @
e9f96384
文件已移动
README.md
浏览文件 @
e9f96384
...
...
@@ -2,7 +2,7 @@ Unity Test API
==============
[
![Unity Build Status
](
https://api.travis-ci.org/ThrowTheSwitch/Unity.png?branch=master
)
](https://travis-ci.org/ThrowTheSwitch/Unity)
__Copyright (c) 2007 - 201
7
Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams__
__Copyright (c) 2007 - 201
9
Unity Project by Mike Karlesky, Mark VanderVoord, and Greg Williams__
Getting Started
===============
...
...
@@ -35,7 +35,7 @@ Another way of calling `TEST_ASSERT_FALSE`
TEST_FAIL()
TEST_FAIL_MESSAGE(message)
This test is automatically marked as a failure.
The message is output stating why.
This test is automatically marked as a failure. The message is output stating why.
Numerical Assertions: Integers
------------------------------
...
...
@@ -47,7 +47,7 @@ Numerical Assertions: Integers
TEST_ASSERT_EQUAL_INT64(expected, actual)
Compare two integers for equality and display errors as signed integers. A cast will be performed
to your natural integer size so often this can just be used.
When you need to specify the exact size,
to your natural integer size so often this can just be used. When you need to specify the exact size,
like when comparing arrays, you can use a specific version:
TEST_ASSERT_EQUAL_UINT(expected, actual)
...
...
@@ -56,7 +56,7 @@ like when comparing arrays, you can use a specific version:
TEST_ASSERT_EQUAL_UINT32(expected, actual)
TEST_ASSERT_EQUAL_UINT64(expected, actual)
Compare two integers for equality and display errors as unsigned integers.
Like INT, there are
Compare two integers for equality and display errors as unsigned integers. Like INT, there are
variants for different sizes also.
TEST_ASSERT_EQUAL_HEX(expected, actual)
...
...
@@ -65,7 +65,7 @@ variants for different sizes also.
TEST_ASSERT_EQUAL_HEX32(expected, actual)
TEST_ASSERT_EQUAL_HEX64(expected, actual)
Compares two integers for equality and display errors as hexadecimal.
Like the other integer comparisons,
Compares two integers for equality and display errors as hexadecimal. Like the other integer comparisons,
you can specify the size... here the size will also effect how many nibbles are shown (for example,
`HEX16`
will show 4 nibbles).
...
...
@@ -75,7 +75,7 @@ Another way of calling TEST_ASSERT_EQUAL_INT
TEST_ASSERT_INT_WITHIN(delta, expected, actual)
Asserts that the actual value is within plus or minus delta of the expected value.
This also comes in
Asserts that the actual value is within plus or minus delta of the expected value. This also comes in
size specific variants.
...
...
@@ -159,12 +159,12 @@ Compare two null-terminate strings. Fail if any character is different or if th
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message)
Compare two strings.
Fail if any character is different, stop comparing after len characters. Output a custom message on failure.
Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure.
Pointer Assertions
------------------
Most pointer operations can be performed by simply using the integer comparisons above.
However, a couple of special cases are added for clarity.
Most pointer operations can be performed by simply using the integer comparisons above. However, a couple of special cases are added for clarity.
TEST_ASSERT_NULL(pointer)
...
...
auto/colour_prompt.rb
浏览文件 @
e9f96384
...
...
@@ -24,7 +24,7 @@ class ColourCommandLine
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'
)
Win32API
.
new
(
'kernel32'
,
'SetConsoleTextAttribute'
,
%w
[L N]
,
'I'
)
@hout
=
get_std_handle
.
call
(
-
11
)
end
...
...
@@ -107,7 +107,7 @@ class ColourCommandLine
$stdout
.
print
(
"
#{
change_to
(
colour
)
}#{
str
}
\033
[0m"
)
if
mode
==
:print
end
end
end
# ColourCommandLine
end
def
colour_puts
(
role
,
str
)
ColourCommandLine
.
new
.
out_c
(
:puts
,
role
,
str
)
...
...
auto/colour_reporter.rb
浏览文件 @
e9f96384
...
...
@@ -4,7 +4,7 @@
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
require
"
#{
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
}
/colour_prompt"
require
_relative
'colour_prompt'
$colour_output
=
true
...
...
auto/generate_module.rb
浏览文件 @
e9f96384
...
...
@@ -35,18 +35,16 @@ TEMPLATE_SRC ||= '%2$s#include "%1$s.h"
'
.
freeze
# TEMPLATE_INC
TEMPLATE_INC
||=
'#ifndef
_
%3$s_H
#define
_
%3$s_H
TEMPLATE_INC
||=
'#ifndef %3$s_H
#define %3$s_H
%2$s
#endif //
_
%3$s_H
#endif // %3$s_H
'
.
freeze
class
UnityModuleGenerator
############################
def
initialize
(
options
=
nil
)
here
=
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
+
'/'
@options
=
UnityModuleGenerator
.
default_options
case
options
when
NilClass
then
@options
...
...
@@ -56,9 +54,9 @@ class UnityModuleGenerator
end
# Create default file paths if none were provided
@options
[
:path_src
]
=
here
+
'../src/'
if
@options
[
:path_src
].
nil?
@options
[
:path_inc
]
=
@options
[
:path_src
]
if
@options
[
:path_inc
].
nil?
@options
[
:path_tst
]
=
here
+
'../test/'
if
@options
[
:path_tst
].
nil?
@options
[
:path_src
]
=
"
#{
__dir__
}
/../src/"
if
@options
[
:path_src
].
nil?
@options
[
:path_inc
]
=
@options
[
:path_src
]
if
@options
[
:path_inc
].
nil?
@options
[
:path_tst
]
=
"
#{
__dir__
}
/../test/"
if
@options
[
:path_tst
].
nil?
@options
[
:path_src
]
+=
'/'
unless
@options
[
:path_src
][
-
1
]
==
47
@options
[
:path_inc
]
+=
'/'
unless
@options
[
:path_inc
][
-
1
]
==
47
@options
[
:path_tst
]
+=
'/'
unless
@options
[
:path_tst
][
-
1
]
==
47
...
...
auto/generate_test_runner.rb
浏览文件 @
e9f96384
...
...
@@ -4,8 +4,6 @@
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
'colour_prompt'
))
class
UnityTestRunnerGenerator
def
initialize
(
options
=
nil
)
@options
=
UnityTestRunnerGenerator
.
default_options
...
...
@@ -15,7 +13,7 @@ class UnityTestRunnerGenerator
when
Hash
then
@options
.
merge!
(
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"
require
_relative
'type_sanitizer'
end
def
self
.
default_options
...
...
@@ -29,6 +27,7 @@ class UnityTestRunnerGenerator
mock_suffix:
''
,
setup_name:
'setUp'
,
teardown_name:
'tearDown'
,
test_reset_name:
'resetTest'
,
main_name:
'main'
,
# set to :auto to automatically generate each time
main_export_decl:
''
,
cmdline_args:
false
,
...
...
@@ -92,16 +91,29 @@ class UnityTestRunnerGenerator
def
find_tests
(
source
)
tests_and_line_numbers
=
[]
# contains characters which will be substituted from within strings, doing
# this prevents these characters from interferring with scrubbers
# @ is not a valid C character, so there should be no clashes with files genuinely containing these markers
substring_subs
=
{
'{'
=>
'@co@'
,
'}'
=>
'@cc@'
,
';'
=>
'@ss@'
,
'/'
=>
'@fs@'
}
substring_re
=
Regexp
.
union
(
substring_subs
.
keys
)
substring_unsubs
=
substring_subs
.
invert
# the inverse map will be used to fix the strings afterwords
substring_unsubs
[
'@quote@'
]
=
'\\"'
substring_unsubs
[
'@apos@'
]
=
'\\\''
substring_unre
=
Regexp
.
union
(
substring_unsubs
.
keys
)
source_scrubbed
=
source
.
clone
source_scrubbed
=
source_scrubbed
.
gsub
(
/"[^"\n]*"/
,
''
)
# remove things in strings
source_scrubbed
=
source_scrubbed
.
gsub
(
/\\"/
,
'@quote@'
)
# hide escaped quotes to allow capture of the full string/char
source_scrubbed
=
source_scrubbed
.
gsub
(
/\\'/
,
'@apos@'
)
# hide escaped apostrophes to allow capture of the full string/char
source_scrubbed
=
source_scrubbed
.
gsub
(
/("[^"\n]*")|('[^'\n]*')/
)
{
|
s
|
s
.
gsub
(
substring_re
,
substring_subs
)
}
# temporarily hide problematic
# characters within strings
source_scrubbed
=
source_scrubbed
.
gsub
(
/\/\/.*$/
,
''
)
# remove line comments
source_scrubbed
=
source_scrubbed
.
gsub
(
/\/\*.*?\*\//m
,
''
)
# remove block comments
lines
=
source_scrubbed
.
split
(
/(^\s*\#.*$) # Treat preprocessor directives as a logical line
| (;|\{|\}) /x
)
# Match ;, {, and } as end of lines
.
map
{
|
line
|
line
.
gsub
(
substring_unre
,
substring_unsubs
)
}
# unhide the problematic characters previously removed
lines
.
each_with_index
do
|
line
,
_index
|
# find tests
next
unless
line
=~
/^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+((?:
#{
@options
[
:test_prefix
]
}
).*)\s*\(\s*(.*)\s*\)/
next
unless
line
=~
/^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+((?:
#{
@options
[
:test_prefix
]
}
).*)\s*\(\s*(.*)\s*\)/
m
arguments
=
Regexp
.
last_match
(
1
)
name
=
Regexp
.
last_match
(
2
)
call
=
Regexp
.
last_match
(
3
)
...
...
@@ -165,10 +177,10 @@ class UnityTestRunnerGenerator
output
.
puts
(
'#include "cmock.h"'
)
unless
mocks
.
empty?
output
.
puts
(
'#ifndef UNITY_EXCLUDE_SETJMP_H'
)
output
.
puts
(
'#include <setjmp.h>'
)
output
.
puts
(
"#endif"
)
output
.
puts
(
'#endif'
)
output
.
puts
(
'#include <stdio.h>'
)
if
@options
[
:defines
]
&&
!
@options
[
:defines
].
empty?
@options
[
:defines
].
each
{
|
d
|
output
.
puts
(
"#
define
#{
d
}
"
)
}
@options
[
:defines
].
each
{
|
d
|
output
.
puts
(
"#
ifndef
#{
d
}
\n
#define
#{
d
}
\n
#endif /*
#{
d
}
*/
"
)
}
end
if
@options
[
:header_file
]
&&
!
@options
[
:header_file
].
empty?
output
.
puts
(
"#include
\"
#{
File
.
basename
(
@options
[
:header_file
])
}
\"
"
)
...
...
@@ -288,6 +300,7 @@ class UnityTestRunnerGenerator
output
.
puts
(
' Unity.CurrentTestLineNumber = TestLineNum; \\'
)
output
.
puts
(
' if (UnityTestMatches()) { \\'
)
if
@options
[
:cmdline_args
]
output
.
puts
(
' Unity.NumberOfTests++; \\'
)
output
.
puts
(
' UNITY_EXEC_TIME_START(); \\'
)
output
.
puts
(
' CMock_Init(); \\'
)
unless
used_mocks
.
empty?
output
.
puts
(
' UNITY_CLR_DETAILS(); \\'
)
unless
used_mocks
.
empty?
output
.
puts
(
' if (TEST_PROTECT()) \\'
)
...
...
@@ -304,6 +317,7 @@ class UnityTestRunnerGenerator
output
.
puts
(
' CMock_Verify(); \\'
)
unless
used_mocks
.
empty?
output
.
puts
(
' } \\'
)
output
.
puts
(
' CMock_Destroy(); \\'
)
unless
used_mocks
.
empty?
output
.
puts
(
' UNITY_EXEC_TIME_STOP(); \\'
)
output
.
puts
(
' UnityConcludeTest(); \\'
)
output
.
puts
(
' } \\'
)
if
@options
[
:cmdline_args
]
output
.
puts
(
"}
\n
"
)
...
...
@@ -311,8 +325,8 @@ class UnityTestRunnerGenerator
def
create_reset
(
output
,
used_mocks
)
output
.
puts
(
"
\n
/*=======Test Reset Option=====*/"
)
output
.
puts
(
'void resetTest(void);'
)
output
.
puts
(
'void resetTest(void)'
)
output
.
puts
(
"void
#{
@options
[
:test_reset_name
]
}
(void);"
)
output
.
puts
(
"void
#{
@options
[
:test_reset_name
]
}
(void)"
)
output
.
puts
(
'{'
)
output
.
puts
(
' CMock_Verify();'
)
unless
used_mocks
.
empty?
output
.
puts
(
' CMock_Destroy();'
)
unless
used_mocks
.
empty?
...
...
@@ -379,7 +393,7 @@ class UnityTestRunnerGenerator
end
output
.
puts
output
.
puts
(
' CMock_Guts_MemFreeFinal();'
)
unless
used_mocks
.
empty?
output
.
puts
(
" return suite_teardown(UnityEnd());"
)
output
.
puts
(
' return suite_teardown(UnityEnd());'
)
output
.
puts
(
'}'
)
end
...
...
@@ -446,6 +460,7 @@ if $0 == __FILE__
' --teardown_name="" - redefine tearDown func name to something else'
,
' --main_name="" - redefine main func name to something else'
,
' --test_prefix="" - redefine test prefix from default test|spec|should'
,
' --test_reset_name="" - redefine resetTest func name to something else'
,
' --suite_setup="" - code to execute for setup of entire suite'
,
' --suite_teardown="" - code to execute for teardown of entire suite'
,
' --use_param_tests=1 - enable parameterized tests (disabled by default)'
,
...
...
@@ -457,4 +472,4 @@ if $0 == __FILE__
ARGV
[
1
]
=
ARGV
[
0
].
gsub
(
'.c'
,
'_Runner.c'
)
unless
ARGV
[
1
]
UnityTestRunnerGenerator
.
new
(
options
).
run
(
ARGV
[
0
],
ARGV
[
1
])
end
end
\ No newline at end of file
auto/parse_output.rb
浏览文件 @
e9f96384
...
...
@@ -210,7 +210,7 @@ class ParseOutput
# Adjusts the os specific members according to the current path style
# (Windows or Unix based)
def
se
t_os_specifics
(
line
)
def
detec
t_os_specifics
(
line
)
if
line
.
include?
'\\'
# Windows X:\Y\Z
@class_name_idx
=
1
...
...
@@ -254,43 +254,42 @@ class ParseOutput
# TEST(<test_group, <test_file>) PASS
#
# Note: Where path is different on Unix vs Windows devices (Windows leads with a drive letter)!
se
t_os_specifics
(
line
)
detec
t_os_specifics
(
line
)
line_array
=
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_array
.
size
>=
4
)
||
(
line
.
start_with?
'TEST('
)
||
(
line
.
start_with?
'IGNORE_TEST('
)
# check if the output is fixture output (with verbose flag "-v")
if
(
line
.
start_with?
'TEST('
)
||
(
line
.
start_with?
'IGNORE_TEST('
)
line_array
=
prepare_fixture_line
(
line
)
if
line
.
include?
' PASS'
test_passed_unity_fixture
(
line_array
)
@test_passed
+=
1
elsif
line
.
include?
'FAIL'
test_failed_unity_fixture
(
line_array
)
@test_failed
+=
1
elsif
line
.
include?
'IGNORE'
test_ignored_unity_fixture
(
line_array
)
@test_ignored
+=
1
end
# normal output / fixture output (without verbose "-v")
elsif
line
.
include?
':PASS'
test_passed
(
line_array
)
next
unless
(
line_array
.
size
>=
4
)
||
(
line
.
start_with?
'TEST('
)
||
(
line
.
start_with?
'IGNORE_TEST('
)
# check if the output is fixture output (with verbose flag "-v")
if
(
line
.
start_with?
'TEST('
)
||
(
line
.
start_with?
'IGNORE_TEST('
)
line_array
=
prepare_fixture_line
(
line
)
if
line
.
include?
' PASS'
test_passed_unity_fixture
(
line_array
)
@test_passed
+=
1
elsif
line
.
include?
'
:
FAIL'
test_failed
(
line_array
)
elsif
line
.
include?
'FAIL'
test_failed
_unity_fixture
(
line_array
)
@test_failed
+=
1
elsif
line
.
include?
':IGNORE:'
test_ignored
(
line_array
)
@test_ignored
+=
1
elsif
line
.
include?
':IGNORE'
line_array
.
push
(
'No reason given'
)
test_ignored
(
line_array
)
elsif
line
.
include?
'IGNORE'
test_ignored_unity_fixture
(
line_array
)
@test_ignored
+=
1
end
@total_tests
=
@test_passed
+
@test_failed
+
@test_ignored
# normal output / fixture output (without verbose "-v")
elsif
line
.
include?
':PASS'
test_passed
(
line_array
)
@test_passed
+=
1
elsif
line
.
include?
':FAIL'
test_failed
(
line_array
)
@test_failed
+=
1
elsif
line
.
include?
':IGNORE:'
test_ignored
(
line_array
)
@test_ignored
+=
1
elsif
line
.
include?
':IGNORE'
line_array
.
push
(
'No reason given'
)
test_ignored
(
line_array
)
@test_ignored
+=
1
end
@total_tests
=
@test_passed
+
@test_failed
+
@test_ignored
end
puts
''
puts
'=================== SUMMARY ====================='
...
...
auto/stylize_as_junit.rb
浏览文件 @
e9f96384
...
...
@@ -61,8 +61,8 @@ class ArgvParser
opts
.
parse!
(
args
)
options
end
# parse()
end
# class OptparseExample
end
end
class
UnityToJUnit
include
FileUtils
::
Verbose
...
...
@@ -155,10 +155,6 @@ class UnityToJUnit
[
Regexp
.
last_match
(
1
).
to_i
,
Regexp
.
last_match
(
2
).
to_i
,
Regexp
.
last_match
(
3
).
to_i
]
end
def
here
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
end
private
def
results_structure
...
...
@@ -221,9 +217,9 @@ class UnityToJUnit
def
write_suites_footer
(
stream
)
stream
.
puts
'</testsuites>'
end
end
# UnityToJUnit
end
if
__FILE__
==
$0
if
$0
==
__FILE__
# parse out the command options
options
=
ArgvParser
.
parse
(
ARGV
)
...
...
auto/test_file_filter.rb
浏览文件 @
e9f96384
...
...
@@ -11,8 +11,8 @@ module RakefileHelpers
def
initialize
(
all_files
=
false
)
@all_files
=
all_files
return
false
unless
@all_files
return
false
unless
File
.
exist?
(
'test_file_filter.yml'
)
return
unless
@all_files
return
unless
File
.
exist?
(
'test_file_filter.yml'
)
filters
=
YAML
.
load_file
(
'test_file_filter.yml'
)
@all_files
=
filters
[
:all_files
]
...
...
auto/unity_test_summary.py
浏览文件 @
e9f96384
...
...
@@ -121,7 +121,7 @@ if __name__ == '__main__':
targets_dir
=
sys
.
argv
[
1
]
else
:
targets_dir
=
'./'
targets
=
list
(
map
(
lambda
x
:
x
.
replace
(
'
\\
'
,
'/'
),
glob
(
targets_dir
+
'*
.test*'
)))
targets
=
list
(
map
(
lambda
x
:
x
.
replace
(
'
\\
'
,
'/'
),
glob
(
targets_dir
+
'*
*/*.test*'
,
recursive
=
True
)))
if
len
(
targets
)
==
0
:
raise
Exception
(
"No *.testpass or *.testfail files found in '%s'"
%
targets_dir
)
uts
.
set_targets
(
targets
)
...
...
auto/unity_test_summary.rb
浏览文件 @
e9f96384
...
...
@@ -101,10 +101,6 @@ class UnityTestSummary
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
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
end
end
if
$0
==
__FILE__
...
...
docs/UnityAssertionsReference.md
浏览文件 @
e9f96384
...
...
@@ -391,7 +391,6 @@ of 7 - 13.
##### `TEST_ASSERT_HEX64_WITHIN (delta, expected, actual)`
### Structs and Strings
##### `TEST_ASSERT_EQUAL_PTR (expected, actual)`
...
...
@@ -466,6 +465,42 @@ match. Failure messages specify the array index of the failed comparison.
`len`
is the memory in bytes to be compared at each array element.
### Integer Array Ranges (of all sizes)
These assertions verify that the
`expected`
array parameter is within +/-
`delta`
(inclusive) of the
`actual`
array parameter. For example, if the expected value is
\[
10, 12
\]
and the delta is 3 then the assertion will fail for any value
outside the range of
\[
7 - 13, 9 - 15
\]
.
##### `TEST_ASSERT_INT_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_INT8_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_INT16_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_INT32_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_INT64_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_UINT_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_UINT8_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_UINT16_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_UINT32_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_UINT64_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_HEX_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_HEX8_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_HEX16_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_HEX32_ARRAY_WITHIN (delta, expected, actual)`
##### `TEST_ASSERT_HEX64_ARRAY_WITHIN (delta, expected, actual)`
### Each Equal (Arrays to Single Value)
...
...
docs/UnityConfigurationGuide.md
浏览文件 @
e9f96384
...
...
@@ -66,7 +66,9 @@ That way, Unity will know to skip the inclusion of this file and you won't
be left with a compiler error.
_Example:_
#define UNITY_EXCLUDE_STDINT_H
```
C
#define UNITY_EXCLUDE_STDINT_H
```
##### `UNITY_EXCLUDE_LIMITS_H`
...
...
@@ -76,8 +78,9 @@ that don't support `stdint.h` could include `limits.h` instead. If you don't
want Unity to check this file either, define this to make it skip the inclusion.
_Example:_
#define UNITY_EXCLUDE_LIMITS_H
```
C
#define UNITY_EXCLUDE_LIMITS_H
```
If you've disabled both of the automatic options above, you're going to have to
do the configuration yourself. Don't worry. Even this isn't too bad... there are
...
...
@@ -91,7 +94,9 @@ Define this to be the number of bits an `int` takes up on your system. The
default, if not autodetected, is 32 bits.
_Example:_
#define UNITY_INT_WIDTH 16
```
C
#define UNITY_INT_WIDTH 16
```
##### `UNITY_LONG_WIDTH`
...
...
@@ -103,7 +108,9 @@ of 64-bit support your system can handle. Does it need to specify a `long` or a
ignored.
_Example:_
#define UNITY_LONG_WIDTH 16
```
C
#define UNITY_LONG_WIDTH 16
```
##### `UNITY_POINTER_WIDTH`
...
...
@@ -113,7 +120,9 @@ default, if not autodetected, is 32-bits. If you're getting ugly compiler
warnings about casting from pointers, this is the one to look at.
_Example:_
#define UNITY_POINTER_WIDTH 64
```
C
#define UNITY_POINTER_WIDTH 64
```
##### `UNITY_SUPPORT_64`
...
...
@@ -125,7 +134,9 @@ can be a significant size and speed impact to enabling 64-bit support on small
targets, so don't define it if you don't need it.
_Example:_
#define UNITY_SUPPORT_64
```
C
#define UNITY_SUPPORT_64
```
### Floating Point Types
...
...
@@ -153,10 +164,11 @@ suits your needs. For features that are enabled, the following floating point
options also become available.
_Example:_
//what manner of strange processor is this?
#define UNITY_EXCLUDE_FLOAT
#define UNITY_INCLUDE_DOUBLE
```
C
//what manner of strange processor is this?
#define UNITY_EXCLUDE_FLOAT
#define UNITY_INCLUDE_DOUBLE
```
##### `UNITY_EXCLUDE_FLOAT_PRINT`
...
...
@@ -172,7 +184,9 @@ can use this define to instead respond to a failed assertion with a message like
point assertions, use these options to give more explicit failure messages.
_Example:_
#define UNITY_EXCLUDE_FLOAT_PRINT
```
C
#define UNITY_EXCLUDE_FLOAT_PRINT
```
##### `UNITY_FLOAT_TYPE`
...
...
@@ -182,7 +196,9 @@ floats. If your compiler supports a specialty floating point type, you can
always override this behavior by using this definition.
_Example:_
#define UNITY_FLOAT_TYPE float16_t
```
C
#define UNITY_FLOAT_TYPE float16_t
```
##### `UNITY_DOUBLE_TYPE`
...
...
@@ -194,7 +210,9 @@ could enable gargantuan floating point types on your 64-bit processor instead of
the standard
`double`
.
_Example:_
#define UNITY_DOUBLE_TYPE long double
```
C
#define UNITY_DOUBLE_TYPE long double
```
##### `UNITY_FLOAT_PRECISION`
...
...
@@ -213,7 +231,62 @@ For further details on how this works, see the appendix of the Unity Assertion
Guide.
_Example:_
#define UNITY_FLOAT_PRECISION 0.001f
```
C
#define UNITY_FLOAT_PRECISION 0.001f
```
### Miscellaneous
##### `UNITY_EXCLUDE_STDDEF_H`
Unity uses the
`NULL`
macro, which defines the value of a null pointer constant,
defined in
`stddef.h`
by default. If you want to provide
your own macro for this, you should exclude the
`stddef.h`
header file by adding this
define to your configuration.
_Example:_
```
C
#define UNITY_EXCLUDE_STDDEF_H
```
#### `UNITY_INCLUDE_PRINT_FORMATTED`
Unity provides a simple (and very basic) printf-like string output implementation,
which is able to print a string modified by the following format string modifiers:
-
__%d__ - signed value (decimal)
-
__%i__ - same as __%i__
-
__%u__ - unsigned value (decimal)
-
__%f__ - float/Double (if float support is activated)
-
__%g__ - same as __%f__
-
__%b__ - binary prefixed with "0b"
-
__%x__ - hexadecimal (upper case) prefixed with "0x"
-
__%X__ - same as __%x__
-
__%p__ - pointer (same as __%x__ or __%X__)
-
__%c__ - a single character
-
__%s__ - a string (e.g. "string")
-
__%%__ - The "%" symbol (escaped)
_Example:_
```
C
#define UNITY_INCLUDE_PRINT_FORMATTED
int a = 0xfab1;
UnityPrintFormatted("Decimal %d\n", -7);
UnityPrintFormatted("Unsigned %u\n", 987);
UnityPrintFormatted("Float %f\n", 3.1415926535897932384);
UnityPrintFormatted("Binary %b\n", 0xA);
UnityPrintFormatted("Hex %X\n", 0xFAB);
UnityPrintFormatted("Pointer %p\n", &a);
UnityPrintFormatted("Character %c\n", 'F');
UnityPrintFormatted("String %s\n", "My string");
UnityPrintFormatted("Percent %%\n");
UnityPrintFormatted("Color Red \033[41mFAIL\033[00m\n");
UnityPrintFormatted("\n");
UnityPrintFormatted("Multiple (%d) (%i) (%u) (%x)\n", -100, 0, 200, 0x12345);
```
### Toolset Customization
...
...
@@ -248,12 +321,14 @@ _Example:_
Say you are forced to run your test suite on an embedded processor with no
`stdout`
option. You decide to route your test result output to a custom serial
`RS232_putc()`
function you wrote like thus:
#include "RS232_header.h"
...
#define UNITY_OUTPUT_CHAR(a) RS232_putc(a)
#define UNITY_OUTPUT_START() RS232_config(115200,1,8,0)
#define UNITY_OUTPUT_FLUSH() RS232_flush()
#define UNITY_OUTPUT_COMPLETE() RS232_close()
```
C
#include "RS232_header.h"
...
#define UNITY_OUTPUT_CHAR(a) RS232_putc(a)
#define UNITY_OUTPUT_START() RS232_config(115200,1,8,0)
#define UNITY_OUTPUT_FLUSH() RS232_flush()
#define UNITY_OUTPUT_COMPLETE() RS232_close()
```
_Note:_
`UNITY_OUTPUT_FLUSH()`
can be set to the standard out flush function simply by
...
...
@@ -282,10 +357,12 @@ empty). You can also force Unity to NOT use weak functions by defining
UNITY_NO_WEAK. The most common options for this feature are:
_Example:_
#define UNITY_WEAK_ATTRIBUTE weak
#define UNITY_WEAK_ATTRIBUTE __attribute__((weak))
#define UNITY_WEAK_PRAGMA
#define UNITY_NO_WEAK
```
C
#define UNITY_WEAK_ATTRIBUTE weak
#define UNITY_WEAK_ATTRIBUTE __attribute__((weak))
#define UNITY_WEAK_PRAGMA
#define UNITY_NO_WEAK
```
##### `UNITY_PTR_ATTRIBUTE`
...
...
@@ -295,9 +372,10 @@ Some compilers require a custom attribute to be assigned to pointers, like
defining this option with the attribute you would like.
_Example:_
#define UNITY_PTR_ATTRIBUTE __attribute__((far))
#define UNITY_PTR_ATTRIBUTE near
```
C
#define UNITY_PTR_ATTRIBUTE __attribute__((far))
#define UNITY_PTR_ATTRIBUTE near
```
##### `UNITY_PRINT_EOL`
...
...
@@ -306,8 +384,9 @@ to parse by the scripts, by Ceedling, etc, but it might not be ideal for YOUR
system. Feel free to override this and to make it whatever you wish.
_Example:_
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('
\r
'); UNITY_OUTPUT_CHAR('
\n
') }
```
C
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\r'); UNITY_OUTPUT_CHAR('\n') }
```
##### `UNITY_EXCLUDE_DETAILS`
...
...
@@ -319,8 +398,9 @@ report which function or argument flagged an error. If you're not using CMock an
you're not using these details for other things, then you can exclude them.
_Example:_
#define UNITY_EXCLUDE_DETAILS
```
C
#define UNITY_EXCLUDE_DETAILS
```
##### `UNITY_EXCLUDE_SETJMP`
...
...
@@ -333,15 +413,18 @@ compiler doesn't support setjmp, you wouldn't have had the memory space for thos
things anyway, though... so this option exists for those situations.
_Example:_
#define UNITY_EXCLUDE_SETJMP
```
C
#define UNITY_EXCLUDE_SETJMP
```
##### `UNITY_OUTPUT_COLOR`
If you want to add color using ANSI escape codes you can use this define.
t
_Example:_
#define UNITY_OUTPUT_COLOR
```
C
#define UNITY_OUTPUT_COLOR
```
## Getting Into The Guts
...
...
@@ -368,13 +451,15 @@ output of your test results.
A simple main function looks something like this:
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_TheFirst);
RUN_TEST(test_TheSecond);
RUN_TEST(test_TheThird);
return UNITY_END();
}
```
C
int main(void) {
UNITY_BEGIN();
RUN_TEST(test_TheFirst);
RUN_TEST(test_TheSecond);
RUN_TEST(test_TheThird);
return UNITY_END();
}
```
You can see that our main function doesn't bother taking any arguments. For our
most barebones case, we'll never have arguments because we just run all the
...
...
@@ -397,15 +482,17 @@ case function. This includes catching failures, calling the test module's
using CMock or test coverage, there will be additional stubs in use here. A
simple minimalist RUN_TEST macro looks something like this:
#define RUN_TEST(testfunc) \
UNITY_NEW_TEST(#testfunc) \
if (TEST_PROTECT()) { \
setUp(); \
testfunc(); \
} \
if (TEST_PROTECT() && (!TEST_IS_IGNORED)) \
tearDown(); \
UnityConcludeTest();
```
C
#define RUN_TEST(testfunc) \
UNITY_NEW_TEST(#testfunc) \
if (TEST_PROTECT()) { \
setUp(); \
testfunc(); \
} \
if (TEST_PROTECT() && (!TEST_IS_IGNORED)) \
tearDown(); \
UnityConcludeTest();
```
So that's quite a macro, huh? It gives you a glimpse of what kind of stuff Unity
has to deal with for every single test case. For each test case, we declare that
...
...
examples/example_1/src/ProductionCode.c
浏览文件 @
e9f96384
...
...
@@ -4,14 +4,14 @@
int
Counter
=
0
;
int
NumbersToFind
[
9
]
=
{
0
,
34
,
55
,
66
,
32
,
11
,
1
,
77
,
888
};
/* some obnoxious array to search that is 1-based indexing instead of 0. */
/* This function is supposed to search through NumbersToFind and find a particular number.
* If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since
* NumbersToFind is indexed from 1. Unfortunately it's broken
/* This function is supposed to search through NumbersToFind and find a particular number.
* If it finds it, the index is returned. Otherwise 0 is returned which sorta makes sense since
* NumbersToFind is indexed from 1. Unfortunately it's broken
* (and should therefore be caught by our tests) */
int
FindFunction_WhichIsBroken
(
int
NumberToFind
)
{
int
i
=
0
;
while
(
i
<
=
8
)
/* Notice I should have been in braces */
while
(
i
<
8
)
/* Notice I should have been in braces */
i
++
;
if
(
NumbersToFind
[
i
]
==
NumberToFind
)
/* Yikes! I'm getting run after the loop finishes instead of during it! */
return
i
;
...
...
examples/example_1/test/TestProductionCode.c
浏览文件 @
e9f96384
...
...
@@ -5,7 +5,7 @@
/* sometimes you may want to get at local data in a module.
* for example: If you plan to pass by reference, this could be useful
* however, it should often be avoided */
extern
int
Counter
;
extern
int
Counter
;
void
setUp
(
void
)
{
...
...
@@ -21,7 +21,7 @@ void test_FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInList_WhichWork
{
/* All of these should pass */
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
78
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
1
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
2
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
33
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
999
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
-
1
));
...
...
@@ -31,9 +31,9 @@ void test_FindFunction_WhichIsBroken_ShouldReturnTheIndexForItemsInList_WhichWil
{
/* You should see this line fail in your test summary */
TEST_ASSERT_EQUAL
(
1
,
FindFunction_WhichIsBroken
(
34
));
/* Notice the rest of these didn't get a chance to run because the line above failed.
* Unit tests abort each test function on the first sign of trouble.
/* Notice the rest of these didn't get a chance to run because the line above failed.
* Unit tests abort each test function on the first sign of trouble.
* Then NEXT test function runs as normal. */
TEST_ASSERT_EQUAL
(
8
,
FindFunction_WhichIsBroken
(
8888
));
}
...
...
@@ -42,7 +42,7 @@ void test_FunctionWhichReturnsLocalVariable_ShouldReturnTheCurrentCounterValue(v
{
/* This should be true because setUp set this up for us before this test */
TEST_ASSERT_EQUAL_HEX
(
0x5a5a
,
FunctionWhichReturnsLocalVariable
());
/* This should be true because we can still change our answer */
Counter
=
0x1234
;
TEST_ASSERT_EQUAL_HEX
(
0x1234
,
FunctionWhichReturnsLocalVariable
());
...
...
examples/example_2/test/TestProductionCode.c
浏览文件 @
e9f96384
...
...
@@ -23,7 +23,7 @@ TEST(ProductionCode, FindFunction_WhichIsBroken_ShouldReturnZeroIfItemIsNotInLis
{
//All of these should pass
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
78
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
1
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
2
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
33
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
999
));
TEST_ASSERT_EQUAL
(
0
,
FindFunction_WhichIsBroken
(
-
1
));
...
...
examples/example_3/rakefile.rb
浏览文件 @
e9f96384
HERE
=
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
+
'/'
UNITY_ROOT
=
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
+
'/../..'
require
'rake'
require
'rake/clean'
require
HERE
+
'rakefile_helper'
require
_relative
'rakefile_helper'
TEMP_DIRS
=
[
File
.
join
(
HERE
,
'build'
)
File
.
join
(
__dir__
,
'build'
)
].
freeze
TEMP_DIRS
.
each
do
|
dir
|
...
...
@@ -32,8 +29,8 @@ task :summary do
end
desc
'Build and test Unity'
task
all:
%i
(clean unit summary)
task
default:
%i
(clobber all)
task
all:
%i
[clean unit summary]
task
default:
%i
[clobber all]
task
ci:
[
:default
]
task
cruise:
[
:default
]
...
...
examples/example_3/rakefile_helper.rb
浏览文件 @
e9f96384
require
'yaml'
require
'fileutils'
require
UNITY_ROOT
+
'
/auto/unity_test_summary'
require
UNITY_ROOT
+
'
/auto/generate_test_runner'
require
UNITY_ROOT
+
'
/auto/colour_reporter'
require
_relative
'../..
/auto/unity_test_summary'
require
_relative
'../..
/auto/generate_test_runner'
require
_relative
'../..
/auto/colour_reporter'
module
RakefileHelpers
C_EXTENSION
=
'.c'
.
freeze
...
...
@@ -149,7 +149,7 @@ module RakefileHelpers
def
report_summary
summary
=
UnityTestSummary
.
new
summary
.
root
=
HERE
summary
.
root
=
__dir__
results_glob
=
"
#{
$cfg
[
'compiler'
][
'build_path'
]
}
*.test*"
results_glob
.
tr!
(
'\\'
,
'/'
)
results
=
Dir
[
results_glob
]
...
...
examples/example_3/target_gcc_32.yml
浏览文件 @
e9f96384
# Copied from ~Unity/targets/gcc_32.yml
unity_root
:
&unity_root
'
../..'
unity_source
:
&unity_source
'
../../src/'
compiler
:
path
:
gcc
source_path
:
'
src/'
source_path
:
&source_path
'
src/'
unit_tests_path
:
&unit_tests_path
'
test/'
build_path
:
&build_path
'
build/'
options
:
...
...
@@ -15,8 +16,8 @@ compiler:
includes
:
prefix
:
'
-I'
items
:
-
'
src/'
-
'
../../src/'
-
*source_path
-
*unity_source
-
*unit_tests_path
defines
:
prefix
:
'
-D'
...
...
examples/unity_config.h
浏览文件 @
e9f96384
...
...
@@ -176,6 +176,22 @@
/* #define UNITY_DOUBLE_PRECISION 0.001f */
/* *************************** MISCELLANEOUS ***********************************
* Miscellaneous configuration options for Unity
**************************************************************************** */
/* Unity uses the stddef.h header included in the C standard library for the
* "NULL" macro. Define this in order to disable the include of stddef.h. If you
* do this, you have to make sure to provide your own "NULL" definition.
*/
/* #define UNITY_EXCLUDE_STDDEF_H */
/* Define this to enable the unity formatted print function:
* "UnityPrintFormatted"
*/
/* #define UNITY_INCLUDE_PRINT_FORMATTED */
/* *************************** TOOLSET CUSTOMIZATION ***************************
* In addition to the options listed above, there are a number of other options
* which will come in handy to customize Unity's behavior for your specific
...
...
extras/fixture/rakefile.rb
浏览文件 @
e9f96384
...
...
@@ -4,15 +4,13 @@
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
HERE
=
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
+
'/'
require
'rake'
require
'rake/clean'
require
'rake/testtask'
require
HERE
+
'rakefile_helper'
require
_relative
'rakefile_helper'
TEMP_DIRS
=
[
File
.
join
(
HERE
,
'build'
)
File
.
join
(
__dir__
,
'build'
)
].
freeze
TEMP_DIRS
.
each
do
|
dir
|
...
...
@@ -33,10 +31,10 @@ task unit: [:prepare_for_tests] do
end
desc
'Build and test Unity Framework'
task
all:
%i
(clean unit)
task
default:
%i
(clobber all)
task
ci:
%i
(no_color default)
task
cruise:
%i
(no_color default)
task
all:
%i
[clean unit]
task
default:
%i
[clobber all]
task
ci:
%i
[no_color default]
task
cruise:
%i
[no_color default]
desc
'Load configuration'
task
:config
,
:config_file
do
|
_t
,
args
|
...
...
extras/fixture/rakefile_helper.rb
浏览文件 @
e9f96384
...
...
@@ -6,9 +6,9 @@
require
'yaml'
require
'fileutils'
require
HERE
+
'../../auto/unity_test_summary'
require
HERE
+
'../../auto/generate_test_runner'
require
HERE
+
'../../auto/colour_reporter'
require
_relative
'../../auto/unity_test_summary'
require
_relative
'../../auto/generate_test_runner'
require
_relative
'../../auto/colour_reporter'
module
RakefileHelpers
C_EXTENSION
=
'.c'
.
freeze
...
...
@@ -16,7 +16,7 @@ module RakefileHelpers
def
load_configuration
(
config_file
)
return
if
$configured
$cfg_file
=
HERE
+
"
../../test/targets/
#{
config_file
}
"
unless
config_file
=~
/[\\|\/]/
$cfg_file
=
"
#{
__dir__
}
/
../../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
...
...
@@ -128,7 +128,7 @@ module RakefileHelpers
def
report_summary
summary
=
UnityTestSummary
.
new
summary
.
root
=
HERE
summary
.
root
=
__dir__
results_glob
=
"
#{
$cfg
[
'compiler'
][
'build_path'
]
}
*.test*"
results_glob
.
tr!
(
'\\'
,
'/'
)
results
=
Dir
[
results_glob
]
...
...
@@ -145,9 +145,9 @@ module RakefileHelpers
$cfg
[
'compiler'
][
'defines'
][
'items'
]
=
[]
if
$cfg
[
'compiler'
][
'defines'
][
'items'
].
nil?
# Get a list of all source files needed
src_files
=
Dir
[
HERE
+
'src/*.c'
]
src_files
+=
Dir
[
HERE
+
'test/*.c'
]
src_files
+=
Dir
[
HERE
+
'test/main/*.c'
]
src_files
=
Dir
[
"
#{
__dir__
}
/src/*.c"
]
src_files
+=
Dir
[
"
#{
__dir__
}
/test/*.c"
]
src_files
+=
Dir
[
"
#{
__dir__
}
/test/main/*.c"
]
src_files
<<
'../../src/unity.c'
# Build object files
...
...
extras/fixture/src/unity_fixture.c
浏览文件 @
e9f96384
...
...
@@ -419,7 +419,8 @@ void UnityConcludeFixtureTest(void)
{
if
(
UnityFixture
.
Verbose
)
{
UnityPrint
(
" PASS"
);
UnityPrint
(
" "
);
UnityPrint
(
UnityStrPass
);
UNITY_EXEC_TIME_STOP
();
UNITY_PRINT_EXEC_TIME
();
UNITY_PRINT_EOL
();
...
...
src/unity.c
浏览文件 @
e9f96384
此差异已折叠。
点击以展开。
src/unity.h
浏览文件 @
e9f96384
/* ==========================================
Unity Project - A Test Framework for C
Copyright (c) 2007-1
4
Mike Karlesky, Mark VanderVoord, Greg Williams
Copyright (c) 2007-1
9
Mike Karlesky, Mark VanderVoord, Greg Williams
[Released under MIT License. Please refer to license.txt for details]
========================================== */
...
...
@@ -230,6 +230,24 @@ int suiteTearDown(int num_failures);
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, NULL)
/* Integer Array Ranges (of all sizes) */
#define TEST_ASSERT_INT_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_INT8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_INT16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_INT32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_UINT_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_UINT8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_UINT16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_UINT32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_HEX_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_HEX8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_HEX16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_HEX32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
#define TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL)
/* Structs and Strings */
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, NULL)
...
...
@@ -422,6 +440,24 @@ int suiteTearDown(int num_failures);
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, (message))
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, (message))
/* Integer Array Ranges (of all sizes) */
#define TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_INT32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_UINT32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_HEX_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
#define TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message))
/* Structs and Strings */
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, (message))
...
...
src/unity_internals.h
浏览文件 @
e9f96384
此差异已折叠。
点击以展开。
test/.rubocop.yml
浏览文件 @
e9f96384
...
...
@@ -18,7 +18,7 @@ Style/HashSyntax:
EnforcedStyle
:
no_mixed_keys
# This is disabled because it seems to get confused over nested hashes
Style
/AlignHash
:
Layout
/AlignHash
:
Enabled
:
false
EnforcedHashRocketStyle
:
table
EnforcedColonStyle
:
table
...
...
test/rakefile
浏览文件 @
e9f96384
...
...
@@ -4,17 +4,16 @@
# [Released under MIT License. Please refer to license.txt for details]
# ==========================================
UNITY_ROOT
=
File
.
expand_path
(
File
.
dirname
(
__FILE__
))
+
'/'
$verbose
=
false
require
'rake'
require
'rake/clean'
require
UNITY_ROOT
+
'rakefile_helper'
require
_relative
'rakefile_helper'
require
'rspec/core/rake_task'
TEMP_DIRS
=
[
File
.
join
(
UNITY_ROOT
,
'build'
),
File
.
join
(
UNITY_ROOT
,
'sandbox'
)
File
.
join
(
__dir__
,
'build'
),
File
.
join
(
__dir__
,
'sandbox'
)
]
TEMP_DIRS
.
each
do
|
dir
|
...
...
test/rakefile_helper.rb
浏览文件 @
e9f96384
...
...
@@ -6,9 +6,9 @@
require
'yaml'
require
'fileutils'
require
UNITY_ROOT
+
'../auto/unity_test_summary'
require
UNITY_ROOT
+
'../auto/generate_test_runner'
require
UNITY_ROOT
+
'../auto/colour_reporter'
require
_relative
'../auto/unity_test_summary'
require
_relative
'../auto/generate_test_runner'
require
_relative
'../auto/colour_reporter'
module
RakefileHelpers
C_EXTENSION
=
'.c'
.
freeze
...
...
@@ -179,7 +179,7 @@ module RakefileHelpers
def
report_summary
summary
=
UnityTestSummary
.
new
summary
.
root
=
UNITY_ROOT
summary
.
root
=
__dir__
results_glob
=
"
#{
$cfg
[
'compiler'
][
'build_path'
]
}
*.test*"
results_glob
.
tr!
(
'\\'
,
'/'
)
results
=
Dir
[
results_glob
]
...
...
test/tests/testparameterized.c
浏览文件 @
e9f96384
...
...
@@ -46,6 +46,14 @@ void flushSpy(void) {}
int
SetToOneToFailInTearDown
;
int
SetToOneMeanWeAlreadyCheckedThisGuy
;
static
unsigned
NextExpectedStringIndex
;
static
unsigned
NextExpectedCharIndex
;
void
suiteSetUp
(
void
)
{
NextExpectedStringIndex
=
0
;
NextExpectedCharIndex
=
0
;
}
void
setUp
(
void
)
{
...
...
@@ -111,3 +119,56 @@ void test_NormalFailsStillWork(void)
TEST_ASSERT_TRUE
(
0
);
VERIFY_FAILS_END
}
TEST_CASE
(
0
,
"abc"
)
TEST_CASE
(
1
,
"{"
)
TEST_CASE
(
2
,
"}"
)
TEST_CASE
(
3
,
";"
)
TEST_CASE
(
4
,
"
\"
quoted
\"
"
)
void
test_StringsArePreserved
(
unsigned
index
,
const
char
*
str
)
{
static
const
char
*
const
expected
[]
=
{
"abc"
,
"{"
,
"}"
,
";"
,
"
\"
quoted
\"
"
};
/* Ensure that no test cases are skipped by tracking the next expected index */
TEST_ASSERT_EQUAL_UINT32
(
NextExpectedStringIndex
,
index
);
TEST_ASSERT_LESS_THAN
(
sizeof
(
expected
)
/
sizeof
(
expected
[
0
]),
index
);
TEST_ASSERT_EQUAL_STRING
(
expected
[
index
],
str
);
NextExpectedStringIndex
++
;
}
TEST_CASE
(
0
,
'x'
)
TEST_CASE
(
1
,
'{'
)
TEST_CASE
(
2
,
'}'
)
TEST_CASE
(
3
,
';'
)
TEST_CASE
(
4
,
'\''
)
TEST_CASE
(
5
,
'"'
)
void
test_CharsArePreserved
(
unsigned
index
,
char
c
)
{
static
const
char
expected
[]
=
{
'x'
,
'{'
,
'}'
,
';'
,
'\''
,
'"'
};
/* Ensure that no test cases are skipped by tracking the next expected index */
TEST_ASSERT_EQUAL_UINT32
(
NextExpectedCharIndex
,
index
);
TEST_ASSERT_LESS_THAN
(
sizeof
(
expected
)
/
sizeof
(
expected
[
0
]),
index
);
TEST_ASSERT_EQUAL
(
expected
[
index
],
c
);
NextExpectedCharIndex
++
;
}
test/tests/testunity.c
浏览文件 @
e9f96384
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录