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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/monkeytest.rb', line 7
def self.run_tests(mode)
quiet = ((mode.to_s == "quiet") or (mode.to_s == "q"))
silent = ((mode.to_s == "silent") or (mode.to_s == "s"))
directories = DIRECTORIES.collect {|dir| File.expand_path(dir) }
failures = Array.new
totalTests = totalAsserts = totalErrors = totalFailures = 0
directories.each do |dir|
puts "#{dir.match(/\/([^\/]+)\/?$/)[1].upcase} TESTS:".bold
Dir.foreach(dir) do |file|
if file.match(PATTERN)
print " #{file.ljust(35)}"
fullResult = `ruby -C \"#{dir}\" \"#{dir}/#{file}\"`
result = fullResult.match(/([\d]+) tests, ([\d]+) assertions, ([\d]+) failures, ([\d]+) errors/) or break
numTests = result[1].to_i
numAsserts = result[2].to_i
numFailures = result[3].to_i
numErrors = result[4].to_i
totalTests += numTests
totalAsserts += numAsserts
totalErrors += numErrors
totalFailures += numFailures
print "#{numTests.to_s.rjust(4)} Tests "
print "#{numAsserts.to_s.rjust(4)} Assertions "
if numErrors > 0 then
puts "ERROR".red
failures.push fullResult
elsif numFailures > 0 then
puts "FAIL".yellow
failures.push fullResult
else
puts "PASS".green
end
end
end
end
puts '-'*80
print "TOTALS:".bold.ljust(38)
print "#{totalTests.to_s.rjust(4)} Tests "
print "#{totalAsserts.to_s.rjust(4)} Assertions "
print "#{(totalFailures+totalErrors).to_s.rjust(4)} Problem(s)\n"
if silent
puts "\n"
elsif quiet
puts "\n\nErrors & Failures:".bold unless failures.empty?
failures.each do |badthing|
while matches = badthing.match(/(Error|Failure):[\s]+(test_[^\()]+)\(([^\)]+)\)([\s]\[[^\]]+\/(.+?):([\d]+)\])?/m) do
msg = " #{matches[1].ljust(10).red}" if matches[1] == "Error"
msg = " #{matches[1].ljust(10).yellow}" if matches[1] == "Failure"
msg << " #{matches[3].underline} : #{matches[2]}"
msg << " (#{matches[5]}:#{matches[6]})" unless matches[6].nil?
puts msg
badthing = matches.post_match
end
end
puts "\n"
else
puts "\n\nErrors & Failures:".bold unless failures.empty?
failures.each do |badthing|
puts badthing
puts "\n"
end
end
end
|