提交 14b07433 编写于 作者: M Mark VanderVoord

reenable results summary.

support tests named spec as well.
clean up UnityBegin to make us not have to dig inside it to inject the filename.
Add UNITY_OUTPUT_START() and UNITY_OUTPUT_COMPLETE() for future use.
上级 a4a2eb78
...@@ -78,7 +78,7 @@ class UnityTestRunnerGenerator ...@@ -78,7 +78,7 @@ class UnityTestRunnerGenerator
lines.each_with_index do |line, index| lines.each_with_index do |line, index|
#find tests #find tests
if line =~ /^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+(test.*?)\s*\(\s*(.*)\s*\)/ if line =~ /^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+((?:test.*)|(?:spec.*))\s*\(\s*(.*)\s*\)/
arguments = $1 arguments = $1
name = $2 name = $2
call = $3 call = $3
...@@ -266,8 +266,7 @@ class UnityTestRunnerGenerator ...@@ -266,8 +266,7 @@ class UnityTestRunnerGenerator
output.puts("int main(void)") output.puts("int main(void)")
output.puts("{") output.puts("{")
output.puts(" suite_setup();") unless @options[:suite_setup].nil? output.puts(" suite_setup();") unless @options[:suite_setup].nil?
output.puts(" UnityBegin();") output.puts(" UnityBegin(\"#{filename}\");")
output.puts(" Unity.TestFile = \"#{filename}\";")
if (@options[:use_param_tests]) if (@options[:use_param_tests])
tests.each do |test| tests.each do |test|
if ((test[:args].nil?) or (test[:args].empty?)) if ((test[:args].nil?) or (test[:args].empty?))
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Unity Project - A Test Framework for C # Unity Project - A Test Framework for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details] # [Released under MIT License. Please refer to license.txt for details]
# ========================================== # ==========================================
#!/usr/bin/ruby #!/usr/bin/ruby
# #
...@@ -15,22 +15,22 @@ class UnityTestSummary ...@@ -15,22 +15,22 @@ class UnityTestSummary
include FileUtils::Verbose include FileUtils::Verbose
attr_reader :report, :total_tests, :failures, :ignored attr_reader :report, :total_tests, :failures, :ignored
def initialize def initialize
@report = '' @report = ''
@total_tests = 0 @total_tests = 0
@failures = 0 @failures = 0
@ignored = 0 @ignored = 0
end end
def run def run
# Clean up result file names # Clean up result file names
results = @targets.map {|target| target.gsub(/\\/,'/')} results = @targets.map {|target| target.gsub(/\\/,'/')}
# Dig through each result file, looking for details on pass/fail: # Dig through each result file, looking for details on pass/fail:
failure_output = [] failure_output = []
ignore_output = [] ignore_output = []
results.each do |result_file| results.each do |result_file|
lines = File.readlines(result_file).map { |line| line.chomp } lines = File.readlines(result_file).map { |line| line.chomp }
if lines.length == 0 if lines.length == 0
...@@ -45,7 +45,7 @@ class UnityTestSummary ...@@ -45,7 +45,7 @@ class UnityTestSummary
@ignored += ignored @ignored += ignored
end end
end end
if @ignored > 0 if @ignored > 0
@report += "\n" @report += "\n"
@report += "--------------------------\n" @report += "--------------------------\n"
...@@ -53,7 +53,7 @@ class UnityTestSummary ...@@ -53,7 +53,7 @@ class UnityTestSummary
@report += "--------------------------\n" @report += "--------------------------\n"
@report += ignore_output.flatten.join("\n") @report += ignore_output.flatten.join("\n")
end end
if @failures > 0 if @failures > 0
@report += "\n" @report += "\n"
@report += "--------------------------\n" @report += "--------------------------\n"
...@@ -61,7 +61,7 @@ class UnityTestSummary ...@@ -61,7 +61,7 @@ class UnityTestSummary
@report += "--------------------------\n" @report += "--------------------------\n"
@report += failure_output.flatten.join("\n") @report += failure_output.flatten.join("\n")
end end
@report += "\n" @report += "\n"
@report += "--------------------------\n" @report += "--------------------------\n"
@report += "OVERALL UNITY TEST SUMMARY\n" @report += "OVERALL UNITY TEST SUMMARY\n"
...@@ -69,11 +69,11 @@ class UnityTestSummary ...@@ -69,11 +69,11 @@ class UnityTestSummary
@report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n" @report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n"
@report += "\n" @report += "\n"
end end
def set_targets(target_array) def set_targets(target_array)
@targets = target_array @targets = target_array
end end
def set_root_path(path) def set_root_path(path)
@root = path @root = path
end end
...@@ -88,7 +88,7 @@ class UnityTestSummary ...@@ -88,7 +88,7 @@ class UnityTestSummary
puts " root_path - Helpful for producing more verbose output if using relative paths." puts " root_path - Helpful for producing more verbose output if using relative paths."
exit 1 exit 1
end end
protected protected
def get_details(result_file, lines) def get_details(result_file, lines)
...@@ -104,7 +104,7 @@ class UnityTestSummary ...@@ -104,7 +104,7 @@ class UnityTestSummary
end end
return results return results
end end
def parse_test_summary(summary) def parse_test_summary(summary)
if summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ } if summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ }
[$1.to_i,$2.to_i,$3.to_i] [$1.to_i,$2.to_i,$3.to_i]
...@@ -114,7 +114,7 @@ class UnityTestSummary ...@@ -114,7 +114,7 @@ class UnityTestSummary
end end
def here; File.expand_path(File.dirname(__FILE__)); end def here; File.expand_path(File.dirname(__FILE__)); end
end end
if $0 == __FILE__ if $0 == __FILE__
...@@ -126,11 +126,11 @@ if $0 == __FILE__ ...@@ -126,11 +126,11 @@ if $0 == __FILE__
results = Dir[targets] results = Dir[targets]
raise "No *.testpass or *.testfail files found in '#{targets}'" if results.empty? raise "No *.testpass or *.testfail files found in '#{targets}'" if results.empty?
uts.set_targets(results) uts.set_targets(results)
#set the root path #set the root path
ARGV[1] ||= File.expand_path(File.dirname(__FILE__)) + '/' ARGV[1] ||= File.expand_path(File.dirname(__FILE__)) + '/'
uts.set_root_path(ARGV[1]) uts.set_root_path(ARGV[1])
#run the summarizer #run the summarizer
puts uts.run puts uts.run
rescue Exception => e rescue Exception => e
......
...@@ -1102,9 +1102,9 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int ...@@ -1102,9 +1102,9 @@ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int
} }
//----------------------------------------------- //-----------------------------------------------
void UnityBegin(void) void UnityBegin(const char* filename)
{ {
Unity.TestFile = NULL; Unity.TestFile = filename;
Unity.CurrentTestName = NULL; Unity.CurrentTestName = NULL;
Unity.CurrentTestLineNumber = 0; Unity.CurrentTestLineNumber = 0;
Unity.NumberOfTests = 0; Unity.NumberOfTests = 0;
...@@ -1112,6 +1112,8 @@ void UnityBegin(void) ...@@ -1112,6 +1112,8 @@ void UnityBegin(void)
Unity.TestIgnores = 0; Unity.TestIgnores = 0;
Unity.CurrentTestFailed = 0; Unity.CurrentTestFailed = 0;
Unity.CurrentTestIgnored = 0; Unity.CurrentTestIgnored = 0;
UNITY_OUTPUT_START();
} }
//----------------------------------------------- //-----------------------------------------------
...@@ -1136,6 +1138,7 @@ int UnityEnd(void) ...@@ -1136,6 +1138,7 @@ int UnityEnd(void)
UnityPrintFail(); UnityPrintFail();
} }
UNITY_PRINT_EOL; UNITY_PRINT_EOL;
UNITY_OUTPUT_COMPLETE();
return (int)(Unity.TestFailures); return (int)(Unity.TestFailures);
} }
......
...@@ -258,20 +258,23 @@ typedef UNITY_DOUBLE_TYPE _UD; ...@@ -258,20 +258,23 @@ typedef UNITY_DOUBLE_TYPE _UD;
#endif #endif
//------------------------------------------------------- //-------------------------------------------------------
// Output Method // Output Method: stdout (DEFAULT)
//------------------------------------------------------- //-------------------------------------------------------
#ifndef UNITY_OUTPUT_CHAR #ifndef UNITY_OUTPUT_CHAR
//Default to using putchar, which is defined in stdio.h //Default to using putchar, which is defined in stdio.h
#include <stdio.h> #include <stdio.h>
#define UNITY_OUTPUT_CHAR(a) putchar(a) #define UNITY_OUTPUT_CHAR(a) putchar(a)
#else #else
//If defined as something else, make sure we declare it here so it's ready for use //If defined as something else, make sure we declare it here so it's ready for use
extern int UNITY_OUTPUT_CHAR(int); extern int UNITY_OUTPUT_CHAR(int);
#endif
#ifndef UNITY_OUTPUT_START
#define UNITY_OUTPUT_START()
#endif
#ifndef UNITY_OUTPUT_COMPLETE
#define UNITY_OUTPUT_COMPLETE()
#endif #endif
//------------------------------------------------------- //-------------------------------------------------------
...@@ -388,7 +391,7 @@ extern struct _Unity Unity; ...@@ -388,7 +391,7 @@ extern struct _Unity Unity;
// Test Suite Management // Test Suite Management
//------------------------------------------------------- //-------------------------------------------------------
void UnityBegin(void); void UnityBegin(const char* filename);
int UnityEnd(void); int UnityEnd(void);
void UnityConcludeTest(void); void UnityConcludeTest(void);
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum); void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
...@@ -544,7 +547,7 @@ extern const char* UnityStrErr64; ...@@ -544,7 +547,7 @@ extern const char* UnityStrErr64;
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored) #define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
#ifndef UNITY_BEGIN #ifndef UNITY_BEGIN
#define UNITY_BEGIN() {UnityBegin(); Unity.TestFile = __FILE__;} #define UNITY_BEGIN() UnityBegin(__FILE__)
#endif #endif
#ifndef UNITY_END #ifndef UNITY_END
......
...@@ -172,12 +172,12 @@ module RakefileHelpers ...@@ -172,12 +172,12 @@ module RakefileHelpers
def report_summary def report_summary
summary = UnityTestSummary.new summary = UnityTestSummary.new
summary.set_root_path(UNITY_ROOT ) summary.set_root_path(UNITY_ROOT)
results_glob = "#{$cfg['compiler']['build_path']}*.test*" results_glob = "#{$cfg['compiler']['build_path']}*.test*"
results_glob.gsub!(/\\/, '/') results_glob.gsub!(/\\/, '/')
results = Dir[results_glob] results = Dir[results_glob]
summary.set_targets(results) summary.set_targets(results)
summary.run report summary.run
end end
def run_tests(test_files) def run_tests(test_files)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册