Add examples to the automated testing in travis. Make err-on-fail optional on both examples (disabled during ci)

This commit is contained in:
Mark VanderVoord
2017-04-07 22:22:38 -04:00
parent 07d6714fe2
commit bfdfe944b9
10 changed files with 53 additions and 31 deletions
+2
View File
@@ -19,3 +19,5 @@ install:
script: script:
- cd test && rake ci - cd test && rake ci
- cd examples && cd make_example && make clean && make setup && make test
- cd examples && cd temp_sensor && rake ci
+2 -2
View File
@@ -14,7 +14,7 @@ all: setup test ${BUILD_DIR}/main run
setup: setup:
mkdir -p ${BUILD_DIR} mkdir -p ${BUILD_DIR}
mkdir -p ${OBJ} mkdir -p ${OBJ}
ruby ../../scripts/create_makefile.rb ruby ../../scripts/create_makefile.rb --silent
clean: clean:
rm -rf ${BUILD_DIR} rm -rf ${BUILD_DIR}
@@ -23,7 +23,7 @@ ${BUILD_DIR}/main: ${SRC_DIR}/main.c ${SRC_DIR}/foo.c
${CC} $< -o $@ ${CC} $< -o $@
run: run:
./build/main ./build/main || true
test: setup test: setup
+5 -4
View File
@@ -9,10 +9,10 @@ compiler:
prefix: '-I' prefix: '-I'
items: items:
- 'src/' - 'src/'
- '../src/' - '../../src/'
- '../vendor/unity/src/' - '../../vendor/unity/src/'
- '../vendor/unity/examples/example_3/helper/' - '../../vendor/unity/examples/example_3/helper/'
- 'mocks/' - './build/mocks/'
- *unit_tests_path - *unit_tests_path
defines: defines:
prefix: '-D' prefix: '-D'
@@ -39,5 +39,6 @@ linker:
:plugins: [] :plugins: []
:includes: :includes:
- Types.h - Types.h
:mock_path: ./build/mocks
colour: true colour: true
+5 -4
View File
@@ -30,10 +30,10 @@ compiler:
prefix: '-I' prefix: '-I'
items: items:
- 'src/' - 'src/'
- '../src/' - '../../src/'
- '../vendor/unity/src/' - '../../vendor/unity/src/'
- '../vendor/unity/examples/example_3/helper/' - '../../vendor/unity/examples/example_3/helper/'
- 'mocks/' - './build/mocks/'
- [*tools_root, 'arm\inc\'] - [*tools_root, 'arm\inc\']
- *unit_tests_path - *unit_tests_path
defines: defines:
@@ -88,4 +88,5 @@ simulator:
:plugins: [] :plugins: []
:includes: :includes:
- Types.h - Types.h
:mock_path: ./build/mocks
+5 -4
View File
@@ -29,10 +29,10 @@ compiler:
prefix: '-I' prefix: '-I'
items: items:
- 'src/' - 'src/'
- '../src/' - '../../src/'
- '../vendor/unity/src/' - '../../vendor/unity/src/'
- '../vendor/unity/examples/example_3/helper/' - '../../vendor/unity/examples/example_3/helper/'
- 'mocks/' - './build/mocks/'
- [*tools_root, 'arm\inc\'] - [*tools_root, 'arm\inc\']
- *unit_tests_path - *unit_tests_path
defines: defines:
@@ -77,4 +77,5 @@ simulator:
:plugins: [] :plugins: []
:includes: :includes:
- Types.h - Types.h
:mock_path: ./build/mocks
+11 -1
View File
@@ -7,6 +7,11 @@ require './rakefile_helper'
include RakefileHelpers include RakefileHelpers
REQUIRED_DIRS = [ './build', './build/mocks' ]
REQUIRED_DIRS.each do |v|
directory v
end
# Load default configuration, for now # Load default configuration, for now
DEFAULT_CONFIG_FILE = 'gcc.yml' DEFAULT_CONFIG_FILE = 'gcc.yml'
configure_toolchain(DEFAULT_CONFIG_FILE) configure_toolchain(DEFAULT_CONFIG_FILE)
@@ -22,7 +27,7 @@ end
desc "Build and test Unity" desc "Build and test Unity"
task :all => [:clean, :unit, :summary] task :all => [:clean, :unit, :summary]
task :default => [:clobber, :all] task :default => REQUIRED_DIRS + [:clobber, :all]
task :ci => [:default] task :ci => [:default]
task :cruise => [:default] task :cruise => [:default]
@@ -30,3 +35,8 @@ desc "Load configuration"
task :config, :config_file do |t, args| task :config, :config_file do |t, args|
configure_toolchain(args[:config_file]) configure_toolchain(args[:config_file])
end end
desc "Return error on Failures"
task :strict do
$return_error_on_failures = true
end
+12 -10
View File
@@ -1,11 +1,13 @@
require 'yaml' require 'yaml'
require 'fileutils' require 'fileutils'
require '../vendor/unity/auto/unity_test_summary' require '../../vendor/unity/auto/unity_test_summary'
require '../vendor/unity/auto/generate_test_runner' require '../../vendor/unity/auto/generate_test_runner'
require '../vendor/unity/auto/colour_reporter' require '../../vendor/unity/auto/colour_reporter'
module RakefileHelpers module RakefileHelpers
$return_error_on_failures = false
C_EXTENSION = '.c' C_EXTENSION = '.c'
def load_configuration(config_file) def load_configuration(config_file)
@@ -145,11 +147,11 @@ module RakefileHelpers
return {:command => command, :pre_support => pre_support, :post_support => post_support} return {:command => command, :pre_support => pre_support, :post_support => post_support}
end end
def execute(command_string, verbose=true) def execute(command_string, verbose=true, ok_to_fail=false)
report command_string report command_string
output = `#{command_string}`.chomp output = `#{command_string}`.chomp
report(output) if (verbose && !output.nil? && (output.length > 0)) report(output) if (verbose && !output.nil? && (output.length > 0))
if $?.exitstatus != 0 unless $?.exitstatus.zero? || ok_to_fail
raise "Command failed. (Returned #{$?.exitstatus})" raise "Command failed. (Returned #{$?.exitstatus})"
end end
return output return output
@@ -157,13 +159,13 @@ module RakefileHelpers
def report_summary def report_summary
summary = UnityTestSummary.new summary = UnityTestSummary.new
summary.set_root_path(HERE) summary.root = HERE
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.targets = results
report summary.run report summary.run
raise "There were failures" if (summary.failures > 0) raise "There were failures" if (summary.failures > 0) && $return_error_on_failures
end end
def run_tests(test_files) def run_tests(test_files)
@@ -188,7 +190,7 @@ module RakefileHelpers
#create mocks if needed #create mocks if needed
if (header =~ /Mock/) if (header =~ /Mock/)
require "../lib/cmock.rb" require "../../lib/cmock.rb"
@cmock ||= CMock.new($cfg_file) @cmock ||= CMock.new($cfg_file)
@cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')]) @cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')])
end end
@@ -231,7 +233,7 @@ module RakefileHelpers
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
output = execute(cmd_str) output = execute(cmd_str, true, true)
test_results = $cfg['compiler']['build_path'] + test_base test_results = $cfg['compiler']['build_path'] + test_base
if output.match(/OK$/m).nil? if output.match(/OK$/m).nil?
test_results += '.testfail' test_results += '.testfail'
+4 -2
View File
@@ -27,6 +27,8 @@ end
all_headers_to_mock = [] all_headers_to_mock = []
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT")
File.open(TEST_MAKEFILE, "w") do |mkfile| File.open(TEST_MAKEFILE, "w") do |mkfile|
# Define make variables # Define make variables
@@ -103,7 +105,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
end end
end end
raise "Module header '#{name}' not found to mock!" unless header_to_mock raise "Module header '#{name}' not found to mock!" unless header_to_mock
headers_to_mock << header_to_mock headers_to_mock << header_to_mock
end end
all_headers_to_mock += headers_to_mock all_headers_to_mock += headers_to_mock
mock_objs = headers_to_mock.map do |hdr| mock_objs = headers_to_mock.map do |hdr|
@@ -149,7 +151,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
# Create test summary task # Create test summary task
mkfile.puts "test_summary:" mkfile.puts "test_summary:"
mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/test_summary.rb" mkfile.puts "\t@UNITY_DIR=${UNITY_DIR} ruby ${CMOCK_DIR}/scripts/test_summary.rb #{suppress_error ? '--silent' : ''}"
mkfile.puts "" mkfile.puts ""
mkfile.puts ".PHONY: test_summary" mkfile.puts ".PHONY: test_summary"
mkfile.puts "" mkfile.puts ""
+5 -2
View File
@@ -1,3 +1,6 @@
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT")
require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb" require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb"
build_dir = ENV.fetch('BUILD_DIR', './build') build_dir = ENV.fetch('BUILD_DIR', './build')
@@ -5,7 +8,7 @@ test_build_dir = ENV.fetch('TEST_BUILD_DIR', File.join(build_dir, 'test'))
results = Dir["#{test_build_dir}/*.result"] results = Dir["#{test_build_dir}/*.result"]
parser = UnityTestSummary.new parser = UnityTestSummary.new
parser.set_targets(results) parser.targets = results
parser.run parser.run
puts parser.report puts parser.report
exit(parser.failures) exit(parser.failures) unless suppress_error
+2 -2
View File
@@ -162,11 +162,11 @@ module RakefileHelpers
def report_summary def report_summary
summary = UnityTestSummary.new summary = UnityTestSummary.new
summary.set_root_path(File.expand_path(File.dirname(__FILE__)) + '/') summary.root = File.expand_path(File.dirname(__FILE__)) + '/'
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.targets = results
summary.run summary.run
fail_out "FAIL: There were failures" if (summary.failures > 0) fail_out "FAIL: There were failures" if (summary.failures > 0)
end end