Skip to content

Commit d65fafd

Browse files
author
Jeff McCune
committed
Merge branch 'main/mater/watchr'
* main/mater/watchr: (Maint) Add watchr autotest script
2 parents 01335cb + a8ba1b3 commit d65fafd

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

spec/watchr.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
ENV['FOG_MOCK'] ||= 'true'
2+
ENV['AUTOTEST'] = 'true'
3+
ENV['WATCHR'] = '1'
4+
5+
system 'clear'
6+
7+
def growl(message)
8+
growlnotify = `which growlnotify`.chomp
9+
title = "Watchr Test Results"
10+
image = case message
11+
when /(\d+)\s+?(failure|error)/i
12+
($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
13+
else
14+
'~/.watchr_images/unknown.png'
15+
end
16+
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
17+
system %(#{growlnotify} #{options} &)
18+
end
19+
20+
def run(cmd)
21+
puts(cmd)
22+
`#{cmd}`
23+
end
24+
25+
def run_spec_test(file)
26+
if File.exist? file
27+
result = run "rspec --format p --color #{file}"
28+
growl result.split("\n").last
29+
puts result
30+
else
31+
puts "FIXME: No test #{file} [#{Time.now}]"
32+
end
33+
end
34+
35+
def filter_rspec(data)
36+
data.split("\n").find_all do |l|
37+
l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/
38+
end.join("\n")
39+
end
40+
41+
def run_all_tests
42+
system('clear')
43+
files = Dir.glob("spec/**/*_spec.rb").join(" ")
44+
result = run "rspec #{files}"
45+
growl_results = filter_rspec result
46+
growl growl_results
47+
puts result
48+
puts "GROWL: #{growl_results}"
49+
end
50+
51+
# Ctrl-\
52+
Signal.trap 'QUIT' do
53+
puts " --- Running all tests ---\n\n"
54+
run_all_tests
55+
end
56+
57+
@interrupted = false
58+
59+
# Ctrl-C
60+
Signal.trap 'INT' do
61+
if @interrupted then
62+
@wants_to_quit = true
63+
abort("\n")
64+
else
65+
puts "Interrupt a second time to quit"
66+
@interrupted = true
67+
Kernel.sleep 1.5
68+
# raise Interrupt, nil # let the run loop catch it
69+
run_suite
70+
end
71+
end
72+
73+
def file2spec(file)
74+
result = file.sub('lib/puppet/', 'spec/unit/puppet/').gsub(/\.rb$/, '_spec.rb')
75+
result = file.sub('lib/facter/', 'spec/unit/facter/').gsub(/\.rb$/, '_spec.rb')
76+
end
77+
78+
79+
watch( 'spec/.*_spec\.rb' ) do |md|
80+
#run_spec_test(md[0])
81+
run_all_tests
82+
end
83+
watch( 'lib/.*\.rb' ) do |md|
84+
# run_spec_test(file2spec(md[0]))
85+
run_all_tests
86+
end

0 commit comments

Comments
 (0)