135375f98Sopenharmony_ci# ==========================================
235375f98Sopenharmony_ci#   Unity Project - A Test Framework for C
335375f98Sopenharmony_ci#   Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
435375f98Sopenharmony_ci#   [Released under MIT License. Please refer to license.txt for details]
535375f98Sopenharmony_ci# ==========================================
635375f98Sopenharmony_ci
735375f98Sopenharmony_ci$verbose = false
835375f98Sopenharmony_ci$extra_paths = []
935375f98Sopenharmony_ci
1035375f98Sopenharmony_cirequire 'rake'
1135375f98Sopenharmony_cirequire 'rake/clean'
1235375f98Sopenharmony_cirequire_relative 'rakefile_helper'
1335375f98Sopenharmony_cirequire 'rspec/core/rake_task'
1435375f98Sopenharmony_ci
1535375f98Sopenharmony_ciTEMP_DIRS = [
1635375f98Sopenharmony_ci	File.join(__dir__, 'build'),
1735375f98Sopenharmony_ci	File.join(__dir__, 'sandbox')
1835375f98Sopenharmony_ci]
1935375f98Sopenharmony_ci
2035375f98Sopenharmony_ciTEMP_DIRS.each do |dir|
2135375f98Sopenharmony_ci  directory(dir)
2235375f98Sopenharmony_ci  CLOBBER.include(dir)
2335375f98Sopenharmony_ciend
2435375f98Sopenharmony_ci
2535375f98Sopenharmony_citask :prepare_for_tests => TEMP_DIRS
2635375f98Sopenharmony_ci
2735375f98Sopenharmony_ciinclude RakefileHelpers
2835375f98Sopenharmony_ci
2935375f98Sopenharmony_ci# Load proper GCC as defult configuration
3035375f98Sopenharmony_ciDEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml'
3135375f98Sopenharmony_ciconfigure_toolchain(DEFAULT_CONFIG_FILE)
3235375f98Sopenharmony_ci
3335375f98Sopenharmony_ci############# ALL THE SELF-TESTS WE CAN PERFORM
3435375f98Sopenharmony_cinamespace :test do
3535375f98Sopenharmony_ci  desc "Build and test Unity"
3635375f98Sopenharmony_ci  task :all => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:fixture', 'test:memory', 'test:summary']
3735375f98Sopenharmony_ci  task :ci => [:clean, :prepare_for_tests, 'test:scripts', 'test:unit', :style, 'test:make', 'test:fixture', 'test:memory', 'test:summary']
3835375f98Sopenharmony_ci
3935375f98Sopenharmony_ci  desc "Test unity with its own unit tests"
4035375f98Sopenharmony_ci  task :unit => [:prepare_for_tests] do
4135375f98Sopenharmony_ci    run_tests unit_test_files
4235375f98Sopenharmony_ci  end
4335375f98Sopenharmony_ci
4435375f98Sopenharmony_ci  namespace :unit do
4535375f98Sopenharmony_ci    unit_test_files.each do |f|
4635375f98Sopenharmony_ci      desc "test this unit only"
4735375f98Sopenharmony_ci      task File.basename(f,'.c').sub('test_unity_','') => [:prepare_for_tests] do
4835375f98Sopenharmony_ci        run_tests [f]
4935375f98Sopenharmony_ci      end
5035375f98Sopenharmony_ci    end
5135375f98Sopenharmony_ci  end
5235375f98Sopenharmony_ci
5335375f98Sopenharmony_ci  desc "Test unity's helper scripts"
5435375f98Sopenharmony_ci  task :scripts => [:prepare_for_tests] do
5535375f98Sopenharmony_ci    Dir['tests/test_*.rb'].each do |scriptfile|
5635375f98Sopenharmony_ci      require "./"+scriptfile
5735375f98Sopenharmony_ci    end
5835375f98Sopenharmony_ci  end
5935375f98Sopenharmony_ci
6035375f98Sopenharmony_ci  desc "Test unity triggered from make"
6135375f98Sopenharmony_ci  task :make => [:prepare_for_tests] do
6235375f98Sopenharmony_ci    run_make_tests()
6335375f98Sopenharmony_ci  end
6435375f98Sopenharmony_ci
6535375f98Sopenharmony_ci  desc "Test unity fixture addon"
6635375f98Sopenharmony_ci  task :fixture => [:prepare_for_tests] do
6735375f98Sopenharmony_ci    test_fixtures()
6835375f98Sopenharmony_ci  end
6935375f98Sopenharmony_ci
7035375f98Sopenharmony_ci  desc "Test unity memory addon"
7135375f98Sopenharmony_ci  task :memory => [:prepare_for_tests] do
7235375f98Sopenharmony_ci    test_memory()
7335375f98Sopenharmony_ci  end
7435375f98Sopenharmony_ci
7535375f98Sopenharmony_ci  desc "Test unity examples"
7635375f98Sopenharmony_ci  task :examples => [:prepare_for_tests] do
7735375f98Sopenharmony_ci    execute("cd ../examples/example_1 && make -s ci", false)
7835375f98Sopenharmony_ci    execute("cd ../examples/example_2 && make -s ci", false)
7935375f98Sopenharmony_ci    execute("cd ../examples/example_3 && rake", false)
8035375f98Sopenharmony_ci  end
8135375f98Sopenharmony_ci
8235375f98Sopenharmony_ci  desc "Run all rspecs"
8335375f98Sopenharmony_ci  RSpec::Core::RakeTask.new(:spec) do |t|
8435375f98Sopenharmony_ci    t.pattern = 'spec/**/*_spec.rb'
8535375f98Sopenharmony_ci  end
8635375f98Sopenharmony_ci
8735375f98Sopenharmony_ci  desc "Generate test summary"
8835375f98Sopenharmony_ci  task :summary do
8935375f98Sopenharmony_ci    report_summary
9035375f98Sopenharmony_ci  end
9135375f98Sopenharmony_ciend
9235375f98Sopenharmony_ci
9335375f98Sopenharmony_ci###################### Shorthand for many common tasks
9435375f98Sopenharmony_citask :ci => ['test:ci']
9535375f98Sopenharmony_citask :all => ['test:all']
9635375f98Sopenharmony_citask :default => [:clobber, :all]
9735375f98Sopenharmony_ci
9835375f98Sopenharmony_cidesc "Load configuration"
9935375f98Sopenharmony_citask :config, :config_file do |t, args|
10035375f98Sopenharmony_ci  configure_toolchain(args[:config_file])
10135375f98Sopenharmony_ciend
10235375f98Sopenharmony_ci
10335375f98Sopenharmony_citask :no_color do
10435375f98Sopenharmony_ci  $colour_output = false
10535375f98Sopenharmony_ciend
10635375f98Sopenharmony_ci
10735375f98Sopenharmony_citask :verbose do
10835375f98Sopenharmony_ci  $verbose = true
10935375f98Sopenharmony_ciend
11035375f98Sopenharmony_ci
11135375f98Sopenharmony_ci################### CODING STYLE VALIDATION
11235375f98Sopenharmony_cinamespace :style do
11335375f98Sopenharmony_ci  desc "Check style"
11435375f98Sopenharmony_ci  task :check do
11535375f98Sopenharmony_ci    report "\nVERIFYING RUBY STYLE"
11635375f98Sopenharmony_ci    report execute("rubocop ../auto ../examples ../extras --config .rubocop.yml", true)
11735375f98Sopenharmony_ci    report "Styling Ruby:PASS"
11835375f98Sopenharmony_ci  end
11935375f98Sopenharmony_ci
12035375f98Sopenharmony_ci  namespace :check do
12135375f98Sopenharmony_ci    Dir['../**/*.rb'].each do |f|
12235375f98Sopenharmony_ci      filename = File.basename(f, '.rb')
12335375f98Sopenharmony_ci      #desc "Check Style of #{filename}"
12435375f98Sopenharmony_ci      task filename.to_sym => ['style:clean'] do
12535375f98Sopenharmony_ci        report execute("rubocop #{f} --color --config .rubocop.yml", true)
12635375f98Sopenharmony_ci        report "Style Checked for #{f}"
12735375f98Sopenharmony_ci      end
12835375f98Sopenharmony_ci    end
12935375f98Sopenharmony_ci  end
13035375f98Sopenharmony_ci
13135375f98Sopenharmony_ci  desc "Fix Style of all C Code"
13235375f98Sopenharmony_ci  task :c do
13335375f98Sopenharmony_ci    run_astyle("../src/*.* ../extras/fixture/src/*.*")
13435375f98Sopenharmony_ci  end
13535375f98Sopenharmony_ci
13635375f98Sopenharmony_ci  namespace :c do
13735375f98Sopenharmony_ci    Dir['../{src,extras/**}/*.{c,h}'].each do |f|
13835375f98Sopenharmony_ci      filename = File.basename(f)[0..-3]
13935375f98Sopenharmony_ci      #desc "Check Style of #{filename}"
14035375f98Sopenharmony_ci      task filename.to_sym do
14135375f98Sopenharmony_ci        run_astyle f
14235375f98Sopenharmony_ci      end
14335375f98Sopenharmony_ci    end
14435375f98Sopenharmony_ci  end
14535375f98Sopenharmony_ci
14635375f98Sopenharmony_ci  desc "Attempt to Autocorrect style"
14735375f98Sopenharmony_ci  task :auto  => ['style:clean'] do
14835375f98Sopenharmony_ci    execute("rubocop ../auto ../examples ../extras --auto-correct --config .rubocop.yml")
14935375f98Sopenharmony_ci    report "Autocorrected What We Could."
15035375f98Sopenharmony_ci  end
15135375f98Sopenharmony_ci
15235375f98Sopenharmony_ci  desc "Update style todo list"
15335375f98Sopenharmony_ci  task :todo  => ['style:clean'] do
15435375f98Sopenharmony_ci    execute("rubocop ../auto ../examples ../extras --auto-gen-config --config .rubocop.yml")
15535375f98Sopenharmony_ci    report "Updated Style TODO List."
15635375f98Sopenharmony_ci  end
15735375f98Sopenharmony_ci
15835375f98Sopenharmony_ci  task :clean do
15935375f98Sopenharmony_ci    File.delete(".rubocop_todo.yml") if File.exists?(".rubocop_todo.yml")
16035375f98Sopenharmony_ci  end
16135375f98Sopenharmony_ciend
16235375f98Sopenharmony_ci
16335375f98Sopenharmony_citask :style => ['style:check']
164