autotest 4.4.5 → 4.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,62 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{autotest}
8
- s.version = "4.4.5"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Ryan Davis"]
12
- s.date = %q{2010-11-20}
13
- s.executables = ["autotest", "unit_diff"]
14
- s.files = [
15
- ".autotest",
16
- ".gitignore",
17
- "Gemfile",
18
- "Gemfile.lock",
19
- "History.txt",
20
- "Rakefile",
21
- "Readme.md",
22
- "VERSION",
23
- "articles/getting_started_with_autotest.html",
24
- "autotest.gemspec",
25
- "bin/autotest",
26
- "bin/unit_diff",
27
- "example_dot_autotest.rb",
28
- "lib/autotest.rb",
29
- "lib/autotest/autoupdate.rb",
30
- "lib/autotest/once.rb",
31
- "lib/autotest/rcov.rb",
32
- "lib/autotest/restart.rb",
33
- "lib/autotest/timestamp.rb",
34
- "lib/unit_diff.rb",
35
- "test/helper.rb",
36
- "test/test_autotest.rb",
37
- "test/test_autotest_integration.rb",
38
- "test/test_unit_diff.rb"
39
- ]
40
- s.homepage = %q{http://github.com/grosser/autotest}
41
- s.rdoc_options = ["--charset=UTF-8"]
42
- s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.7}
44
- s.summary = %q{Autotest, without ZenTest}
45
- s.test_files = [
46
- "test/test_autotest_integration.rb",
47
- "test/helper.rb",
48
- "test/test_autotest.rb",
49
- "test/test_unit_diff.rb"
50
- ]
51
-
52
- if s.respond_to? :specification_version then
53
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
- s.specification_version = 3
55
-
56
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
- else
58
- end
59
- else
60
- end
61
- end
62
-
@@ -1,67 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
- require 'optparse'
4
-
5
- options = {}
6
- OptionParser.new do |opts|
7
- opts.banner = <<BANNER
8
- Continuous testing for your ruby app.
9
-
10
- Usage:
11
- autotest [options]
12
- BANNER
13
- opts.on("-f", "--fast-start","Do not run full tests at start") do
14
- options[:no_full_after_start] = true
15
- end
16
- opts.on("-p", "--parallel","Run tests (Test::Unit only) in parallel -- gem install parallel_tests") do
17
- options[:parallel] = true
18
- require 'parallel_tests'
19
- end
20
- opts.on("-c", "--no-full-after-failed","Do not run full tests after failed test passed") { options[:no_full_after_failed] = true }
21
- opts.on("-v", "--verbose","Be verbose. Prints files that autotest doesn't know how to map to tests") { options[:verbose] = true }
22
- opts.on("-q", "--quiet","Be quiet.") { options[:quiet] = true }
23
- opts.on("-r", "--rc CONFIG", String, "Path to config file. (Defaults to ~/.autotest or current_dir/.autotest)") do |opt|
24
- options[:rc] = opt
25
- end
26
- opts.on("-s", "--style STYLE", "Which style to use, e.g. rspec, rspec2") do |style|
27
- options[:style] = style
28
- end
29
- opts.on("-b", "--bundle-exec", "Use bundle exec to run tests") do
30
- options[:bundle_exec] = true
31
- end
32
- opts.on("-h", "--help","Show this.") { puts opts;exit }
33
- end.parse!
34
-
35
- # remove warnings from Dir.[]
36
- class Dir
37
- class << self
38
- alias :old_index :[]
39
- def [](*args)
40
- $-w, old_warn = false, $-w
41
- old_index(*args)
42
- ensure
43
- $-w = old_warn
44
- end
45
- end
46
- end
47
-
48
- #run the correct Autotest variant fitting to the local structure
49
- $LOAD_PATH.unshift(File.expand_path("#{File.dirname(__FILE__)}/../lib"))
50
- require 'autotest'
51
-
52
- Autotest.options.merge!(options)
53
- target = Autotest
54
- style = (options[:style] ? [options[:style]] : Autotest.autodiscover)
55
-
56
- unless style.empty?
57
- mod = "autotest/#{style.join("_")}"
58
- puts "loading #{mod}" unless options[:quiet]
59
- begin
60
- require mod
61
- rescue LoadError => e
62
- abort "Error loading Autotest style #{mod} (#{e.to_s}). Aborting."
63
- end
64
- puts "style: #{style.map {|s| s.capitalize}.join}"
65
- target = Autotest.const_get(style.map {|s| s.capitalize}.join)
66
- end
67
- target.run
@@ -1,44 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rubygems'
3
- require 'optparse'
4
-
5
- OptionParser.new do |opts|
6
- opts.banner = <<BANNER
7
- unit_diff - a ruby unit test filter by Ryan Davis <ryand-ruby@zenspider.com>
8
-
9
- usage:
10
- test.rb | unit_diff [options]
11
- BANNER
12
- opts.on("-b", "ignore whitespace differences") { $b = true }
13
- opts.on("-c", "contextual diff") { $c = true }
14
- opts.on("-k", "keep temp diff files around") { $k = true }
15
- opts.on("-u", "unified diff") { $u = true }
16
- opts.on("-v", "display version") { $v = true }
17
- opts.on("-h", "--help","Show this.") { puts opts;exit }
18
- end.parse!
19
-
20
- begin
21
- require 'unit_diff'
22
- rescue LoadError
23
- require File.dirname(__FILE__) + '/../lib/unit_diff'
24
- end
25
-
26
- ############################################################
27
-
28
- if defined? $v then
29
- puts "#{File.basename $0} v. #{File.read( File.join(File.dirname(__FILE__),'..','VERSION') )}"
30
- exit 0
31
- end
32
-
33
- if defined? $h then
34
- File.open(__FILE__) do |f|
35
- begin; end until f.readline =~ /usage:/
36
- f.readline
37
- while line = f.readline and line.sub!(/^# ?/, '')
38
- $stderr.puts line
39
- end
40
- end
41
- exit 0
42
- end
43
-
44
- UnitDiff.unit_diff
@@ -1,12 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- # require 'autotest/autoupdate'
4
- # require 'autotest/once'
5
- # require 'autotest/rcov'
6
- # require 'autotest/restart'
7
- # require 'autotest/timestamp'
8
-
9
- # Autotest::AutoUpdate.sleep_time = o
10
- # Autotest::AutoUpdate.update_cmd = o
11
- # Autotest::RCov.command = o
12
- # Autotest::RCov.pattern = o
@@ -1,724 +0,0 @@
1
- require 'find'
2
- require 'rbconfig'
3
-
4
- $TESTING = false unless defined? $TESTING
5
-
6
- ##
7
- # Autotest continuously scans the files in your project for changes
8
- # and runs the appropriate tests. Test failures are run until they
9
- # have all passed. Then the full test suite is run to ensure that
10
- # nothing else was inadvertantly broken.
11
- #
12
- # If you want Autotest to start over from the top, hit ^C once. If
13
- # you want Autotest to quit, hit ^C twice.
14
- #
15
- # Rails:
16
- #
17
- # The autotest command will automatically discover a Rails directory
18
- # by looking for config/environment.rb. When Rails is discovered,
19
- # autotest uses RailsAutotest to perform file mappings and other work.
20
- # See RailsAutotest for details.
21
- #
22
- # Plugins:
23
- #
24
- # Plugins are available by creating a .autotest file either in your
25
- # project root or in your home directory. You can then write event
26
- # handlers in the form of:
27
- #
28
- # Autotest.add_hook hook_name { |autotest| ... }
29
- #
30
- # The available hooks are listed in +ALL_HOOKS+.
31
- #
32
- # See example_dot_autotest.rb for more details.
33
- #
34
- # If a hook returns a true value, it signals to autotest that the hook
35
- # was handled and should not continue executing hooks.
36
- #
37
- # Naming:
38
- #
39
- # Autotest uses a simple naming scheme to figure out how to map
40
- # implementation files to test files following the Test::Unit naming
41
- # scheme.
42
- #
43
- # * Test files must be stored in test/
44
- # * Test files names must start with test_
45
- # * Test class names must start with Test
46
- # * Implementation files must be stored in lib/
47
- # * Implementation files must match up with a test file named
48
- # test_.*implementation.rb
49
- #
50
- # Strategy:
51
- #
52
- # 1. Find all files and associate them from impl <-> test.
53
- # 2. Run all tests.
54
- # 3. Scan for failures.
55
- # 4. Detect changes in ANY (ruby?. file, rerun all failures + changed files.
56
- # 5. Until 0 defects, goto 3.
57
- # 6. When 0 defects, goto 2.
58
-
59
- class Autotest
60
-
61
- VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
62
-
63
- RUBY19 = defined? Encoding
64
-
65
- T0 = Time.at 0
66
-
67
- ALL_HOOKS = [ :all_good, :died, :green, :initialize, :interrupt, :quit,
68
- :ran_command, :red, :reset, :run_command, :updated, :waiting ]
69
-
70
- @@options = {}
71
- def self.options;@@options;end
72
- def options;@@options;end
73
-
74
-
75
- HOOKS = Hash.new { |h,k| h[k] = [] } #unfound keys are []
76
- unless defined? WINDOZE then
77
- WINDOZE = /mswin|mingw|windows/ =~ Config::CONFIG['host_os']
78
- SEP = WINDOZE ? '&' : ';'
79
- end
80
-
81
- @@discoveries = []
82
-
83
- ##
84
- # Add a proc to the collection of discovery procs. See
85
- # +autodiscover+.
86
-
87
- def self.add_discovery &proc
88
- @@discoveries << proc
89
- end
90
-
91
- ##
92
- # Automatically find all potential autotest runner styles by
93
- # searching your loadpath, vendor/plugins, and rubygems for
94
- # "autotest/discover.rb". If found, that file is loaded and it
95
- # should register discovery procs with autotest using
96
- # +add_discovery+. That proc should return one or more strings
97
- # describing the user's current environment. Those styles are then
98
- # combined to dynamically invoke an autotest plugin to suite your
99
- # environment. That plugin should define a subclass of Autotest with
100
- # a corresponding name.
101
- #
102
- # === Process:
103
- #
104
- # 1. All autotest/discover.rb files loaded.
105
- # 2. Those procs determine your styles (eg ["rails", "rspec"]).
106
- # 3. Require file by sorting styles and joining (eg 'autotest/rails_rspec').
107
- # 4. Invoke run method on appropriate class (eg Autotest::RailsRspec.run).
108
- #
109
- # === Example autotest/discover.rb:
110
- #
111
- # Autotest.add_discovery do
112
- # "rails" if File.exist? 'config/environment.rb'
113
- # end
114
- #
115
- def self.autodiscover
116
- require 'rubygems'
117
- begin
118
- require 'win32console' if WINDOZE
119
- rescue LoadError
120
- end
121
-
122
- with_current_path_in_load_path do
123
- # search load paths for autotest/discover.rb and load em all
124
- Gem.find_files("autotest/discover").each do |f|
125
- load f
126
- end
127
- end
128
-
129
- #call all discover procs an determine style
130
- @@discoveries.map{ |proc| proc.call }.flatten.compact.sort.uniq
131
- end
132
-
133
- ##
134
- # Initialize and run the system.
135
-
136
- def self.run
137
- new.run
138
- end
139
-
140
- attr_writer :known_files
141
- attr_accessor(:completed_re,
142
- :extra_class_map,
143
- :extra_files,
144
- :failed_results_re,
145
- :files_to_test,
146
- :find_order,
147
- :interrupted,
148
- :last_mtime,
149
- :libs,
150
- :order,
151
- :output,
152
- :results,
153
- :sleep,
154
- :tainted,
155
- :testlib,
156
- :find_directories,
157
- :unit_diff,
158
- :wants_to_quit)
159
-
160
- alias tainted? tainted
161
-
162
- ##
163
- # Initialize the instance and then load the user's .autotest file, if any.
164
-
165
- def initialize
166
- # these two are set directly because they're wrapped with
167
- # add/remove/clear accessor methods
168
- @exception_list = []
169
- @test_mappings = []
170
-
171
- self.completed_re = /\d+ tests, \d+ assertions, \d+ failures, \d+ errors/
172
- self.extra_class_map = {}
173
- self.extra_files = []
174
- self.failed_results_re = /^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/
175
- self.files_to_test = new_hash_of_arrays
176
- self.find_order = []
177
- self.known_files = nil
178
- self.libs = %w[. lib test].join(File::PATH_SEPARATOR)
179
- self.order = :random
180
- self.output = $stderr
181
- self.sleep = 1
182
- self.testlib = "test/unit"
183
- self.find_directories = ['.']
184
- self.unit_diff = "#{File.expand_path("#{File.dirname(__FILE__)}/../bin/unit_diff")} -u"
185
-
186
- add_test_unit_mappings
187
-
188
- #execute custom extensions
189
- load_custom_extensions(options[:rc])
190
- end
191
-
192
- def add_test_unit_mappings
193
- #file in /lib -> run test in /test
194
- self.add_mapping(/^lib\/.*\.rb$/) do |filename, _|
195
- possible = File.basename(filename).gsub '_', '_?'
196
- files_matching %r%^test/.*#{possible}$%
197
- end
198
-
199
- #file in /test -> run it
200
- self.add_mapping(/^test.*\/test_.*rb$/) do |filename, _|
201
- filename
202
- end
203
- end
204
-
205
- def load_custom_extensions(config_file)
206
- configs = ['./.autotest']
207
- if config_file
208
- configs << File.expand_path(config_file)
209
- else
210
- configs << File.expand_path('~/.autotest')
211
- end
212
- configs.each do |f|
213
- load f if File.exist? f
214
- end
215
- end
216
-
217
- ##
218
- # Repeatedly run failed tests, then all tests, then wait for changes
219
- # and carry on until killed.
220
-
221
- def run
222
- hook :initialize
223
- reset
224
- add_sigint_handler
225
-
226
- self.last_mtime = Time.now if options[:no_full_after_start]
227
-
228
- loop do
229
- begin # ^c handler
230
- get_to_green
231
- if tainted? and not options[:no_full_after_failed]
232
- rerun_all_tests
233
- else
234
- hook :all_good
235
- end
236
- wait_for_changes
237
- rescue Interrupt
238
- break if wants_to_quit
239
- reset
240
- end
241
- end
242
- hook :quit
243
- rescue Exception => err
244
- hook :died, err
245
- end
246
-
247
- ##
248
- # Keep running the tests after a change, until all pass.
249
-
250
- def get_to_green
251
- begin
252
- run_tests
253
- wait_for_changes unless all_good
254
- end until all_good
255
- end
256
-
257
- ##
258
- # Look for files to test then run the tests and handle the results.
259
-
260
- def run_tests
261
- hook :run_command
262
-
263
- new_mtime = self.find_files_to_test
264
- return unless new_mtime
265
- self.last_mtime = new_mtime
266
-
267
- cmd = self.make_test_cmd self.files_to_test
268
- return if cmd.empty?
269
-
270
- puts cmd unless options[:quiet]
271
-
272
- old_sync = $stdout.sync
273
- $stdout.sync = true
274
- self.results = []
275
- line = []
276
- begin
277
- open("| #{cmd}", "r") do |f|
278
- until f.eof? do
279
- c = f.getc or break
280
- putc (c.is_a?(Fixnum) ? c.chr : c) # print breaks coloring on windows -> putc
281
- line << c
282
- if c == ?\n then
283
- self.results << if RUBY19 then
284
- line.join
285
- else
286
- line.pack "c*"
287
- end
288
- line.clear
289
- end
290
- end
291
- end
292
- ensure
293
- $stdout.sync = old_sync
294
- end
295
- hook :ran_command
296
- self.results = self.results.join
297
-
298
- handle_results(self.results)
299
- end
300
-
301
- ############################################################
302
- # Utility Methods, not essential to reading of logic
303
-
304
- ##
305
- # Installs a sigint handler.
306
-
307
- def add_sigint_handler
308
- trap 'INT' do
309
- if self.interrupted then
310
- self.wants_to_quit = true
311
- else
312
- unless hook :interrupt then
313
- puts "Interrupt a second time to quit"
314
- self.interrupted = true
315
- Kernel.sleep 1.5
316
- end
317
- raise Interrupt, nil # let the run loop catch it
318
- end
319
- end
320
- end
321
-
322
- ##
323
- # If there are no files left to test (because they've all passed),
324
- # then all is good.
325
-
326
- def all_good
327
- files_to_test.empty?
328
- end
329
-
330
- ##
331
- # Convert a path in a string, s, into a class name, changing
332
- # underscores to CamelCase, etc.
333
-
334
- def path_to_classname(s)
335
- sep = File::SEPARATOR
336
- f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split(sep)
337
- f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
338
- f = f.map { |path| path =~ /^Test/ ? path : "Test#{path}" }
339
-
340
- f.join('::')
341
- end
342
-
343
- ##
344
- # Returns a hash mapping a file name to the known failures for that
345
- # file.
346
-
347
- def consolidate_failures(failed)
348
- filters = new_hash_of_arrays
349
-
350
- class_map = Hash[*self.find_order.grep(/^test/).map { |f| # TODO: ugly
351
- [path_to_classname(f), f]
352
- }.flatten]
353
- class_map.merge!(self.extra_class_map)
354
-
355
- failed.each do |method, klass|
356
- if class_map.has_key? klass then
357
- filters[class_map[klass]] << method
358
- else
359
- output.puts "Unable to map class #{klass} to a file"
360
- end
361
- end
362
-
363
- return filters
364
- end
365
-
366
- ##
367
- # Find the files to process, ignoring temporary files, source
368
- # configuration management files, etc., and return a Hash mapping
369
- # filename to modification time.
370
-
371
- def find_files
372
- result = {}
373
- targets = self.find_directories + self.extra_files
374
- self.find_order.clear
375
-
376
- targets.each do |target|
377
- order = []
378
- Find.find(target) do |f|
379
- Find.prune if f =~ self.exceptions
380
-
381
- next if test ?d, f
382
- next if f =~ /(swp|~|rej|orig)$/ # temporary/patch files
383
- next if f =~ /\/\.?#/ # Emacs autosave/cvs merge files
384
-
385
- filename = f.sub(/^\.\//, '')
386
-
387
- result[filename] = File.stat(filename).mtime rescue next
388
- order << filename
389
- end
390
- self.find_order.push(*order.sort)
391
- end
392
-
393
- return result
394
- end
395
-
396
- ##
397
- # Find the files which have been modified, update the recorded
398
- # timestamps, and use this to update the files to test. Returns
399
- # the latest mtime of the files modified or nil when nothing was
400
- # modified.
401
- def find_files_to_test(files=find_files)
402
- updated = files.select { |filename, mtime| self.last_mtime < mtime }
403
-
404
- unless updated.empty? or self.last_mtime.to_i == 0 #nothing to update or initial run
405
- p updated if options[:verbose]
406
- hook :updated, updated
407
- end
408
-
409
- updated.map { |f,m| test_files_for(f) }.flatten.uniq.each do |filename|
410
- self.files_to_test[filename] # creates key with default value
411
- end
412
-
413
- if updated.empty? then
414
- nil
415
- else
416
- files.values.max
417
- end
418
- end
419
-
420
- ##
421
- # Check results for failures, set the "bar" to red or green, and if
422
- # there are failures record this.
423
-
424
- def handle_results(results)
425
- failed = results.scan(self.failed_results_re)
426
- completed = results =~ self.completed_re
427
-
428
- self.files_to_test = consolidate_failures failed if completed
429
-
430
- color = completed && self.files_to_test.empty? ? :green : :red
431
- hook color unless $TESTING
432
-
433
- self.tainted = true unless self.files_to_test.empty?
434
- end
435
-
436
- ##
437
- # Lazy accessor for the known_files hash.
438
-
439
- def known_files
440
- unless @known_files then
441
- @known_files = Hash[*find_order.map { |f| [f, true] }.flatten]
442
- end
443
- @known_files
444
- end
445
-
446
- ##
447
- # Generate the commands to test the supplied files
448
-
449
- def make_test_cmd files_to_test
450
- cmds = []
451
- full, partial = reorder(files_to_test).partition { |k,v| v.empty? }
452
- base_cmd = "#{bundle_exec}#{ruby} -I#{libs} -rubygems"
453
-
454
- unless full.empty? then
455
- files = full.map {|k,v| k}.flatten.uniq
456
- if options[:parallel] and files.size > 1
457
- files = files.map{|file| File.expand_path(file) } if RUBY19
458
- cmds << "#{bundle_exec}parallel_test #{escape_filenames(files).join(' ')}"
459
- else
460
- files.unshift testlib
461
- cmds << "#{base_cmd} -e \"[#{escape_filenames(files).join(', ')}].each { |f| require f }\" | #{unit_diff}"
462
- end
463
- end
464
-
465
- partial.each do |klass, methods|
466
- regexp = Regexp.union(*methods).source
467
- cmds << "#{base_cmd} #{klass} -n \"/^(#{regexp})$/\" | #{unit_diff}"
468
- end
469
-
470
- cmds.join("#{SEP} ")
471
- end
472
-
473
- def bundle_exec
474
- options[:bundle_exec] ? 'bundle exec ' : ''
475
- end
476
-
477
- def escape_filenames(classes)
478
- classes.map{|klass| "'#{klass}'"}
479
- end
480
-
481
- def new_hash_of_arrays
482
- Hash.new { |h,k| h[k] = [] }
483
- end
484
-
485
- def reorder files_to_test
486
- case self.order
487
- when :alpha then
488
- files_to_test.sort_by { |k,v| k }
489
- when :reverse then
490
- files_to_test.sort_by { |k,v| k }.reverse
491
- when :random then
492
- max = files_to_test.size
493
- files_to_test.sort_by { |k,v| rand(max) }
494
- when :natural then
495
- (self.find_order & files_to_test.keys).map { |f| [f, files_to_test[f]] }
496
- else
497
- raise "unknown order type: #{self.order.inspect}"
498
- end
499
- end
500
-
501
- ##
502
- # Rerun the tests from cold (reset state)
503
-
504
- def rerun_all_tests
505
- reset
506
- run_tests
507
-
508
- hook :all_good if all_good
509
- end
510
-
511
- ##
512
- # Clear all state information about test failures and whether
513
- # interrupts will kill autotest.
514
-
515
- def reset
516
- self.files_to_test.clear
517
- self.find_order.clear
518
- self.interrupted = false
519
- self.known_files = nil
520
- self.last_mtime = T0
521
- self.tainted = false
522
- self.wants_to_quit = false
523
-
524
- hook :reset
525
- end
526
-
527
- ##
528
- # Determine and return the path of the ruby executable.
529
-
530
- def ruby
531
- ruby = ENV['RUBY']
532
- ruby ||= File.join(Config::CONFIG['bindir'],
533
- Config::CONFIG['ruby_install_name'])
534
-
535
- ruby.gsub! File::SEPARATOR, File::ALT_SEPARATOR if File::ALT_SEPARATOR
536
-
537
- return ruby
538
- end
539
-
540
- ##
541
- # Return the name of the file with the tests for filename by finding
542
- # a +test_mapping+ that matches the file and executing the mapping's
543
- # proc.
544
-
545
- def test_files_for(filename)
546
- result = @test_mappings.find { |file_re, ignored| filename =~ file_re }
547
-
548
- p :test_file_for => [filename, result.first] if result and $DEBUG
549
-
550
- result = result.nil? ? [] : [result.last.call(filename, $~)].flatten
551
-
552
- output.puts "No tests matched #{filename}" if
553
- (options[:verbose] or $TESTING) and result.empty?
554
-
555
- result.sort.uniq.select { |f| known_files[f] }
556
- end
557
-
558
- ##
559
- # Sleep then look for files to test, until there are some.
560
-
561
- def wait_for_changes
562
- hook :waiting
563
- Kernel.sleep self.sleep until find_files_to_test
564
- end
565
-
566
- ############################################################
567
- # File Mappings:
568
-
569
- ##
570
- # Returns all known files in the codebase matching +regexp+.
571
-
572
- def files_matching regexp
573
- self.find_order.select { |k| k =~ regexp }
574
- end
575
-
576
- ##
577
- # Adds a file mapping, optionally prepending the mapping to the
578
- # front of the list if +prepend+ is true. +regexp+ should match a
579
- # file path in the codebase. +proc+ is passed a matched filename and
580
- # Regexp.last_match. +proc+ should return an array of tests to run.
581
- #
582
- # For example, if test_helper.rb is modified, rerun all tests:
583
- #
584
- # at.add_mapping(/test_helper.rb/) do |f, _|
585
- # at.files_matching(/^test.*rb$/)
586
- # end
587
-
588
- def add_mapping(regexp, prepend = false, &proc)
589
- if prepend then
590
- @test_mappings.unshift [regexp, proc]
591
- else
592
- @test_mappings.push [regexp, proc]
593
- end
594
- nil
595
- end
596
-
597
- ##
598
- # Removed a file mapping matching +regexp+.
599
-
600
- def remove_mapping regexp
601
- @test_mappings.delete_if do |k,v|
602
- k == regexp
603
- end
604
- nil
605
- end
606
-
607
- ##
608
- # Clears all file mappings. This is DANGEROUS as it entirely
609
- # disables autotest. You must add at least one file mapping that
610
- # does a good job of rerunning appropriate tests.
611
-
612
- def clear_mappings
613
- @test_mappings.clear
614
- nil
615
- end
616
-
617
- ############################################################
618
- # Exceptions:
619
-
620
- ##
621
- # Adds +regexp+ to the list of exceptions for find_file. This must
622
- # be called _before_ the exceptions are compiled.
623
-
624
- def add_exception regexp
625
- raise "exceptions already compiled" if defined? @exceptions
626
-
627
- @exception_list << regexp
628
- nil
629
- end
630
-
631
- ##
632
- # Removes +regexp+ to the list of exceptions for find_file. This
633
- # must be called _before_ the exceptions are compiled.
634
-
635
- def remove_exception regexp
636
- raise "exceptions already compiled" if defined? @exceptions
637
- @exception_list.delete regexp
638
- nil
639
- end
640
-
641
- ##
642
- # Clears the list of exceptions for find_file. This must be called
643
- # _before_ the exceptions are compiled.
644
-
645
- def clear_exceptions
646
- raise "exceptions already compiled" if defined? @exceptions
647
- @exception_list.clear
648
- nil
649
- end
650
-
651
- ##
652
- # Return a compiled regexp of exceptions for find_files or nil if no
653
- # filtering should take place. This regexp is generated from
654
- # +exception_list+.
655
-
656
- def exceptions
657
- unless defined? @exceptions then
658
- if @exception_list.empty? then
659
- @exceptions = nil
660
- else
661
- @exceptions = Regexp.union(*@exception_list)
662
- end
663
- end
664
-
665
- @exceptions
666
- end
667
-
668
- ############################################################
669
- # Hooks:
670
-
671
- ##
672
- # Call the event hook named +name+, executing all registered hooks
673
- # until one returns true. Returns false if no hook handled the
674
- # event.
675
-
676
- def hook(name, *args)
677
- deprecated = {
678
- # none currently
679
- }
680
-
681
- if deprecated[name] and not HOOKS[name].empty? then
682
- warn "hook #{name} has been deprecated, use #{deprecated[name]}"
683
- end
684
-
685
- HOOKS[name].any? do |plugin|
686
- plugin[self, *args]
687
- end
688
- end
689
-
690
- ##
691
- # Add the supplied block to the available hooks, with the given
692
- # name.
693
-
694
- def self.add_hook(name, &block)
695
- HOOKS[name] << block
696
- end
697
-
698
- private
699
-
700
- # since ruby 1.9 current path (path where autotest was called from) is not in $LOAD_PATH
701
- def self.with_current_path_in_load_path
702
- if RUBY19 and not $LOAD_PATH.include?(File.expand_path('.')) and not $LOAD_PATH.include?('.')
703
- begin
704
- $LOAD_PATH << '.'
705
- result = yield
706
- ensure
707
- $LOAD_PATH.delete('.')
708
- end
709
- result
710
- else
711
- yield
712
- end
713
- end
714
-
715
- #list of all available rubygem load paths
716
- def self.rubygem_load_paths
717
- begin
718
- require 'rubygems'
719
- Gem.latest_load_paths
720
- rescue LoadError
721
- []
722
- end
723
- end
724
- end