Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 120 lines (94 sloc) 2.93 kb
908b2d6 @zenspider Pulled flat history from subversion.
zenspider authored
1 #!/usr/bin/env ruby
2
534bd3a @drbrain Ensure test/unit doesn't swallow our timeout.
drbrain authored
3 require 'test/unit/testcase'
908b2d6 @zenspider Pulled flat history from subversion.
zenspider authored
4 require 'heckle'
cd4ec4f @zenspider FEEL THE EYE OF SAURON!!! MUAHAHAHAHA!!!
zenspider authored
5 require 'zentest_mapping'
6
c4226a3 @zenspider Fixed load path so CUT requires work.
zenspider authored
7 $: << 'lib' << 'test'
908b2d6 @zenspider Pulled flat history from subversion.
zenspider authored
8
534bd3a @drbrain Ensure test/unit doesn't swallow our timeout.
drbrain authored
9 # Make sure test/unit doesn't swallow our timeout
c6f379e @zenspider Updated history and readme for new hoe capabilities.
zenspider authored
10 begin
11 Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS << Heckle::Timeout
12 rescue NameError
13 # ignore
14 end
534bd3a @drbrain Ensure test/unit doesn't swallow our timeout.
drbrain authored
15
7a3edda @zenspider Whitespace cleanup. Ugh.
zenspider authored
16 class TestUnitHeckler < Heckle
534bd3a @drbrain Ensure test/unit doesn't swallow our timeout.
drbrain authored
17
16d8d17 @kevinclark Refactoring of reporting and test::unit runner (Aslak Hellesoy)
kevinclark authored
18 @@test_pattern = 'test/test_*.rb'
cd4ec4f @zenspider FEEL THE EYE OF SAURON!!! MUAHAHAHAHA!!!
zenspider authored
19 @@tests_loaded = false
20 @@focus = false
16d8d17 @kevinclark Refactoring of reporting and test::unit runner (Aslak Hellesoy)
kevinclark authored
21
8325ac0 @zenspider Fixed manifest for previous refactoring/file-splits.
zenspider authored
22 def self.test_pattern=(value)
23 @@test_pattern = value
24 end
7a3edda @zenspider Whitespace cleanup. Ugh.
zenspider authored
25
cd4ec4f @zenspider FEEL THE EYE OF SAURON!!! MUAHAHAHAHA!!!
zenspider authored
26 def self.focus=(value)
27 @@focus = value
28 end
29
8325ac0 @zenspider Fixed manifest for previous refactoring/file-splits.
zenspider authored
30 def self.load_test_files
31 @@tests_loaded = true
32 Dir.glob(@@test_pattern).each {|test| require test}
33 end
16d8d17 @kevinclark Refactoring of reporting and test::unit runner (Aslak Hellesoy)
kevinclark authored
34
70089de @drbrain Heckle :call nodes.
drbrain authored
35 def self.validate(klass_name, method_name = nil,
09e34c4 @drbrain Add --force to ignore initial test failure.
drbrain authored
36 nodes = Heckle::MUTATABLE_NODES, force = false)
8325ac0 @zenspider Fixed manifest for previous refactoring/file-splits.
zenspider authored
37 load_test_files
38 klass = klass_name.to_class
8bc68e2 @zenspider Was using the wrong var for the original in the diff. Fixed.
zenspider authored
39
c2e1647 @kevinclark Abort Heckle if supplied method doesn't exist
kevinclark authored
40 # Does the method exist?
41 klass_methods = klass.singleton_methods(false).collect {|meth| "self.#{meth}"}
42 if method_name
43 if method_name =~ /self\./
44 abort "Unknown method: #{klass_name}.#{method_name.gsub('self.', '')}" unless klass_methods.include? method_name
45 else
46 abort "Unknown method: #{klass_name}##{method_name}" unless klass.instance_methods(false).include? method_name
47 end
48 end
49
9b1f0e2 @kevinclark Infinite loop detection (take that halting problem!)
kevinclark authored
50 initial_time = Time.now
273e59b @kevinclark Class method support
kevinclark authored
51
09e34c4 @drbrain Add --force to ignore initial test failure.
drbrain authored
52 heckle = self.new(klass_name)
53
54 passed = heckle.tests_pass?
55
dee274c @drbrain Make -v more useful.
drbrain authored
56 unless force or passed then
7a3edda @zenspider Whitespace cleanup. Ugh.
zenspider authored
57 abort "Initial run of tests failed... fix and run heckle again"
58 end
8bc68e2 @zenspider Was using the wrong var for the original in the diff. Fixed.
zenspider authored
59
534bd3a @drbrain Ensure test/unit doesn't swallow our timeout.
drbrain authored
60 if self.guess_timeout? then
61 running_time = Time.now - initial_time
62 adjusted_timeout = (running_time * 2 < 5) ? 5 : (running_time * 2).ceil
88afdf2 @kevinclark Command line options (-T) for timeouts on testing
kevinclark authored
63 self.timeout = adjusted_timeout
64 end
8bc68e2 @zenspider Was using the wrong var for the original in the diff. Fixed.
zenspider authored
65
534bd3a @drbrain Ensure test/unit doesn't swallow our timeout.
drbrain authored
66 puts "Timeout set to #{adjusted_timeout} seconds."
8bc68e2 @zenspider Was using the wrong var for the original in the diff. Fixed.
zenspider authored
67
09e34c4 @drbrain Add --force to ignore initial test failure.
drbrain authored
68 if passed then
69 puts "Initial tests pass. Let's rumble."
70 else
71 puts "Initial tests failed but you forced things. Let's rumble."
72 end
d0f2b0d @zenspider Diff mutation on verbose output too.
zenspider authored
73 puts
74
273e59b @kevinclark Class method support
kevinclark authored
75 methods = method_name ? Array(method_name) : klass.instance_methods(false) + klass_methods
8bc68e2 @zenspider Was using the wrong var for the original in the diff. Fixed.
zenspider authored
76
d0f2b0d @zenspider Diff mutation on verbose output too.
zenspider authored
77 counts = Hash.new(0)
78 methods.sort.each do |method_name|
70089de @drbrain Heckle :call nodes.
drbrain authored
79 result = self.new(klass_name, method_name, nodes).validate
d0f2b0d @zenspider Diff mutation on verbose output too.
zenspider authored
80 counts[result] += 1
81 end
82 all_good = counts[false] == 0
83
84 puts "Heckle Results:"
85 puts
86 puts "Passed : %3d" % counts[true]
87 puts "Failed : %3d" % counts[false]
88 puts "Thick Skin: %3d" % counts[nil]
89 puts
af5a6fb @zenspider thick skin == nil, not true, so exit cade was wrong sometimes.
zenspider authored
90
d0f2b0d @zenspider Diff mutation on verbose output too.
zenspider authored
91 if all_good then
af5a6fb @zenspider thick skin == nil, not true, so exit cade was wrong sometimes.
zenspider authored
92 puts "All heckling was thwarted! YAY!!!"
93 else
94 puts "Improve the tests and try again."
95 end
96
d0f2b0d @zenspider Diff mutation on verbose output too.
zenspider authored
97 all_good
16d8d17 @kevinclark Refactoring of reporting and test::unit runner (Aslak Hellesoy)
kevinclark authored
98 end
99
70089de @drbrain Heckle :call nodes.
drbrain authored
100 def initialize(klass_name=nil, method_name=nil, nodes=Heckle::MUTATABLE_NODES)
101 super
16d8d17 @kevinclark Refactoring of reporting and test::unit runner (Aslak Hellesoy)
kevinclark authored
102 self.class.load_test_files unless @@tests_loaded
103 end
7a3edda @zenspider Whitespace cleanup. Ugh.
zenspider authored
104
cd4ec4f @zenspider FEEL THE EYE OF SAURON!!! MUAHAHAHAHA!!!
zenspider authored
105 include ZenTestMapping
106
908b2d6 @zenspider Pulled flat history from subversion.
zenspider authored
107 def tests_pass?
7a3edda @zenspider Whitespace cleanup. Ugh.
zenspider authored
108 silence_stream do
cd4ec4f @zenspider FEEL THE EYE OF SAURON!!! MUAHAHAHAHA!!!
zenspider authored
109 if @@focus and @method_name then
110 name = normal_to_test @method_name.to_s
111 ARGV.clear
112 ARGV << "--name=/#{name}/"
113 end
4aa0c20 @kevinclark Fix test_unit_heckler's test_pass? so it returns the result of the run ...
kevinclark authored
114 result = Test::Unit::AutoRunner.run
cd4ec4f @zenspider FEEL THE EYE OF SAURON!!! MUAHAHAHAHA!!!
zenspider authored
115 ARGV.clear
4aa0c20 @kevinclark Fix test_unit_heckler's test_pass? so it returns the result of the run ...
kevinclark authored
116 result
7a3edda @zenspider Whitespace cleanup. Ugh.
zenspider authored
117 end
908b2d6 @zenspider Pulled flat history from subversion.
zenspider authored
118 end
8325ac0 @zenspider Fixed manifest for previous refactoring/file-splits.
zenspider authored
119 end
Something went wrong with that request. Please try again.