forked from kputnam/piggly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autotest.rb
executable file
·44 lines (36 loc) · 1.29 KB
/
autotest.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env ruby
STDOUT.sync = true
newest = Time.now - 3600 * 12
# TODO: re-run any failed tests
while sleep 2 do
specs = Dir['spec/**/*_spec.rb']
changes = Dir['lib/piggly/**/*.*'].concat(specs).select{|f| File.mtime(f) > newest }
changes -= %w(lib/piggly/parser/parser.rb)
unless changes.empty?
newest = changes.map{|f| File.mtime(f) }.max
rerun = changes.select{|f| specs.include? f }
# run all of the specs if the only files that changed were not specs
rerun = specs if rerun.empty?
$stdout.puts "Changes:\n " + rerun.join("\n ")
$stdout.write "Forking spec..."
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
STDOUT.reopen('spec.html')
Process.waitpid (spawn 'ruby', '-I', 'spec', '-S', 'rspec', '-fh', *rerun)
STDERR.reopen(File::NULL)
STDOUT.reopen(File::NULL)
Process.waitpid(spawn 'explorer', 'spec.html')
else
Process.waitpid(fork do
STDOUT.reopen('spec.html')
exec 'ruby', '-I', 'spec', '-S', 'rspec', '-fh', *rerun
end)
Process.waitpid(fork do
STDERR.reopen('/dev/null')
STDOUT.reopen('/dev/null')
#exec "opera", "-noraise", "-activetab", "spec.html" }
exec "open", "spec.html"
end)
end
$stdout.puts "done"
end
end