提交 57178b92 编写于 作者: M mvandervoord

- tweaked parameterized tests to be C99 standards compliant

- fixed a few bugs in fixtures to get it to pass against our standard compilers
- added extern of OUTPUT_CHAR method to keep compilers from complaining

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@107 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
上级 5a6b8c40
...@@ -203,6 +203,7 @@ class UnityTestRunnerGenerator ...@@ -203,6 +203,7 @@ class UnityTestRunnerGenerator
va_args1 = @options[:use_param_tests] ? ', ...' : '' va_args1 = @options[:use_param_tests] ? ', ...' : ''
va_args2 = @options[:use_param_tests] ? '__VA_ARGS__' : '' va_args2 = @options[:use_param_tests] ? '__VA_ARGS__' : ''
output.puts("\n//=======Test Runner Used To Run Each Test Below=====") output.puts("\n//=======Test Runner Used To Run Each Test Below=====")
output.puts("#define RUN_TEST_NO_ARGS") if @options[:use_param_tests]
output.puts("#define RUN_TEST(TestFunc, TestLineNum#{va_args1}) \\") output.puts("#define RUN_TEST(TestFunc, TestLineNum#{va_args1}) \\")
output.puts("{ \\") output.puts("{ \\")
output.puts(" Unity.CurrentTestName = #TestFunc; \\") output.puts(" Unity.CurrentTestName = #TestFunc; \\")
...@@ -246,12 +247,16 @@ class UnityTestRunnerGenerator ...@@ -246,12 +247,16 @@ class UnityTestRunnerGenerator
output.puts(" suite_setup();") unless @options[:suite_setup].nil? output.puts(" suite_setup();") unless @options[:suite_setup].nil?
output.puts(" Unity.TestFile = \"#{filename}\";") output.puts(" Unity.TestFile = \"#{filename}\";")
output.puts(" UnityBegin();") output.puts(" UnityBegin();")
tests.each do |test| if (@options[:use_param_tests])
if ((test[:args].nil?) or (test[:args].empty?)) tests.each do |test|
output.puts(" RUN_TEST(#{test[:name]}, #{test[:line_number]});") if ((test[:args].nil?) or (test[:args].empty?))
else output.puts(" RUN_TEST(#{test[:name]}, #{test[:line_number]}, RUN_TEST_NO_ARGS);")
test[:args].each {|args| output.puts(" RUN_TEST(#{test[:name]}, #{test[:line_number]}, #{args});")} else
test[:args].each {|args| output.puts(" RUN_TEST(#{test[:name]}, #{test[:line_number]}, #{args});")}
end
end end
else
tests.each { |test| output.puts(" RUN_TEST(#{test[:name]}, #{test[:line_number]});") }
end end
output.puts() output.puts()
output.puts(" return #{@options[:suite_teardown].nil? ? "" : "suite_teardown"}(UnityEnd());") output.puts(" return #{@options[:suite_teardown].nil? ? "" : "suite_teardown"}(UnityEnd());")
......
...@@ -8,16 +8,19 @@ require 'yaml' ...@@ -8,16 +8,19 @@ require 'yaml'
require 'fileutils' require 'fileutils'
require HERE+'../../auto/unity_test_summary' require HERE+'../../auto/unity_test_summary'
require HERE+'../../auto/generate_test_runner' require HERE+'../../auto/generate_test_runner'
require HERE+'../../auto/colour_reporter' require HERE+'../../auto/colour_reporter'
module RakefileHelpers module RakefileHelpers
C_EXTENSION = '.c' C_EXTENSION = '.c'
def load_configuration(config_file) def load_configuration(config_file)
$cfg_file = HERE+"../../targets/#{config_file}" unless $cfg_file =~ /[\\|\/]/ unless ($configured)
$cfg = YAML.load(File.read($cfg_file)) $cfg_file = HERE+"../../targets/#{config_file}" unless (config_file =~ /[\\|\/]/)
$colour_output = false unless $cfg['colour'] $cfg = YAML.load(File.read($cfg_file))
$colour_output = false unless $cfg['colour']
$configured = true if (config_file != DEFAULT_CONFIG_FILE)
end
end end
def configure_clean def configure_clean
...@@ -159,7 +162,7 @@ module RakefileHelpers ...@@ -159,7 +162,7 @@ module RakefileHelpers
simulator = build_simulator_fields simulator = build_simulator_fields
executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension'] executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension']
if simulator.nil? if simulator.nil?
cmd_str = executable + " -v -r 8" cmd_str = executable + " -v -r"
else else
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}" cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
end end
...@@ -171,6 +174,5 @@ module RakefileHelpers ...@@ -171,6 +174,5 @@ module RakefileHelpers
test_results += '.testpass' test_results += '.testpass'
end end
File.open(test_results, 'w') { |f| f.print output } File.open(test_results, 'w') { |f| f.print output }
puts output
end end
end end
...@@ -297,7 +297,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree) ...@@ -297,7 +297,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringFree)
{ {
void* m = malloc(10); void* m = malloc(10);
char* s = (char*)m; char* s = (char*)m;
s[10] = -1; s[10] = (char)0xFF;
UnityOutputCharSpy_Enable(1); UnityOutputCharSpy_Enable(1);
EXPECT_ABORT_BEGIN EXPECT_ABORT_BEGIN
free(m); free(m);
...@@ -312,7 +312,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringRealloc) ...@@ -312,7 +312,7 @@ TEST(LeakDetection, BufferOverrunFoundDuringRealloc)
{ {
void* m = malloc(10); void* m = malloc(10);
char* s = (char*)m; char* s = (char*)m;
s[10] = -1; s[10] = (char)0xFF;
UnityOutputCharSpy_Enable(1); UnityOutputCharSpy_Enable(1);
EXPECT_ABORT_BEGIN EXPECT_ABORT_BEGIN
m = realloc(m, 100); m = realloc(m, 100);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "unity_output_Spy.h" #include "unity_output_Spy.h"
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
......
...@@ -15,9 +15,12 @@ module RakefileHelpers ...@@ -15,9 +15,12 @@ module RakefileHelpers
C_EXTENSION = '.c' C_EXTENSION = '.c'
def load_configuration(config_file) def load_configuration(config_file)
$cfg_file = "targets/#{config_file}" unless $cfg_file =~ /[\\|\/]/ unless ($configured)
$cfg = YAML.load(File.read($cfg_file)) $cfg_file = "targets/#{config_file}" unless (config_file =~ /[\\|\/]/)
$colour_output = false unless $cfg['colour'] $cfg = YAML.load(File.read($cfg_file))
$colour_output = false unless $cfg['colour']
$configured = true if (config_file != DEFAULT_CONFIG_FILE)
end
end end
def configure_clean def configure_clean
......
...@@ -120,6 +120,8 @@ typedef UNITY_FLOAT_TYPE _UF; ...@@ -120,6 +120,8 @@ typedef UNITY_FLOAT_TYPE _UF;
#define UNITY_OUTPUT_CHAR(a) putchar(a) #define UNITY_OUTPUT_CHAR(a) putchar(a)
#endif #endif
extern int UNITY_OUTPUT_CHAR(int);
//------------------------------------------------------- //-------------------------------------------------------
// Footprint // Footprint
//------------------------------------------------------- //-------------------------------------------------------
......
/* AUTOGENERATED FILE. DO NOT EDIT. */ /* AUTOGENERATED FILE. DO NOT EDIT. */
//=======Test Runner Used To Run Each Test Below===== //=======Test Runner Used To Run Each Test Below=====
#define RUN_TEST_NO_ARGS
#define RUN_TEST(TestFunc, TestLineNum, ...) \ #define RUN_TEST(TestFunc, TestLineNum, ...) \
{ \ { \
Unity.CurrentTestName = #TestFunc; \ Unity.CurrentTestName = #TestFunc; \
...@@ -65,8 +66,8 @@ int main(void) ...@@ -65,8 +66,8 @@ int main(void)
{ {
Unity.TestFile = "test/testdata/mocksample.c"; Unity.TestFile = "test/testdata/mocksample.c";
UnityBegin(); UnityBegin();
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21, RUN_TEST_NO_ARGS);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43, RUN_TEST_NO_ARGS);
return (UnityEnd()); return (UnityEnd());
} }
/* AUTOGENERATED FILE. DO NOT EDIT. */ /* AUTOGENERATED FILE. DO NOT EDIT. */
//=======Test Runner Used To Run Each Test Below===== //=======Test Runner Used To Run Each Test Below=====
#define RUN_TEST_NO_ARGS
#define RUN_TEST(TestFunc, TestLineNum, ...) \ #define RUN_TEST(TestFunc, TestLineNum, ...) \
{ \ { \
Unity.CurrentTestName = #TestFunc; \ Unity.CurrentTestName = #TestFunc; \
...@@ -43,8 +44,8 @@ int main(void) ...@@ -43,8 +44,8 @@ int main(void)
{ {
Unity.TestFile = "test/testdata/testsample.c"; Unity.TestFile = "test/testdata/testsample.c";
UnityBegin(); UnityBegin();
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21, RUN_TEST_NO_ARGS);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43, RUN_TEST_NO_ARGS);
return (UnityEnd()); return (UnityEnd());
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册