提交 1f643e86 编写于 作者: M mvandervoord

- updated example and main tests to show how to use generate_test_runner with yaml target file

- improved error reporting for generate_test_runner

git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@96 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
上级 b7564ce8
...@@ -24,6 +24,7 @@ class UnityTestRunnerGenerator ...@@ -24,6 +24,7 @@ class UnityTestRunnerGenerator
require 'yaml' require 'yaml'
yaml_guts = YAML.load_file(config_file) yaml_guts = YAML.load_file(config_file)
yaml_goodness = yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock] yaml_goodness = yaml_guts[:unity] ? yaml_guts[:unity] : yaml_guts[:cmock]
raise "No :unity or :cmock section found in #{config_file}" unless yaml_goodness
options[:cexception] = 1 unless (yaml_goodness[:plugins] & ['cexception', :cexception]).empty? options[:cexception] = 1 unless (yaml_goodness[:plugins] & ['cexception', :cexception]).empty?
options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering]) options[:order] = 1 if (yaml_goodness[:enforce_strict_ordering])
options[:framework] = (yaml_goodness[:framework] || :unity) options[:framework] = (yaml_goodness[:framework] || :unity)
...@@ -120,7 +121,7 @@ class UnityTestRunnerGenerator ...@@ -120,7 +121,7 @@ class UnityTestRunnerGenerator
output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */') output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */')
output.puts("#include \"#{@options[:framework].to_s}.h\"") output.puts("#include \"#{@options[:framework].to_s}.h\"")
output.puts('#include "cmock.h"') unless (mocks.empty?) output.puts('#include "cmock.h"') unless (mocks.empty?)
@options[:includes].flatten.each do |includes| @options[:includes].flatten.uniq.compact.each do |includes|
output.puts("#include \"#{includes.gsub('.h','')}.h\"") output.puts("#include \"#{includes.gsub('.h','')}.h\"")
end end
output.puts('#include <setjmp.h>') output.puts('#include <setjmp.h>')
......
...@@ -9,7 +9,7 @@ module RakefileHelpers ...@@ -9,7 +9,7 @@ module RakefileHelpers
C_EXTENSION = '.c' C_EXTENSION = '.c'
def load_configuration(config_file) def load_configuration(config_file)
$cfg_file = config_file $cfg_file = "../targets/#{config_file}"
$cfg = YAML.load(File.read($cfg_file)) $cfg = YAML.load(File.read($cfg_file))
end end
...@@ -191,7 +191,7 @@ module RakefileHelpers ...@@ -191,7 +191,7 @@ module RakefileHelpers
runner_name = test_base + '_Runner.c' runner_name = test_base + '_Runner.c'
if $cfg['compiler']['runner_path'].nil? if $cfg['compiler']['runner_path'].nil?
runner_path = $cfg['compiler']['build_path'] + runner_name runner_path = $cfg['compiler']['build_path'] + runner_name
test_gen = UnityTestRunnerGenerator.new test_gen = UnityTestRunnerGenerator.new($cfg_file)
test_gen.run(test, runner_path) test_gen.run(test, runner_path)
else else
runner_path = $cfg['compiler']['runner_path'] + runner_name runner_path = $cfg['compiler']['runner_path'] + runner_name
......
...@@ -16,7 +16,7 @@ module RakefileHelpers ...@@ -16,7 +16,7 @@ module RakefileHelpers
C_EXTENSION = '.c' C_EXTENSION = '.c'
def load_configuration(config_file) def load_configuration(config_file)
$cfg_file = config_file $cfg_file = "targets/#{config_file}" unless $cfg_file =~ /[\\|\/]/
$cfg = YAML.load(File.read($cfg_file)) $cfg = YAML.load(File.read($cfg_file))
$colour_output = false unless $cfg['colour'] $colour_output = false unless $cfg['colour']
end end
...@@ -27,7 +27,7 @@ module RakefileHelpers ...@@ -27,7 +27,7 @@ module RakefileHelpers
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 += '.yml' unless config_file =~ /\.yml$/
config_file = "targets/#{config_file}" unless config_file =~ /[\\|\/]/ config_file = config_file unless config_file =~ /[\\|\/]/
load_configuration(config_file) load_configuration(config_file)
configure_clean configure_clean
end end
...@@ -205,8 +205,7 @@ module RakefileHelpers ...@@ -205,8 +205,7 @@ module RakefileHelpers
runner_path = $cfg['compiler']['runner_path'] + runner_name runner_path = $cfg['compiler']['runner_path'] + runner_name
end end
#UnityTestRunnerGenerator.new(:suite_setup => 'puts("\nStarting Test Suite!\n");', :suite_teardown => 'return num_failures;').run(test, runner_path) UnityTestRunnerGenerator.new($cfg_file).run(test, runner_path)
UnityTestRunnerGenerator.new.run(test, runner_path)
compile(runner_path, test_defines) compile(runner_path, test_defines)
obj_list << runner_name.ext($cfg['compiler']['object_files']['extension']) obj_list << runner_name.ext($cfg['compiler']['object_files']['extension'])
......
...@@ -35,4 +35,6 @@ linker: ...@@ -35,4 +35,6 @@ linker:
prefix: '-o' prefix: '-o'
extension: '.exe' extension: '.exe'
destination: *build_path destination: *build_path
colour: true colour: true
\ No newline at end of file :unity:
:plugins: []
\ No newline at end of file
...@@ -36,4 +36,6 @@ linker: ...@@ -36,4 +36,6 @@ linker:
prefix: '-o' prefix: '-o'
extension: '.exe' extension: '.exe'
destination: *build_path destination: *build_path
colour: true colour: true
\ No newline at end of file :unity:
:plugins: []
\ No newline at end of file
...@@ -31,7 +31,7 @@ compiler: ...@@ -31,7 +31,7 @@ compiler:
items: items:
- [*tools_root, 'arm\inc\'] - [*tools_root, 'arm\inc\']
- 'src\' - 'src\'
- '../src/' - '..\src\'
- *unit_tests_path - *unit_tests_path
- 'vendor\unity\src\' - 'vendor\unity\src\'
defines: defines:
...@@ -83,4 +83,6 @@ simulator: ...@@ -83,4 +83,6 @@ simulator:
- [*tools_root, 'arm\config\ioat91sam7X256.ddf'] - [*tools_root, 'arm\config\ioat91sam7X256.ddf']
- -d - -d
- sim - sim
colour: true colour: true
\ No newline at end of file :unity:
:plugins: []
\ No newline at end of file
...@@ -30,7 +30,7 @@ compiler: ...@@ -30,7 +30,7 @@ compiler:
items: items:
- [*tools_root, 'arm\inc\'] - [*tools_root, 'arm\inc\']
- 'src\' - 'src\'
- '../src/' - '..\src\'
- *unit_tests_path - *unit_tests_path
- 'vendor\unity\src\' - 'vendor\unity\src\'
- 'iar\iar_v5\incIAR\' - 'iar\iar_v5\incIAR\'
...@@ -73,4 +73,6 @@ simulator: ...@@ -73,4 +73,6 @@ simulator:
- [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf'] - [*tools_root, 'arm\config\debugger\atmel\ioat91sam7X256.ddf']
- -d - -d
- sim - sim
colour: true colour: true
\ No newline at end of file :unity:
:plugins: []
\ No newline at end of file
...@@ -32,7 +32,7 @@ compiler: ...@@ -32,7 +32,7 @@ compiler:
items: items:
- [*tools_root, 'arm\inc\'] - [*tools_root, 'arm\inc\']
- 'src\' - 'src\'
- '../src/' - '..\src\'
- *unit_tests_path - *unit_tests_path
- 'vendor\unity\src\' - 'vendor\unity\src\'
- 'iar\iar_v5\incIAR\' - 'iar\iar_v5\incIAR\'
...@@ -77,4 +77,6 @@ simulator: ...@@ -77,4 +77,6 @@ simulator:
- --cpu=Cortex-M3 - --cpu=Cortex-M3
- -d - -d
- sim - sim
colour: true colour: true
\ No newline at end of file :unity:
:plugins: []
\ No newline at end of file
...@@ -88,4 +88,6 @@ simulator: ...@@ -88,4 +88,6 @@ simulator:
- -p - -p
- [*core_config, 'MSP430F5438.ddf'] - [*core_config, 'MSP430F5438.ddf']
- -d sim - -d sim
colour: true colour: true
\ No newline at end of file :unity:
:plugins: []
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册