rakefile.rb 2.1 KB
Newer Older
1 2 3 4 5 6 7 8
$here = File.expand_path( File.dirname( __FILE__ ) )

require 'rake/clean'
require 'rake/loaders/makefile'
require 'fileutils'
require 'set'
require '../auto/unity_test_summary'
require '../auto/generate_test_runner'
9 10

#USE THIS ONE IF YOU WANT TO TRY THIS WITH GCC
11
require 'rakefile_helper_GCC'
12 13

#USE THIS ONE IF YOU WANT TO TRY THIS WITH IAR
14
#require 'rakefile_helper_IAR'
15 16 17

include RakefileHelpers

18
#This tells us where to clean our temporary files
19 20
CLEAN.include('build/*')

21 22
#This is what is run when you type rake with no params
desc "Build and run all tests, then output results (you can just type \"rake\" to get this)."
23 24
task :default => [:clobber, :all, :summary]

25
#This runs our test summary
26 27 28 29 30 31 32 33
task :summary do
  flush_output
  summary = UnityTestSummary.new
  summary.set_root_path($here)
  summary.set_targets(Dir[BUILD_PATH+'/*.test*'])
  summary.run
end

34
#This builds and runs all the unit tests
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
task :all do
  puts "Starting Test Suite"
  runner_generator = UnityTestRunnerGenerator.new
  test_sets = {}
  
  #compile unity files
  Dir[UNITY_PATH+'/*.c'].each do |file|
    compile(file, BUILD_PATH+'/'+File.basename(file).gsub('.c', OBJ_EXTENSION))
  end
  
  #compile source files
  Dir[SOURCE_PATH+'/*.c'].each do |file|
    compile(file, BUILD_PATH+'/'+File.basename(file).gsub('.c', OBJ_EXTENSION))
  end
  
  #compile test files
  Dir[UNIT_TEST_PATH+'/*.c'].each do |file|
    compile(file, BUILD_PATH+'/'+File.basename(file).gsub('.c', OBJ_EXTENSION))
  end
  
  #compile runner files
  Dir[UNIT_TEST_PATH+'/*.c'].each do |file|
    run_file = BUILD_PATH+'/'+File.basename(file).gsub('.c','_Runner.c')
    test_set = runner_generator.run(file, run_file)
    compile(run_file, run_file.gsub('.c', OBJ_EXTENSION))
    test_sets[run_file.gsub('_Runner.c', BIN_EXTENSION)] = test_set.map {|req_file| BUILD_PATH + '/' + File.basename(req_file).gsub(/\.[c|h]/, OBJ_EXTENSION)}
  end
  
  #link and run each test
  test_sets.each_pair do |exe_file, obj_files|
    link(obj_files, exe_file)
    write_result_file(exe_file, run_test(exe_file))
  end
end