| 1 |
# ========================================== |
| 2 |
# Unity Project - A Test Framework for C |
| 3 |
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams |
| 4 |
# [Released under MIT License. Please refer to license.txt for details] |
| 5 |
# ========================================== |
| 6 |
|
| 7 |
$verbose = false |
| 8 |
$extra_paths = [] |
| 9 |
|
| 10 |
require 'rake' |
| 11 |
require 'rake/clean' |
| 12 |
require_relative 'rakefile_helper' |
| 13 |
require 'rspec/core/rake_task' |
| 14 |
|
| 15 |
TEMP_DIRS = [ |
| 16 |
File.join(__dir__, 'build'), |
| 17 |
File.join(__dir__, 'sandbox') |
| 18 |
] |
| 19 |
|
| 20 |
TEMP_DIRS.each do |dir| |
| 21 |
directory(dir) |
| 22 |
CLOBBER.include(dir) |
| 23 |
end |
| 24 |
|
| 25 |
task :prepare_for_tests => TEMP_DIRS |
| 26 |
|
| 27 |
include RakefileHelpers |
| 28 |
|
| 29 |
# Load proper GCC as defult configuration |
| 30 |
DEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml' |
| 31 |
configure_toolchain(DEFAULT_CONFIG_FILE) |
| 32 |
|
| 33 |
############# ALL THE SELF-TESTS WE CAN PERFORM |
| 34 |
namespace :test do |
| 35 |
desc "Build and test Unity" |
| 36 |
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'] |
| 38 |
|
| 39 |
desc "Test unity with its own unit tests" |
| 40 |
task :unit => [:prepare_for_tests] do |
| 41 |
run_tests unit_test_files |
| 42 |
end |
| 43 |
|
| 44 |
namespace :unit do |
| 45 |
unit_test_files.each do |f| |
| 46 |
desc "test this unit only" |
| 47 |
task File.basename(f,'.c').sub('test_unity_','') => [:prepare_for_tests] do |
| 48 |
run_tests [f] |
| 49 |
end |
| 50 |
end |
| 51 |
end |
| 52 |
|
| 53 |
desc "Test unity's helper scripts" |
| 54 |
task :scripts => [:prepare_for_tests] do |
| 55 |
Dir['tests/test_*.rb'].each do |scriptfile| |
| 56 |
require "./"+scriptfile |
| 57 |
end |
| 58 |
end |
| 59 |
|
| 60 |
desc "Test unity triggered from make" |
| 61 |
task :make => [:prepare_for_tests] do |
| 62 |
run_make_tests() |
| 63 |
end |
| 64 |
|
| 65 |
desc "Test unity fixture addon" |
| 66 |
task :fixture => [:prepare_for_tests] do |
| 67 |
test_fixtures() |
| 68 |
end |
| 69 |
|
| 70 |
desc "Test unity memory addon" |
| 71 |
task :memory => [:prepare_for_tests] do |
| 72 |
test_memory() |
| 73 |
end |
| 74 |
|
| 75 |
desc "Test unity examples" |
| 76 |
task :examples => [:prepare_for_tests] do |
| 77 |
execute("cd ../examples/example_1 && make -s ci", false) |
| 78 |
execute("cd ../examples/example_2 && make -s ci", false) |
| 79 |
execute("cd ../examples/example_3 && rake", false) |
| 80 |
end |
| 81 |
|
| 82 |
desc "Run all rspecs" |
| 83 |
RSpec::Core::RakeTask.new(:spec) do |t| |
| 84 |
t.pattern = 'spec/**/*_spec.rb' |
| 85 |
end |
| 86 |
|
| 87 |
desc "Generate test summary" |
| 88 |
task :summary do |
| 89 |
report_summary |
| 90 |
end |
| 91 |
end |
| 92 |
|
| 93 |
###################### Shorthand for many common tasks |
| 94 |
task :ci => ['test:ci'] |
| 95 |
task :all => ['test:all'] |
| 96 |
task :default => [:clobber, :all] |
| 97 |
|
| 98 |
desc "Load configuration" |
| 99 |
task :config, :config_file do |t, args| |
| 100 |
configure_toolchain(args[:config_file]) |
| 101 |
end |
| 102 |
|
| 103 |
task :no_color do |
| 104 |
$colour_output = false |
| 105 |
end |
| 106 |
|
| 107 |
task :verbose do |
| 108 |
$verbose = true |
| 109 |
end |
| 110 |
|
| 111 |
################### CODING STYLE VALIDATION |
| 112 |
namespace :style do |
| 113 |
desc "Check style" |
| 114 |
task :check do |
| 115 |
report "\nVERIFYING RUBY STYLE" |
| 116 |
report execute("rubocop ../auto ../examples ../extras --config .rubocop.yml", true) |
| 117 |
report "Styling Ruby:PASS" |
| 118 |
end |
| 119 |
|
| 120 |
namespace :check do |
| 121 |
Dir['../**/*.rb'].each do |f| |
| 122 |
filename = File.basename(f, '.rb') |
| 123 |
#desc "Check Style of #{filename}" |
| 124 |
task filename.to_sym => ['style:clean'] do |
| 125 |
report execute("rubocop #{f} --color --config .rubocop.yml", true) |
| 126 |
report "Style Checked for #{f}" |
| 127 |
end |
| 128 |
end |
| 129 |
end |
| 130 |
|
| 131 |
desc "Fix Style of all C Code" |
| 132 |
task :c do |
| 133 |
run_astyle("../src/*.* ../extras/fixture/src/*.*") |
| 134 |
end |
| 135 |
|
| 136 |
namespace :c do |
| 137 |
Dir['../{src,extras/**}/*.{c,h}'].each do |f| |
| 138 |
filename = File.basename(f)[0..-3] |
| 139 |
#desc "Check Style of #{filename}" |
| 140 |
task filename.to_sym do |
| 141 |
run_astyle f |
| 142 |
end |
| 143 |
end |
| 144 |
end |
| 145 |
|
| 146 |
desc "Attempt to Autocorrect style" |
| 147 |
task :auto => ['style:clean'] do |
| 148 |
execute("rubocop ../auto ../examples ../extras --auto-correct --config .rubocop.yml") |
| 149 |
report "Autocorrected What We Could." |
| 150 |
end |
| 151 |
|
| 152 |
desc "Update style todo list" |
| 153 |
task :todo => ['style:clean'] do |
| 154 |
execute("rubocop ../auto ../examples ../extras --auto-gen-config --config .rubocop.yml") |
| 155 |
report "Updated Style TODO List." |
| 156 |
end |
| 157 |
|
| 158 |
task :clean do |
| 159 |
File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml") |
| 160 |
end |
| 161 |
end |
| 162 |
|
| 163 |
task :style => ['style:check'] |