Class: Autotest
- Inherits:
-
Object
- Object
- Autotest
- Defined in:
- lib/autotest.rb,
lib/autotest/rails.rb,
lib/autotest/preload.rb
Overview
Autotest continuously scans the files in your project for changes and runs the appropriate tests. Test failures are run until they have all passed. Then the full test suite is run to ensure that nothing else was inadvertantly broken.
If you want Autotest to start over from the top, hit ^C once. If you want Autotest to quit, hit ^C twice.
Rails:
The autotest command will automatically discover a Rails directory by looking for config/environment.rb. When Rails is discovered, autotest uses RailsAutotest to perform file mappings and other work. See RailsAutotest for details.
Plugins:
Plugins are available by creating a .autotest file either in your project root or in your home directory. You can then write event handlers in the form of:
Autotest.add_hook hook_name { |autotest| ... }
The available hooks are listed in ALL_HOOKS.
See example_dot_autotest.rb for more details.
If a hook returns a true value, it signals to autotest that the hook was handled and should not continue executing hooks.
Naming:
Autotest uses a simple naming scheme to figure out how to map implementation files to test files following the Test::Unit naming scheme.
-
Test files must be stored in test/
-
Test files names must start with test_
-
Test class names must start with Test
-
Implementation files must be stored in lib/
-
Implementation files must match up with a test file named test_.*<impl-name>.rb
Strategy:
-
Find all files and associate them from impl <-> test.
-
Run all tests.
-
Scan for failures.
-
Detect changes in ANY (ruby?. file, rerun all failures + changed files.
-
Until 0 defects, goto 3.
-
When 0 defects, goto 2.
Defined Under Namespace
Modules: AutoUpdate, Bundler, Fixtures, Isolate, Migrate, Once, Preload, RCov, Rails, Restart, Timestamp
Constant Summary collapse
- TOPDIR =
Dir.pwd + "/"
- T0 =
Time.at 0
- ALL_HOOKS =
[ :all_good, :died, :initialize, :post_initialize, :interrupt, :quit, :ran_command, :reset, :run_command, :updated, :waiting ]
- HOOKS =
Hash.new { |h,k| h[k] = [] }
- WINDOZE =
- SEP =
WINDOZE ? '&' : ';'
Instance Attribute Summary collapse
-
#extra_class_map ⇒ Object
Returns the value of attribute extra_class_map.
-
#extra_files ⇒ Object
Returns the value of attribute extra_files.
-
#failures ⇒ Object
Returns the value of attribute failures.
-
#files_to_test ⇒ Object
TODO: remove in favor of failures?.
-
#find_directories ⇒ Object
Returns the value of attribute find_directories.
-
#find_order ⇒ Object
Returns the value of attribute find_order.
-
#interrupted ⇒ Object
Returns the value of attribute interrupted.
-
#known_files ⇒ Object
Lazy accessor for the known_files hash.
-
#last_mtime ⇒ Object
Returns the value of attribute last_mtime.
-
#libs ⇒ Object
Returns the value of attribute libs.
-
#options ⇒ Object
Returns the value of attribute options.
-
#output ⇒ Object
Returns the value of attribute output.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#sleep ⇒ Object
Returns the value of attribute sleep.
-
#tainted ⇒ Object
(also: #tainted?)
Returns the value of attribute tainted.
-
#test_mappings ⇒ Object
Returns the value of attribute test_mappings.
-
#test_prefix ⇒ Object
Returns the value of attribute test_prefix.
-
#testlib ⇒ Object
Returns the value of attribute testlib.
-
#wants_to_quit ⇒ Object
Returns the value of attribute wants_to_quit.
Class Method Summary collapse
-
.add_hook(name, &block) ⇒ Object
Add the supplied block to the available hooks, with the given name.
- .parse_options(args = ARGV) ⇒ Object
-
.run(args = ARGV) ⇒ Object
Initialize and run the system.
Instance Method Summary collapse
-
#add_exception(regexp) ⇒ Object
Adds
regexpto the list of exceptions for find_file. -
#add_mapping(regexp, prepend = false, &proc) ⇒ Object
Adds a file mapping, optionally prepending the mapping to the front of the list if
prependis true. -
#add_sigint_handler ⇒ Object
Installs a sigint handler.
-
#add_sigquit_handler ⇒ Object
Installs a sigquit handler.
-
#all_good ⇒ Object
If there are no files left to test (because they’ve all passed), then all is good.
- #class_map ⇒ Object
-
#clear_exceptions ⇒ Object
Clears the list of exceptions for find_file.
-
#clear_mappings ⇒ Object
Clears all file mappings.
- #debug ⇒ Object
-
#exceptions ⇒ Object
Return a compiled regexp of exceptions for find_files or nil if no filtering should take place.
-
#files_matching(regexp) ⇒ Object
Returns all known files in the codebase matching
regexp. -
#find_files ⇒ Object
Find the files to process, ignoring temporary files, source configuration management files, etc., and return a Hash mapping filename to modification time.
-
#find_files_to_test(files = find_files) ⇒ Object
Find the files which have been modified, update the recorded timestamps, and use this to update the files to test.
-
#get_to_green ⇒ Object
Keep running the tests after a change, until all pass.
-
#hook(name, *args) ⇒ Object
Call the event hook named
name, passing in optional args depending on the hook itself. -
#initialize(options) ⇒ Autotest
constructor
Initialize the instance and then load the user’s .autotest file, if any.
-
#make_test_cmd(files_to_test) ⇒ Object
Generate the commands to test the supplied files.
- #minitest_result(file, klass, method, fails, assertions, time) ⇒ Object
-
#minitest_start ⇒ Object
Server Methods:.
- #new_hash_of_arrays ⇒ Object
-
#old_path_to_classname ⇒ Object
Convert a path in a string, s, into a class name, changing underscores to CamelCase, etc.
-
#old_run_tests ⇒ Object
Look for files to test then run the tests and handle the results.
-
#path_to_classname(s) ⇒ Object
Convert the pathname s to the name of class.
-
#remove_exception(regexp) ⇒ Object
Removes
regexpto the list of exceptions for find_file. -
#remove_mapping(regexp) ⇒ Object
Removed a file mapping matching
regexp. - #reorder(files_to_test) ⇒ Object
-
#rerun_all_tests ⇒ Object
Rerun the tests from cold (reset state).
-
#reset ⇒ Object
Clear all state information about test failures and whether interrupts will kill autotest.
- #reset_find_order ⇒ Object
- #restart ⇒ Object
-
#ruby ⇒ Object
Determine and return the path of the ruby executable.
-
#ruby_cmd ⇒ Object
Returns the base of the ruby command.
-
#run ⇒ Object
Repeatedly run failed tests, then all tests, then wait for changes and carry on until killed.
-
#run_tests ⇒ Object
Look for files to test then run the tests and handle the results.
-
#test_files_for(filename) ⇒ Object
Return the name of the file with the tests for filename by finding a
test_mappingthat matches the file and executing the mapping’s proc. -
#wait_for_changes ⇒ Object
Sleep then look for files to test, until there are some.
Constructor Details
#initialize(options) ⇒ Autotest
Initialize the instance and then load the user’s .autotest file, if any.
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/autotest.rb', line 179 def initialize # these two are set directly because they're wrapped with # add/remove/clear accessor methods @exception_list = [] @child = nil self. = self.extra_class_map = {} self.extra_files = [] self.failures = Hash.new { |h,k| h[k] = Hash.new { |h2,k2| h2[k2] = [] } } self.files_to_test = new_hash_of_arrays reset_find_order self.libs = %w[. lib test].join(File::PATH_SEPARATOR) self.output = $stderr self.prefix = nil self.sleep = 1 self.test_mappings = [] self.test_prefix = "gem 'minitest'" self.testlib = "minitest/autorun" # TODO: rename self.find_directories = ['.'] # file in /lib -> run test in /test self.add_mapping(/^lib\/.*\.rb$/) do |filename, _| possible = File.basename(filename).gsub '_', '_?' files_matching %r%^test/.*#{possible}$% end # file in /test -> run it (ruby & rails styles) self.add_mapping(/^test.*\/(test_.*|.*_test)\.rb$/) do |filename, _| filename end default_configs = [File.('~/.autotest'), './.autotest'] configs = [:rc] || default_configs configs.each do |f| load f if File.exist? f end end |
Instance Attribute Details
#extra_class_map ⇒ Object
Returns the value of attribute extra_class_map.
156 157 158 |
# File 'lib/autotest.rb', line 156 def extra_class_map @extra_class_map end |
#extra_files ⇒ Object
Returns the value of attribute extra_files.
157 158 159 |
# File 'lib/autotest.rb', line 157 def extra_files @extra_files end |
#failures ⇒ Object
Returns the value of attribute failures.
158 159 160 |
# File 'lib/autotest.rb', line 158 def failures @failures end |
#files_to_test ⇒ Object
TODO: remove in favor of failures?
159 160 161 |
# File 'lib/autotest.rb', line 159 def files_to_test @files_to_test end |
#find_directories ⇒ Object
Returns the value of attribute find_directories.
160 161 162 |
# File 'lib/autotest.rb', line 160 def find_directories @find_directories end |
#find_order ⇒ Object
Returns the value of attribute find_order.
161 162 163 |
# File 'lib/autotest.rb', line 161 def find_order @find_order end |
#interrupted ⇒ Object
Returns the value of attribute interrupted.
162 163 164 |
# File 'lib/autotest.rb', line 162 def interrupted @interrupted end |
#known_files ⇒ Object
Lazy accessor for the known_files hash.
459 460 461 462 463 464 |
# File 'lib/autotest.rb', line 459 def known_files unless @known_files then @known_files = Hash[*find_order.map { |f| [f, true] }.flatten] end @known_files end |
#last_mtime ⇒ Object
Returns the value of attribute last_mtime.
163 164 165 |
# File 'lib/autotest.rb', line 163 def last_mtime @last_mtime end |
#libs ⇒ Object
Returns the value of attribute libs.
164 165 166 |
# File 'lib/autotest.rb', line 164 def libs @libs end |
#options ⇒ Object
Returns the value of attribute options.
69 70 71 |
# File 'lib/autotest.rb', line 69 def @options end |
#output ⇒ Object
Returns the value of attribute output.
165 166 167 |
# File 'lib/autotest.rb', line 165 def output @output end |
#prefix ⇒ Object
Returns the value of attribute prefix.
166 167 168 |
# File 'lib/autotest.rb', line 166 def prefix @prefix end |
#sleep ⇒ Object
Returns the value of attribute sleep.
167 168 169 |
# File 'lib/autotest.rb', line 167 def sleep @sleep end |
#tainted ⇒ Object Also known as: tainted?
Returns the value of attribute tainted.
168 169 170 |
# File 'lib/autotest.rb', line 168 def tainted @tainted end |
#test_mappings ⇒ Object
Returns the value of attribute test_mappings.
169 170 171 |
# File 'lib/autotest.rb', line 169 def test_mappings @test_mappings end |
#test_prefix ⇒ Object
Returns the value of attribute test_prefix.
171 172 173 |
# File 'lib/autotest.rb', line 171 def test_prefix @test_prefix end |
#testlib ⇒ Object
Returns the value of attribute testlib.
170 171 172 |
# File 'lib/autotest.rb', line 170 def testlib @testlib end |
#wants_to_quit ⇒ Object
Returns the value of attribute wants_to_quit.
172 173 174 |
# File 'lib/autotest.rb', line 172 def wants_to_quit @wants_to_quit end |
Class Method Details
.add_hook(name, &block) ⇒ Object
Add the supplied block to the available hooks, with the given name.
732 733 734 |
# File 'lib/autotest.rb', line 732 def self.add_hook name, &block HOOKS[name] << block end |
.parse_options(args = ARGV) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/autotest.rb', line 76 def self. args = ARGV require 'optparse' = { :args => args.dup } OptionParser.new do |opts| opts. = <<-BANNER.gsub(/^ /, '') Continuous testing for your ruby app. Autotest automatically tests code that has changed. It assumes the code is in lib, and tests are in test/test_*.rb. Autotest uses plugins to control what happens. You configure plugins with require statements in the .autotest file in your project base directory, and a default configuration for all your projects in the .autotest file in your home directory. Usage: autotest [options] BANNER opts.on "-d", "--debug", "Debug mode, for reporting bugs." do require "pp" [:debug] = true end opts.on "-f", "--focus", "Focus mode, only run named tests." do [:focus] = true end opts.on "-v", "--verbose", "Be annoyingly verbose (debugs .autotest)." do [:verbose] = true end opts.on "-q", "--quiet", "Be quiet." do [:quiet] = true end opts.on("-r", "--rc CONF", String, "Override path to config file") do |o| [:rc] = Array(o) end opts.on("-w", "--warnings", "Turn on ruby warnings") do $-w = true end opts.on "-h", "--help", "Show this." do puts opts exit 1 end end.parse! args end |
.run(args = ARGV) ⇒ Object
Initialize and run the system.
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/autotest.rb', line 134 def self.run args = ARGV = PathExpander.new args, "**/*.rb" files = .process.to_a autotest = new args if autotest.[:debug] then puts puts "options:" puts pp autotest. puts "files:" puts pp files puts end autotest.extra_files = files autotest.run end |
Instance Method Details
#add_exception(regexp) ⇒ Object
Adds regexp to the list of exceptions for find_file. This must be called before the exceptions are compiled.
658 659 660 661 662 663 |
# File 'lib/autotest.rb', line 658 def add_exception regexp raise "exceptions already compiled" if defined? @exceptions @exception_list << regexp nil end |
#add_mapping(regexp, prepend = false, &proc) ⇒ Object
Adds a file mapping, optionally prepending the mapping to the front of the list if prepend is true. regexp should match a file path in the codebase. proc is passed a matched filename and Regexp.last_match. proc should return an array of tests to run.
For example, if test_helper.rb is modified, rerun all tests:
at.add_mapping(/test_helper.rb/) do |f, _|
at.files_matching(/^test.*rb$/)
end
622 623 624 625 626 627 628 629 |
# File 'lib/autotest.rb', line 622 def add_mapping regexp, prepend = false, &proc if prepend then @test_mappings.unshift [regexp, proc] else @test_mappings.push [regexp, proc] end nil end |
#add_sigint_handler ⇒ Object
Installs a sigint handler.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 |
# File 'lib/autotest.rb', line 323 def add_sigint_handler trap 'INT' do Process.kill "KILL", @child if @child if self.interrupted then self.wants_to_quit = true else unless hook :interrupt then puts "Interrupt a second time to quit" self.interrupted = true Kernel.sleep 1.5 end raise Interrupt, nil # let the run loop catch it end end end |
#add_sigquit_handler ⇒ Object
Installs a sigquit handler
343 344 345 346 347 |
# File 'lib/autotest.rb', line 343 def add_sigquit_handler trap 'QUIT' do restart end end |
#all_good ⇒ Object
If there are no files left to test (because they’ve all passed), then all is good.
372 373 374 |
# File 'lib/autotest.rb', line 372 def all_good failures.empty? end |
#class_map ⇒ Object
235 236 237 238 239 240 241 |
# File 'lib/autotest.rb', line 235 def class_map class_map = Hash[*self.find_order.grep(/^test/).map { |f| # TODO: ugly [path_to_classname(f), f] }.flatten] class_map.merge! self.extra_class_map class_map end |
#clear_exceptions ⇒ Object
Clears the list of exceptions for find_file. This must be called before the exceptions are compiled.
679 680 681 682 683 |
# File 'lib/autotest.rb', line 679 def clear_exceptions raise "exceptions already compiled" if defined? @exceptions @exception_list.clear nil end |
#clear_mappings ⇒ Object
Clears all file mappings. This is DANGEROUS as it entirely disables autotest. You must add at least one file mapping that does a good job of rerunning appropriate tests.
646 647 648 649 |
# File 'lib/autotest.rb', line 646 def clear_mappings @test_mappings.clear nil end |
#debug ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/autotest.rb', line 220 def debug find_files_to_test puts "Known test files:" puts pp files_to_test.keys.sort class_map = self.class_map puts puts "Known class map:" puts pp class_map end |
#exceptions ⇒ Object
Return a compiled regexp of exceptions for find_files or nil if no filtering should take place. This regexp is generated from exception_list.
690 691 692 693 694 695 696 697 698 699 700 |
# File 'lib/autotest.rb', line 690 def exceptions unless defined? @exceptions then @exceptions = if @exception_list.empty? then nil else Regexp.union(*@exception_list) end end @exceptions end |
#files_matching(regexp) ⇒ Object
Returns all known files in the codebase matching regexp.
606 607 608 |
# File 'lib/autotest.rb', line 606 def files_matching regexp self.find_order.select { |k| k =~ regexp } end |
#find_files ⇒ Object
Find the files to process, ignoring temporary files, source configuration management files, etc., and return a Hash mapping filename to modification time.
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/autotest.rb', line 394 def find_files result = {} targets = if [:focus] then self.extra_files else self.find_directories + self.extra_files end reset_find_order targets.each do |target| order = [] Find.find target do |f| Find.prune if f =~ self.exceptions Find.prune if f =~ /^\.\/tmp/ # temp dir, used by isolate next unless File.file? f next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files next if f =~ /(,v)$/ # RCS files next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files filename = f.sub(/^\.\//, '') result[filename] = File.stat(filename).mtime rescue next order << filename end self.find_order.push(*order.sort) end result end |
#find_files_to_test(files = find_files) ⇒ Object
Find the files which have been modified, update the recorded timestamps, and use this to update the files to test. Returns the latest mtime of the files modified or nil when nothing was modified.
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/autotest.rb', line 434 def find_files_to_test files = find_files updated = files.select { |filename, mtime| self.last_mtime < mtime } # nothing to update or initially run unless updated.empty? || self.last_mtime.to_i == 0 then p updated if [:verbose] hook :updated, updated end updated.map { |f,m| test_files_for f }.flatten.uniq.each do |filename| self.failures[filename] # creates key with default value self.files_to_test[filename] # creates key with default value end if updated.empty? then nil else files.values.max end end |
#get_to_green ⇒ Object
Keep running the tests after a change, until all pass.
290 291 292 293 294 295 |
# File 'lib/autotest.rb', line 290 def get_to_green begin run_tests wait_for_changes unless all_good end until all_good end |
#hook(name, *args) ⇒ Object
Call the event hook named name, passing in optional args depending on the hook itself.
Returns false if no hook handled the event.
Hook Writers!
This executes all registered hooks until one returns truthy. Pay attention to the return value of your block!
716 717 718 719 720 721 722 723 724 725 726 |
# File 'lib/autotest.rb', line 716 def hook name, *args deprecated = { # none currently } if deprecated[name] and not HOOKS[name].empty? then warn "hook #{name} has been deprecated, use #{deprecated[name]}" end HOOKS[name].any? { |plugin| plugin[self, *args] } end |
#make_test_cmd(files_to_test) ⇒ Object
Generate the commands to test the supplied files
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
# File 'lib/autotest.rb', line 469 def make_test_cmd files_to_test if [:debug] then puts "Files to test:" puts pp files_to_test puts end cmds = [] full, partial = reorder(failures).partition { |k,v| v.empty? } unless full.empty? then classes = full.map {|k,v| k}.flatten.uniq classes.unshift testlib classes = classes.join " " cmds << "#{ruby_cmd} -e \"#{test_prefix}; %w[#{classes}].each { |f| require f }\" -- --server #{$$}" end unless partial.empty? then files = partial.map(&:first).sort # no longer a hash because of partition files.select! { |path| File.file? path } # filter out (eval) and the like re = [] partial.each do |path, klasses| klasses.each do |klass,methods| re << /#{klass}##{Regexp.union(methods)}/ end end loader = "%w[#{files.join " "}].each do |f| load f; end" re = Regexp.union(re).to_s.gsub(/-mix/, "").gsub(/'/, ".") cmds << "#{ruby_cmd} -e '#{loader}' -- --server #{$$} -n '/#{re}/'" end cmds.join "#{SEP} " end |
#minitest_result(file, klass, method, fails, assertions, time) ⇒ Object
743 744 745 746 747 748 749 750 |
# File 'lib/autotest.rb', line 743 def minitest_result file, klass, method, fails, assertions, time fails.reject! { |fail| Minitest::Skip === fail } unless fails.empty? self.tainted = true self.failures[file][klass] << method end end |
#minitest_start ⇒ Object
Server Methods:
739 740 741 |
# File 'lib/autotest.rb', line 739 def minitest_start self.failures.clear end |
#new_hash_of_arrays ⇒ Object
507 508 509 |
# File 'lib/autotest.rb', line 507 def new_hash_of_arrays Hash.new { |h,k| h[k] = [] } end |
#old_path_to_classname ⇒ Object
Convert a path in a string, s, into a class name, changing underscores to CamelCase, etc.
57 58 59 60 61 62 63 64 |
# File 'lib/autotest/rails.rb', line 57 def path_to_classname s sep = File::SEPARATOR f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split sep f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join } f = f.map { |path| path =~ /^Test/ ? path : "Test#{path}" } f.join '::' end |
#old_run_tests ⇒ Object
Look for files to test then run the tests and handle the results.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/autotest/preload.rb', line 27 def run_tests new_mtime = self.find_files_to_test return unless new_mtime self.last_mtime = new_mtime cmd = self.make_test_cmd self.files_to_test return if cmd.empty? hook :run_command, cmd puts cmd unless [:quiet] system cmd hook :ran_command end |
#path_to_classname(s) ⇒ Object
Convert the pathname s to the name of class.
380 381 382 383 384 385 386 387 |
# File 'lib/autotest.rb', line 380 def path_to_classname s sep = File::SEPARATOR f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split sep f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join } f = f.map { |path| path =~ /^Test/ ? path : "Test#{path}" } f.join '::' end |
#remove_exception(regexp) ⇒ Object
Removes regexp to the list of exceptions for find_file. This must be called before the exceptions are compiled.
669 670 671 672 673 |
# File 'lib/autotest.rb', line 669 def remove_exception regexp raise "exceptions already compiled" if defined? @exceptions @exception_list.delete regexp nil end |
#remove_mapping(regexp) ⇒ Object
Removed a file mapping matching regexp.
634 635 636 637 638 639 |
# File 'lib/autotest.rb', line 634 def remove_mapping regexp @test_mappings.delete_if do |k,v| k == regexp end nil end |
#reorder(files_to_test) ⇒ Object
511 512 513 514 |
# File 'lib/autotest.rb', line 511 def reorder files_to_test max = files_to_test.size files_to_test.sort_by { |k,v| rand max } end |
#rerun_all_tests ⇒ Object
Rerun the tests from cold (reset state)
519 520 521 522 523 524 |
# File 'lib/autotest.rb', line 519 def rerun_all_tests reset run_tests hook :all_good if all_good end |
#reset ⇒ Object
Clear all state information about test failures and whether interrupts will kill autotest.
530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/autotest.rb', line 530 def reset self.files_to_test.clear reset_find_order self.failures.clear self.interrupted = false self.last_mtime = T0 self.tainted = false self.wants_to_quit = false hook :reset end |
#reset_find_order ⇒ Object
543 544 545 546 |
# File 'lib/autotest.rb', line 543 def reset_find_order self.find_order = [] self.known_files = nil end |
#restart ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/autotest.rb', line 349 def restart Minitest::Server.stop Process.kill "KILL", @child if @child cmd = [$0, *[:args]] index = $LOAD_PATH.index RbConfig::CONFIG["sitelibdir"] if index then extra = $LOAD_PATH[0...index] cmd = [Gem.ruby, "-I", extra.join(":")] + cmd end puts cmd.join(" ") if [:verbose] exec(*cmd) end |
#ruby ⇒ Object
Determine and return the path of the ruby executable.
551 552 553 554 555 556 557 558 559 |
# File 'lib/autotest.rb', line 551 def ruby ruby = ENV['RUBY'] ruby ||= File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name']) ruby.gsub! File::SEPARATOR, File::ALT_SEPARATOR if File::ALT_SEPARATOR return ruby end |
#ruby_cmd ⇒ Object
Returns the base of the ruby command.
564 565 566 |
# File 'lib/autotest.rb', line 564 def ruby_cmd "#{prefix}#{ruby} -I#{libs}" end |
#run ⇒ Object
Repeatedly run failed tests, then all tests, then wait for changes and carry on until killed.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/autotest.rb', line 247 def run hook :initialize hook :post_initialize require "minitest/server" Minitest::Server.run self reset add_sigint_handler self.last_mtime = Time.now if [:no_full_after_start] self.debug if [:debug] loop do begin # ^c handler get_to_green if tainted? and not [:no_full_after_failed] then rerun_all_tests else hook :all_good end wait_for_changes rescue Interrupt break if wants_to_quit reset end end hook :quit puts rescue Exception => err hook(:died, err) or ( warn "Unhandled exception: #{err}" warn err.backtrace.join("\n ") warn "Quitting" ) ensure Minitest::Server.stop end |
#run_tests ⇒ Object
Look for files to test then run the tests and handle the results.
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/autotest.rb', line 300 def run_tests new_mtime = self.find_files_to_test return unless new_mtime self.last_mtime = new_mtime cmd = self.make_test_cmd self.files_to_test return if cmd.empty? hook :run_command, cmd puts cmd unless [:quiet] system cmd hook :ran_command end |
#test_files_for(filename) ⇒ Object
Return the name of the file with the tests for filename by finding a test_mapping that matches the file and executing the mapping’s proc.
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/autotest.rb', line 573 def test_files_for filename result = [] self.test_mappings.each do |file_re, proc| if filename =~ file_re then result = [proc.call(filename, $~)]. flatten.sort.uniq.select { |f| known_files[f] } break unless result.empty? end end p :test_file_for => [filename, result.first] if result and [:debug] output.puts "No tests matched #{filename}" if [:verbose] and result.empty? return result end |
#wait_for_changes ⇒ Object
Sleep then look for files to test, until there are some.
595 596 597 598 |
# File 'lib/autotest.rb', line 595 def wait_for_changes hook :waiting Kernel.sleep self.sleep until find_files_to_test end |