Skip to content

Commit dd70d40

Browse files
committed
Make sure that examples get run with ci, and using appropriate settings.
1 parent 444fbda commit dd70d40

4 files changed

Lines changed: 43 additions & 28 deletions

File tree

examples/example_3/rakefile_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
PROJECT_FILE = File.join(__dir__, 'project.yml').freeze
1717

1818
def load_configuration(config_file)
19-
$cfg_file = config_file =~ /[\\\/]/ ? config_file : File.join(TARGETS_PATH, config_file)
19+
$unity_example_config_file = config_file =~ /[\\\/]/ ? config_file : File.join(TARGETS_PATH, config_file)
2020
project = YamlHelper.load_file(PROJECT_FILE)
21-
target = YamlHelper.load_file($cfg_file)
21+
target = YamlHelper.load_file($unity_example_config_file)
2222

2323
# Toolchain settings (tools, extensions) come from the target YML.
2424
# Path and project settings come from project.yml and take precedence.
@@ -130,15 +130,15 @@ def build_command_string(tool_hash, values, defines = nil)
130130

131131
def compile(file, defines = [])
132132
build_path = $cfg[:project][:build_root]
133-
out_file = File.join(build_path, File.basename(file, C_EXTENSION)) + $cfg[:extension][:object]
133+
out_file = File.join(build_path, File.basename(file, C_EXTENSION)) + ($cfg[:extension][:object] || '.o')
134134
cmd_str = build_command_string($cfg[:tools][:test_compiler], [file, out_file], defines)
135135
execute(cmd_str)
136136
out_file
137137
end
138138

139139
def link_it(exe_name, obj_list)
140140
build_path = $cfg[:project][:build_root]
141-
exe_file = File.join(build_path, File.basename(exe_name, '.*')) + $cfg[:extension][:executable]
141+
exe_file = File.join(build_path, File.basename(exe_name, '.*')) + ($cfg[:extension][:executable] || '')
142142
cmd_str = build_command_string($cfg[:tools][:test_linker], [obj_list, exe_file])
143143
execute(cmd_str)
144144
exe_file

test/rakefile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ include RakefileHelpers
2828

2929
# Load proper GCC as defult configuration
3030
DEFAULT_CONFIG_FILE = 'gcc_64_auto_stdint.yml'
31-
configure_toolchain(DEFAULT_CONFIG_FILE)
31+
$unity_test_config_file = DEFAULT_CONFIG_FILE
3232

3333
############# ALL THE SELF-TESTS WE CAN PERFORM
3434
namespace :test do
3535
desc "Build and test Unity"
3636
task :all => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:fixture', 'test:memory', 'test:summary']
37-
task :ci => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:make', 'test:fixture', 'test:memory', 'test:summary']
37+
task :ci => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:make', 'test:fixture', 'test:memory', 'test:examples', 'test:summary']
3838

3939
desc "Test unity with its own unit tests"
40-
task :unit => [:prepare_for_tests] do
40+
task :unit => [:config_toolchain, :prepare_for_tests] do
4141
run_tests unit_test_files
4242
end
4343

4444
namespace :unit do
4545
unit_test_files.each do |f|
4646
desc "test this unit only"
47-
task File.basename(f,'.c').sub('test_unity_','') => [:prepare_for_tests] do
47+
task File.basename(f,'.c').sub('test_unity_','') => [:config_toolchain, :prepare_for_tests] do
4848
run_tests [f]
4949
end
5050
end
5151
end
5252

5353
desc "Test unity's helper scripts"
54-
task :scripts => [:prepare_for_tests] do
54+
task :scripts => [:config_toolchain, :prepare_for_tests] do
5555
begin
5656
Dir['tests/test_*.rb'].each do |scriptfile|
5757
require "./"+scriptfile
@@ -66,27 +66,27 @@ namespace :test do
6666
end
6767

6868
desc "Test unity triggered from make"
69-
task :make => [:prepare_for_tests] do
69+
task :make => [:config_toolchain, :prepare_for_tests] do
7070
run_make_tests()
7171
end
7272

