Changeset 480
- Timestamp:
- 01/24/07 14:21:55 (2 years ago)
- Files:
-
- branches/workorder_report_rename/script/run_tests (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/workorder_report_rename/script/run_tests
r464 r480 1 1 #!/usr/bin/env ruby 2 # Copyright © 2005 Norfello Ltd All Rights Reserved2 # Copyright © 2005-2007 Norfello Ltd All Rights Reserved 3 3 # See license agreement for additional rights 4 4 … … 9 9 10 10 # Check command line syntax 11 if ARGV.size < 1 11 if ARGV.size < 1 or ARGV.include?('-h') or ARGV.include?('--help') 12 12 puts "Usage: run_tests [TEST OPTION] [RUN OPTION]" 13 13 puts "\nTest options" … … 18 18 puts " DEFAULT Run remaining tests and stop on first failure or error." 19 19 puts " all Run all tests. Similar to `rake`." 20 puts " failed Run all failed tests." 20 puts " unknown Run all unknown tests. Can be used to finish an aborted 'all' run." 21 puts " failed Run all failed tests and stop on first failure or error." 21 22 puts " reset Reset state of selected tests." 22 23 puts " show Show state of selected tests." 24 puts "\nInstall gem 'term-ansicolor' for colorized output." 25 puts 23 26 exit 27 end 28 29 if not ['unit', 'functional', 'all'].include?(ARGV[0]) 30 puts "Invalid test option: #{ARGV[0]}" 31 exit 32 end 33 34 if ARGV[1] and not ['all', 'unknown', 'failed', 'reset', 'show'].include?(ARGV[1]) 35 puts "Invalid run option: #{ARGV[1]}" 36 exit 37 end 38 39 # Options for run_tests 40 test_opts = {} 41 42 # Try to load Term::ANSIColor, set run_tests option :color if successful 43 require 'rubygems' 44 begin 45 require_gem 'term-ansicolor' 46 include Term::ANSIColor 47 test_opts[:color] = true 48 rescue Gem::LoadError 24 49 end 25 50 … … 64 89 test.state = STATE_PASSED 65 90 passed_count += 1 66 puts "PASSED" 91 if options[:color] 92 print(green, "PASSED", reset, "\n") 93 else 94 puts("PASSED") 95 end 67 96 else 68 97 test.state = STATE_FAILED 69 puts "FAILED" 98 if options[:color] 99 print(bold, red, "FAILED", reset, "\n") 100 else 101 puts("FAILED") 102 end 70 103 messages << output 71 104 failed_count += 1 … … 86 119 end 87 120 88 puts "\nPASSED: #{passed_count} FAILED: #{failed_count} REMAINING: #{tests.size - passed_count - failed_count}" 121 if options[:color] 122 print("\n\n", green, "PASSED: #{passed_count} ", bold, red, "FAILED: #{failed_count} ", reset, yellow, "REMAINING: #{tests.size - passed_count - failed_count}\n", reset) 123 else 124 puts "\nPASSED: #{passed_count} FAILED: #{failed_count} REMAINING: #{tests.size - passed_count - failed_count}" 125 end 89 126 90 127 return failed_count != 0 ? 1 : 0 … … 103 140 end 104 141 142 # Method: TestDatabase#update 143 # --------------------------- 144 # Updates the tests from the given files. 145 # 146 # Removes the tests which do not exist in the given files, and adds the tests 147 # which exist in the given files but not in the database. Tests which are 148 # both in the given files and the current database are not changed. 149 # 150 # Parameters: 151 # ----------- 152 # files - A list of filenames. 153 # 105 154 def update(files) 106 for file in files 155 new_tests = [] 156 157 for file in files.sort 107 158 test_methods = find_test_methods(file) 108 test_methods.each { |method| 109 @tests << Test.new(file, method) if @tests.select { |test| (test.file == file and test.method == method) }.empty? 159 test_methods.sort.each { |method| 160 existing_test = @tests.select { |test| (test.file == file and test.method == method) }.first 161 new_tests << (existing_test or Test.new(file, method)) 110 162 } 111 @tests.flatten! 112 end 163 end 164 165 @tests = new_tests 113 166 end 114 167 … … 174 227 when 'all' 175 228 tests = db.select(base_paths, [STATE_FAILED, STATE_UNKNOWN, STATE_PASSED]) 176 exit_code = run_tests(tests, :stop_on_failure => false) 229 exit_code = run_tests(tests, test_opts) 230 when 'unknown': 231 tests = db.select(base_paths, [STATE_UNKNOWN]) 232 exit_code = run_tests(tests, test_opts) 177 233 when 'failed' 178 234 tests = db.select(base_paths, [STATE_FAILED]) 179 exit_code = run_tests(tests, :stop_on_failure => true) 235 test_opts[:stop_on_failure] = true 236 exit_code = run_tests(tests, test_opts) 180 237 when 'reset' 181 238 tests = db.select(base_paths, [STATE_FAILED, STATE_UNKNOWN, STATE_PASSED]) … … 183 240 when 'show' 184 241 tests = db.select(base_paths, [STATE_FAILED, STATE_UNKNOWN, STATE_PASSED]) 185 state_as_text = { 186 STATE_FAILED => 'FAILED', 187 STATE_UNKNOWN => 'UNKNOWN', 188 STATE_PASSED => 'PASSED' 189 } 242 if test_opts[:color] 243 state_as_text = { 244 STATE_FAILED => [bold, red, 'FAILED', reset], 245 STATE_UNKNOWN => [yellow, 'UNKNOWN', reset], 246 STATE_PASSED => [green, 'PASSED', reset] 247 } 248 else 249 state_as_text = { 250 STATE_FAILED => 'FAILED', 251 STATE_UNKNOWN => 'UNKNOWN', 252 STATE_PASSED => 'PASSED' 253 } 254 end 190 255 for test in tests 191 256 puts "#{state_as_text[test.state]} #{File.basename(test.file)}:#{test.method}" … … 193 258 else 194 259 tests = db.select(base_paths, [STATE_FAILED, STATE_UNKNOWN]) 195 exit_code = run_tests(tests, :stop_on_failure => true) 260 test_opts[:stop_on_failure] = true 261 exit_code = run_tests(tests, test_opts) 196 262 end 197 263