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 # ==============================================================================
7 require '../config/test_environment'
10 require 'rake/testtask'
11 require './rakefile_helper'
13 include RakefileHelpers
15 DEFAULT_CONFIG_FILE = 'gcc.yml'
16 CMOCK_TEST_ROOT = File.expand_path(File.dirname(__FILE__))
18 SYSTEM_TEST_SUPPORT_DIRS = [
19 File.join(CMOCK_TEST_ROOT, 'system/generated'),
20 File.join(CMOCK_TEST_ROOT, 'system/build')
23 SYSTEM_TEST_SUPPORT_DIRS.each do |dir|
29 task :prep_system_tests => SYSTEM_TEST_SUPPORT_DIRS
32 configure_toolchain(DEFAULT_CONFIG_FILE)
34 task :default => [:test]
35 task :ci => [:no_color, :default, 'test:examples', 'style:check']
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])
45 # Still support testing everything with just 'test' but switch default to ceedling-like test:all
46 task :test => ['test:all']
49 desc "Run all unit, c, and system tests"
50 task :all => [:clobber, :prep_system_tests, 'test:units', 'test:c', 'test:system']
53 Rake::TestTask.new('units') do |t|
54 t.pattern = 'unit/*_test.rb'
58 #individual unit tests
59 FileList['unit/*_test.rb'].each do |test|
60 Rake::TestTask.new(File.basename(test,'.*').sub('_test','')) do |t|
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
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}
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)
89 run_system_test_compilations(compile_tests_to_run)
92 desc "Test cmock examples"
93 task :examples => [:prep_system_tests] do
97 #individual system tests
98 FileList['system/test_interactions/*.yml'].each do |test|
99 basename = File.basename(test,'.*')
100 #desc "Run system test #{basename}"
102 run_system_test_interactions([test])
106 desc "Profile Mock Generation"
107 task :profile => [:clobber, :prep_system_tests] do
108 run_system_test_profiles(FileList[SYSTEST_COMPILE_MOCKABLES_PATH + '*.h'])
113 $colour_output = false
116 ################### CODING STYLE VALIDATION
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"
125 desc "Fix Style of all C Code"
127 run_astyle("../src/*.* ../extras/fixture/src/*.*")
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."
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."
143 File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml")
147 task :style => ['style:check']