~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to autotest/watcher.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
ENV["WATCHR"] = "1"
2
 
ENV['AUTOTEST'] = 'true'
3
 
 
4
 
def run_comp(cmd)
5
 
  puts cmd
6
 
  results = []
7
 
  old_sync = $stdout.sync
8
 
  $stdout.sync = true
9
 
  line = []
10
 
  begin
11
 
    open("| #{cmd}", "r") do |f|
12
 
      until f.eof? do
13
 
        c = f.getc
14
 
        putc c
15
 
        line << c
16
 
        if c == ?\n
17
 
          results << if RUBY_VERSION >= "1.9" then
18
 
            line.join
19
 
              else
20
 
                line.pack "c*"
21
 
                  end
22
 
          line.clear
23
 
        end
24
 
      end
25
 
    end
26
 
  ensure
27
 
    $stdout.sync = old_sync
28
 
  end
29
 
  results.join
30
 
end
31
 
 
32
 
def clear
33
 
  #system("clear")
34
 
end
35
 
 
36
 
def growl(message, status)
37
 
  # Strip the color codes
38
 
  message.gsub!(/\[\d+m/, '')
39
 
 
40
 
  growlnotify = `which growlnotify`.chomp
41
 
  return if growlnotify.empty?
42
 
  title = "Watchr Test Results"
43
 
  image = status == :pass ? "autotest/images/pass.png" : "autotest/images/fail.png"
44
 
  options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
45
 
  system %(#{growlnotify} #{options} &)
46
 
end
47
 
 
48
 
def file2specs(file)
49
 
  %w{spec/unit spec/integration}.collect { |d|
50
 
    file.sub('lib/puppet', d)
51
 
  }.find_all { |f|
52
 
    File.exist?(f)
53
 
  }
54
 
end
55
 
 
56
 
def file2test(file)
57
 
  result = file.sub('lib/puppet', 'test')
58
 
  return nil unless File.exist?(result)
59
 
  result
60
 
end
61
 
 
62
 
def run_spec(command)
63
 
  clear
64
 
  result = run_comp(command).split("\n").last
65
 
  status = result.include?('0 failures') ? :pass : :fail
66
 
  growl result, status
67
 
end
68
 
 
69
 
def run_test(command)
70
 
  clear
71
 
  result = run_comp(command).split("\n").last
72
 
  status = result.include?('0 failures, 0 errors') ? :pass : :fail
73
 
  growl result.split("\n").last rescue nil
74
 
end
75
 
 
76
 
def run_test_file(file)
77
 
  run_test(%Q(#{file}))
78
 
end
79
 
 
80
 
def run_spec_files(files)
81
 
  files = Array(files)
82
 
  return if files.empty?
83
 
  opts = File.readlines('spec/spec.opts').collect { |l| l.chomp }.join(" ")
84
 
  run_spec("spec #{files.join(' ')}")
85
 
end
86
 
 
87
 
def run_all_tests
88
 
  run_test("rake unit")
89
 
end
90
 
 
91
 
def run_all_specs
92
 
  run_test("rake spec")
93
 
end
94
 
 
95
 
def run_suite
96
 
  run_all_tests
97
 
  run_all_specs
98
 
end
99
 
 
100
 
watch('spec/spec_helper.rb') { run_all_specs }
101
 
watch(%r{^spec/(unit|integration)/.*\.rb$}) { |md| run_spec_files(md[0]) }
102
 
watch(%r{^lib/puppet/(.*)\.rb$}) { |md|
103
 
  run_spec_files(file2specs(md[0]))
104
 
  if t = file2test(md[0])
105
 
    run_test_file(t)
106
 
  end
107
 
}
108
 
watch(%r{^spec/lib/spec.*}) { |md| run_all_specs }
109
 
watch(%r{^spec/lib/monkey_patches/.*}) { |md| run_all_specs }
110
 
watch(%r{test/.+\.rb}) { |md|
111
 
  if md[0] =~ /\/lib\//
112
 
    run_all_tests
113
 
  else
114
 
    run_test_file(md[0])
115
 
  end
116
 
}
117
 
 
118
 
# Ctrl-\
119
 
Signal.trap 'QUIT' do
120
 
  puts " --- Running all tests ---\n\n"
121
 
  run_suite
122
 
end
123
 
 
124
 
@interrupted = false
125
 
 
126
 
# Ctrl-C
127
 
Signal.trap 'INT' do
128
 
  if @interrupted
129
 
    @wants_to_quit = true
130
 
    abort("\n")
131
 
  else
132
 
    puts "Interrupt a second time to quit; wait for rerun of tests"
133
 
    @interrupted = true
134
 
    Kernel.sleep 1.5
135
 
    # raise Interrupt, nil # let the run loop catch it
136
 
    run_suite
137
 
  end
138
 
end