mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
Add examples to the automated testing in travis. Make err-on-fail optional on both examples (disabled during ci)
This commit is contained in:
@@ -19,3 +19,5 @@ install:
|
||||
|
||||
script:
|
||||
- cd test && rake ci
|
||||
- cd examples && cd make_example && make clean && make setup && make test
|
||||
- cd examples && cd temp_sensor && rake ci
|
||||
|
||||
@@ -14,7 +14,7 @@ all: setup test ${BUILD_DIR}/main run
|
||||
setup:
|
||||
mkdir -p ${BUILD_DIR}
|
||||
mkdir -p ${OBJ}
|
||||
ruby ../../scripts/create_makefile.rb
|
||||
ruby ../../scripts/create_makefile.rb --silent
|
||||
|
||||
clean:
|
||||
rm -rf ${BUILD_DIR}
|
||||
@@ -23,7 +23,7 @@ ${BUILD_DIR}/main: ${SRC_DIR}/main.c ${SRC_DIR}/foo.c
|
||||
${CC} $< -o $@
|
||||
|
||||
run:
|
||||
./build/main
|
||||
./build/main || true
|
||||
|
||||
test: setup
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ compiler:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- '../../src/'
|
||||
- '../../vendor/unity/src/'
|
||||
- '../../vendor/unity/examples/example_3/helper/'
|
||||
- './build/mocks/'
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
prefix: '-D'
|
||||
@@ -39,5 +39,6 @@ linker:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
:mock_path: ./build/mocks
|
||||
|
||||
colour: true
|
||||
|
||||
@@ -30,10 +30,10 @@ compiler:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- '../../src/'
|
||||
- '../../vendor/unity/src/'
|
||||
- '../../vendor/unity/examples/example_3/helper/'
|
||||
- './build/mocks/'
|
||||
- [*tools_root, 'arm\inc\']
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
@@ -88,4 +88,5 @@ simulator:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
:mock_path: ./build/mocks
|
||||
|
||||
|
||||
@@ -29,10 +29,10 @@ compiler:
|
||||
prefix: '-I'
|
||||
items:
|
||||
- 'src/'
|
||||
- '../src/'
|
||||
- '../vendor/unity/src/'
|
||||
- '../vendor/unity/examples/example_3/helper/'
|
||||
- 'mocks/'
|
||||
- '../../src/'
|
||||
- '../../vendor/unity/src/'
|
||||
- '../../vendor/unity/examples/example_3/helper/'
|
||||
- './build/mocks/'
|
||||
- [*tools_root, 'arm\inc\']
|
||||
- *unit_tests_path
|
||||
defines:
|
||||
@@ -77,4 +77,5 @@ simulator:
|
||||
:plugins: []
|
||||
:includes:
|
||||
- Types.h
|
||||
:mock_path: ./build/mocks
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ require './rakefile_helper'
|
||||
|
||||
include RakefileHelpers
|
||||
|
||||
REQUIRED_DIRS = [ './build', './build/mocks' ]
|
||||
REQUIRED_DIRS.each do |v|
|
||||
directory v
|
||||
end
|
||||
|
||||
# Load default configuration, for now
|
||||
DEFAULT_CONFIG_FILE = 'gcc.yml'
|
||||
configure_toolchain(DEFAULT_CONFIG_FILE)
|
||||
@@ -22,7 +27,7 @@ end
|
||||
|
||||
desc "Build and test Unity"
|
||||
task :all => [:clean, :unit, :summary]
|
||||
task :default => [:clobber, :all]
|
||||
task :default => REQUIRED_DIRS + [:clobber, :all]
|
||||
task :ci => [:default]
|
||||
task :cruise => [:default]
|
||||
|
||||
@@ -30,3 +35,8 @@ desc "Load configuration"
|
||||
task :config, :config_file do |t, args|
|
||||
configure_toolchain(args[:config_file])
|
||||
end
|
||||
|
||||
desc "Return error on Failures"
|
||||
task :strict do
|
||||
$return_error_on_failures = true
|
||||
end
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
require 'yaml'
|
||||
require 'fileutils'
|
||||
require '../vendor/unity/auto/unity_test_summary'
|
||||
require '../vendor/unity/auto/generate_test_runner'
|
||||
require '../vendor/unity/auto/colour_reporter'
|
||||
require '../../vendor/unity/auto/unity_test_summary'
|
||||
require '../../vendor/unity/auto/generate_test_runner'
|
||||
require '../../vendor/unity/auto/colour_reporter'
|
||||
|
||||
module RakefileHelpers
|
||||
|
||||
$return_error_on_failures = false
|
||||
|
||||
C_EXTENSION = '.c'
|
||||
|
||||
def load_configuration(config_file)
|
||||
@@ -145,11 +147,11 @@ module RakefileHelpers
|
||||
return {:command => command, :pre_support => pre_support, :post_support => post_support}
|
||||
end
|
||||
|
||||
def execute(command_string, verbose=true)
|
||||
def execute(command_string, verbose=true, ok_to_fail=false)
|
||||
report command_string
|
||||
output = `#{command_string}`.chomp
|
||||
report(output) if (verbose && !output.nil? && (output.length > 0))
|
||||
if $?.exitstatus != 0
|
||||
unless $?.exitstatus.zero? || ok_to_fail
|
||||
raise "Command failed. (Returned #{$?.exitstatus})"
|
||||
end
|
||||
return output
|
||||
@@ -157,13 +159,13 @@ module RakefileHelpers
|
||||
|
||||
def report_summary
|
||||
summary = UnityTestSummary.new
|
||||
summary.set_root_path(HERE)
|
||||
summary.root = HERE
|
||||
results_glob = "#{$cfg['compiler']['build_path']}*.test*"
|
||||
results_glob.gsub!(/\\/, '/')
|
||||
results = Dir[results_glob]
|
||||
summary.set_targets(results)
|
||||
summary.targets = results
|
||||
report summary.run
|
||||
raise "There were failures" if (summary.failures > 0)
|
||||
raise "There were failures" if (summary.failures > 0) && $return_error_on_failures
|
||||
end
|
||||
|
||||
def run_tests(test_files)
|
||||
@@ -188,7 +190,7 @@ module RakefileHelpers
|
||||
|
||||
#create mocks if needed
|
||||
if (header =~ /Mock/)
|
||||
require "../lib/cmock.rb"
|
||||
require "../../lib/cmock.rb"
|
||||
@cmock ||= CMock.new($cfg_file)
|
||||
@cmock.setup_mocks([$cfg['compiler']['source_path']+header.gsub('Mock','')])
|
||||
end
|
||||
@@ -231,7 +233,7 @@ module RakefileHelpers
|
||||
else
|
||||
cmd_str = "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}"
|
||||
end
|
||||
output = execute(cmd_str)
|
||||
output = execute(cmd_str, true, true)
|
||||
test_results = $cfg['compiler']['build_path'] + test_base
|
||||
if output.match(/OK$/m).nil?
|
||||
test_results += '.testfail'
|
||||
|
||||
@@ -27,6 +27,8 @@ end
|
||||
|
||||
all_headers_to_mock = []
|
||||
|
||||
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT")
|
||||
|
||||
File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
|
||||
# Define make variables
|
||||
@@ -103,7 +105,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
end
|
||||
end
|
||||
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
|
||||
all_headers_to_mock += headers_to_mock
|
||||
mock_objs = headers_to_mock.map do |hdr|
|
||||
@@ -149,7 +151,7 @@ File.open(TEST_MAKEFILE, "w") do |mkfile|
|
||||
|
||||
# Create test summary task
|
||||
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 ".PHONY: test_summary"
|
||||
mkfile.puts ""
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
|
||||
suppress_error = !ARGV.nil? && !ARGV.empty? && (ARGV[0].upcase == "--SILENT")
|
||||
|
||||
require "#{ENV['UNITY_DIR']}/auto/unity_test_summary.rb"
|
||||
|
||||
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"]
|
||||
parser = UnityTestSummary.new
|
||||
parser.set_targets(results)
|
||||
parser.targets = results
|
||||
parser.run
|
||||
puts parser.report
|
||||
exit(parser.failures)
|
||||
exit(parser.failures) unless suppress_error
|
||||
|
||||
@@ -162,11 +162,11 @@ module RakefileHelpers
|
||||
|
||||
def report_summary
|
||||
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.gsub!(/\\/, '/')
|
||||
results = Dir[results_glob]
|
||||
summary.set_targets(results)
|
||||
summary.targets = results
|
||||
summary.run
|
||||
fail_out "FAIL: There were failures" if (summary.failures > 0)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user