| 1 |
# ============================================================================== |
| 2 |
# CMock Project - Automatic Mock Generation for C |
| 3 |
# Copyright (c) 2007-2014 Mike Karlesky, Mark VanderVoord, Greg Williams |
| 4 |
# [Released under MIT License. Please refer to license.txt for details] |
| 5 |
# ============================================================================== |
| 6 |
|
| 7 |
require '../config/test_environment' |
| 8 |
require 'rake' |
| 9 |
require 'rake/clean' |
| 10 |
require 'rake/testtask' |
| 11 |
require './rakefile_helper' |
| 12 |
|
| 13 |
include RakefileHelpers |
| 14 |
|
| 15 |
DEFAULT_CONFIG_FILE = 'gcc.yml' |
| 16 |
CMOCK_TEST_ROOT = File.expand_path(File.dirname(__FILE__)) |
| 17 |
|
| 18 |
SYSTEM_TEST_SUPPORT_DIRS = [ |
| 19 |
File.join(CMOCK_TEST_ROOT, 'system/generated'), |
| 20 |
File.join(CMOCK_TEST_ROOT, 'system/build') |
| 21 |
] |
| 22 |
|
| 23 |
SYSTEM_TEST_SUPPORT_DIRS.each do |dir| |
| 24 |
directory(dir) |
| 25 |
CLOBBER.include(dir) |
| 26 |
end |
| 27 |
|
| 28 |
|
| 29 |
task :prep_system_tests => SYSTEM_TEST_SUPPORT_DIRS |
| 30 |
|
| 31 |
configure_clean |
| 32 |
configure_toolchain(DEFAULT_CONFIG_FILE) |
| 33 |
|
| 34 |
task :default => [:test] |
| 35 |
task :ci => [:no_color, :default, 'test:examples', 'style:check'] |
| 36 |
task :cruise => :ci |
| 37 |
|
| 38 |
desc "Load configuration" |
| 39 |
task :config, :config_file do |t, args| |
| 40 |
args = {:config_file => DEFAULT_CONFIG_FILE} if args[:config_file].nil? |
| 41 |
args = {:config_file => args[:config_file] + '.yml'} unless args[:config_file] =~ /\.yml$/i |
| 42 |
configure_toolchain(args[:config_file]) |
| 43 |
end |
| 44 |
|
| 45 |
# Still support testing everything with just 'test' but switch default to ceedling-like test:all |
| 46 |
task :test => ['test:all'] |
| 47 |
|
| 48 |
namespace :test do |
| 49 |
desc "Run all unit, c, and system tests" |
| 50 |
task :all => [:clobber, :prep_system_tests, 'test:units', 'test:c', 'test:system'] |
| 51 |
|
| 52 |
desc "Run Unit Tests" |
| 53 |
Rake::TestTask.new('units') do |t| |
| 54 |
t.pattern = 'unit/*_test.rb' |
| 55 |
t.verbose = true |
| 56 |
end |
| 57 |
|
| 58 |
#individual unit tests |
| 59 |
FileList['unit/*_test.rb'].each do |test| |
| 60 |
Rake::TestTask.new(File.basename(test,'.*').sub('_test','')) do |t| |
| 61 |
t.pattern = test |
| 62 |
t.verbose = true |
| 63 |
end |
| 64 |
end |
| 65 |
|
| 66 |
desc "Run C Unit Tests" |
| 67 |
task :c => [:prep_system_tests] do |
| 68 |
unless ($cfg['unsupported'].include? "C") |
| 69 |
build_and_test_c_files |
| 70 |
end |
| 71 |
end |
| 72 |
|
| 73 |
desc "Run System Tests" |
| 74 |
task :system => [:clobber, :prep_system_tests] do |
| 75 |
#get a list of all system tests, removing unsupported tests for this compiler |
| 76 |
sys_unsupported = $cfg['unsupported'].map {|a| 'system/test_interactions/'+a+'.yml'} |
| 77 |
sys_tests_to_run = FileList['system/test_interactions/*.yml'] - sys_unsupported |
| 78 |
compile_unsupported = $cfg['unsupported'].map {|a| SYSTEST_COMPILE_MOCKABLES_PATH+a+'.h'} |
| 79 |
compile_tests_to_run = FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'] - compile_unsupported |
| 80 |
unless (sys_unsupported.empty? and compile_unsupported.empty?) |
| 81 |
report "\nIgnoring these system tests..." |
| 82 |
sys_unsupported.each {|a| report a} |
| 83 |
compile_unsupported.each {|a| report a} |
| 84 |
end |
| 85 |
report "\nRunning system tests..." |
| 86 |
tests_failed = run_system_test_interactions(sys_tests_to_run) |
| 87 |
raise "System tests failed." if (tests_failed > 0) |
| 88 |
|
| 89 |
run_system_test_compilations(compile_tests_to_run) |
| 90 |
end |
| 91 |
|
| 92 |
desc "Test cmock examples" |
| 93 |
task :examples => [:prep_system_tests] do |
| 94 |
run_examples() |
| 95 |
end |
| 96 |
|
| 97 |
#individual system tests |
| 98 |
FileList['system/test_interactions/*.yml'].each do |test| |
| 99 |
basename = File.basename(test,'.*') |
| 100 |
#desc "Run system test #{basename}" |
| 101 |
task basename do |
| 102 |
run_system_test_interactions([test]) |
| 103 |
end |
| 104 |
end |
| 105 |
|
| 106 |
desc "Profile Mock Generation" |
| 107 |
task :profile => [:clobber, :prep_system_tests] do |
| 108 |
run_system_test_profiles(FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h']) |
| 109 |
end |
| 110 |
end |
| 111 |
|
| 112 |
task :no_color do |
| 113 |
$colour_output = false |
| 114 |
end |
| 115 |
|
| 116 |
################### CODING STYLE VALIDATION |
| 117 |
namespace :style do |
| 118 |
desc "Check style" |
| 119 |
task :check do |
| 120 |
report "\nVERIFYING RUBY STYLE" |
| 121 |
report execute("rubocop ../lib ../examples ../config ../scripts --config ../vendor/unity/test/.rubocop.yml", true) |
| 122 |
report "Styling Ruby:PASS" |
| 123 |
end |
| 124 |
|
| 125 |
desc "Fix Style of all C Code" |
| 126 |
task :c do |
| 127 |
run_astyle("../src/*.* ../extras/fixture/src/*.*") |
| 128 |
end |
| 129 |
|
| 130 |
desc "Attempt to Autocorrect style" |
| 131 |
task :auto => ['style:clean'] do |
| 132 |
report execute("rubocop ../lib ../examples ../config ../scripts --auto-correct --config ../vendor/unity/test/.rubocop.yml", true) |
| 133 |
report "Autocorrected What We Could." |
| 134 |
end |
| 135 |
|
| 136 |
desc "Update style todo list" |
| 137 |
task :todo => ['style:clean'] do |
| 138 |
report execute("rubocop ../lib ../examples ../config ../scripts --auto-gen-config --config ../vendor/unity/test/.rubocop.yml", true) |
| 139 |
report "Updated Style TODO List." |
| 140 |
end |
| 141 |
|
| 142 |
task :clean do |
| 143 |
File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml") |
| 144 |
end |
| 145 |
end |
| 146 |
|
| 147 |
task :style => ['style:check'] |