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
7UNITY_ROOT = File.expand_path(File.dirname(__FILE__)) + '/'
8$verbose = false
9
10require 'rake'
11require 'rake/clean'
12require UNITY_ROOT + 'rakefile_helper'
13require 'rspec/core/rake_task'
14
15TEMP_DIRS = [
16	File.join(UNITY_ROOT, 'build'),
17	File.join(UNITY_ROOT, 'sandbox')
18]
19
20TEMP_DIRS.each do |dir|
21  directory(dir)
22  CLOBBER.include(dir)
23end
24
25task :prepare_for_tests => TEMP_DIRS
26
27include RakefileHelpers
28
29# Load proper GCC as defult configuration
30DEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml'
31configure_toolchain(DEFAULT_CONFIG_FILE)
32
33desc "Test unity with its own unit tests"
34task :unit => [:prepare_for_tests] do
35  run_tests unit_test_files
36end
37
38desc "Test unity's helper scripts"
39task :scripts => [:prepare_for_tests] do
40  Dir['tests/test_*.rb'].each do |scriptfile|
41    require "./"+scriptfile
42  end
43end
44
45desc "Run all rspecs"
46RSpec::Core::RakeTask.new(:spec) do |t|
47  t.pattern = 'spec/**/*_spec.rb'
48end
49
50desc "Generate test summary"
51task :summary do
52  report_summary
53end
54
55desc "Build and test Unity"
56task :all => [:clean, :prepare_for_tests, :scripts, :unit, :style, :summary]
57task :default => [:clobber, :all]
58task :ci => [:no_color, :default]
59task :cruise => [:no_color, :default]
60
61desc "Load configuration"
62task :config, :config_file do |t, args|
63  configure_toolchain(args[:config_file])
64end
65
66task :no_color do
67  $colour_output = false
68end
69
70task :verbose do
71  $verbose = true
72end
73
74namespace :style do
75  desc "Check style"
76  task :check do
77    report "\nVERIFYING RUBY STYLE"
78    report execute("rubocop ../auto ../examples ../extras --config .rubocop.yml", true)
79    report "Styling Ruby:PASS"
80  end
81
82  namespace :check do
83    Dir['../**/*.rb'].each do |f|
84      filename = File.basename(f, '.rb')
85      desc "Check Style of #{filename}"
86      task filename.to_sym => ['style:clean'] do
87        report execute("rubocop #{f} --color --config .rubocop.yml", true)
88        report "Style Checked for #{f}"
89      end
90    end
91  end
92
93  desc "Fix Style of all C Code"
94  task :c do
95    run_astyle("../src/*.* ../extras/fixture/src/*.*")
96  end
97
98  namespace :c do
99    Dir['../{src,extras/**}/*.{c,h}'].each do |f|
100      filename = File.basename(f)[0..-3]
101      desc "Check Style of #{filename}"
102      task filename.to_sym do
103        run_astyle f
104      end
105    end
106  end
107
108  desc "Attempt to Autocorrect style"
109  task :auto  => ['style:clean'] do
110    execute("rubocop ../auto ../examples ../extras --auto-correct --config .rubocop.yml")
111    report "Autocorrected What We Could."
112  end
113
114  desc "Update style todo list"
115  task :todo  => ['style:clean'] do
116    execute("rubocop ../auto ../examples ../extras --auto-gen-config --config .rubocop.yml")
117    report "Updated Style TODO List."
118  end
119
120  task :clean do
121    File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml")
122  end
123end
124
125task :style => ['style:check']
126