7373
desc "Test unity fixture addon"
74-
task :fixture => [:prepare_for_tests] do
74+
task :fixture => [:config_toolchain, :prepare_for_tests] do
7575
test_fixtures()
7676
end
7777

7878
desc "Test unity memory addon"
79-
task :memory => [:prepare_for_tests] do
79+
task :memory => [:config_toolchain, :prepare_for_tests] do
8080
test_memory()
8181
end
8282

8383
desc "Test unity examples"
84-
task :examples => [:prepare_for_tests] do
84+
task :examples => [:config_toolchain, :prepare_for_tests] do
8585
run_examples
8686
end
8787

8888
desc "Run all rspecs"
89-
task :spec => [:prepare_for_tests] do
89+
task :spec => [:config_toolchain, :prepare_for_tests] do
9090
output = execute("rspec spec/**/*_spec.rb", true)
9191
rspec_ok = $?.exitstatus.zero?
9292
report output
@@ -115,7 +115,11 @@ task :default => [:clobber, :all]
115115

116116
desc "Load configuration"
117117
task :config, :config_file do |t, args|
118-
configure_toolchain(args[:config_file])
118+
$unity_test_config_file = args[:config_file]
119+
end
120+
121+
task :config_toolchain do
122+
configure_toolchain($unity_test_config_file)
119123
end
120124

121125
task :no_color do

test/rakefile_helper.rb

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,19 @@
1313

1414
module RakefileHelpers
1515
C_EXTENSION = '.c'.freeze
16+
1617
def load_configuration(config_file)
1718
return if $configured
1819

19-
if config_file =~ /[\\|\/]/
20-
$cfg_file = config_file
20+
$cfg_file_base = config_file
21+
cfg_file = if config_file =~ /[\\|\/]/
22+
$unity_test_config_file_in_targets = false
23+
config_file
2124
else
22-
$cfg_file_base = config_file
23-
$cfg_file = "targets/#{config_file}"
25+
$unity_test_config_file_in_targets = true
26+
"targets/#{config_file}"
2427
end
25-
$cfg = YamlHelper.load_file($cfg_file)
28+
$cfg = YamlHelper.load_file(cfg_file)
2629
$cfg[:paths] ||= {}
2730
$cfg[:paths][:test] = (Array($cfg[:paths][:test]) + ['src/', '../src/', 'testdata/', 'tests/']).uniq
2831
$colour_output = false unless $cfg['colour']
@@ -418,11 +421,22 @@ def run_make_tests()
418421
def run_examples()
419422
report "\nRunning Unity Examples"
420423
total_tests = total_ignored = 0
421-
[
422-
"cd ../examples/example_1 && make -s ci",
423-
"cd ../examples/example_2 && make -s ci",
424-
"cd ../examples/example_3 && rake config[#{$cfg_file_base || 'gcc_64'}] default"
425-
].each do |cmd|
424+
425+
# If we're set up to use gcc, the makefiles should work too. otherwise, just run example 3
426+
examples = if $cfg_file_base.nil? || ($cfg_file_base =~ /gcc/)
427+
[
428+
"cd ../examples/example_1 && make -s ci",
429+
"cd ../examples/example_2 && make -s ci"
430+
]
431+
else
432+
[]
433+
end + if $unity_test_config_file_in_targets
434+
["cd ../examples/example_3 && rake config[#{$cfg_file_base}] default"]
435+
else
436+
["cd ../examples/example_3 && rake config[\"../#{$unity_test_config_file}\"] default"]
437+
end
438+
439+
examples.each do |cmd|
426440
execute(cmd, false).each_line do |line|
427441
if line =~ /(\d+) Tests \d+ Failures (\d+) Ignored/
428442
total_tests += Regexp.last_match(1).to_i

test/tests/test_generate_test_runner.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,9 +1241,6 @@
12411241
]
12421242

12431243
def runner_test(test, runner, expected, test_defines, cmdline_args, features)
1244-
# Tack on TEST define for compiling unit tests
1245-
load_configuration($cfg_file)
1246-
12471244
# Drop Out if we're skipping this type of test
12481245
if $cfg[:skip_tests] && features
12491246
if $cfg[:skip_tests].include?(:parameterized) && features.include?(:parameterized)

0 commit comments

Comments
 (0)