Class: TestUnitHeckler
- Inherits:
-
Heckle
- Object
- SexpProcessor
- Heckle
- TestUnitHeckler
show all
- Includes:
- ZenTestMapping
- Defined in:
- lib/test_unit_heckler.rb
Constant Summary
collapse
- @@test_pattern =
'test/test_*.rb'
- @@tests_loaded =
false
- @@focus =
false
Constants inherited
from Heckle
Heckle::ASGN_NODES, Heckle::BRANCH_NODES, Heckle::DIFF, Heckle::MUTATABLE_NODES, Heckle::NULL_PATH, Heckle::VERSION, Heckle::WINDOZE
Instance Attribute Summary
Attributes inherited from Heckle
#count, #failures, #klass, #klass_name, #method, #method_name, #mutatees, #mutation_count, #node_count, #original_tree
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Heckle
#aliasing_class, #already_mutated?, #current_code, #current_tree, debug, debug=, #grab_conditional_loop_parts, #grab_mutatees, guess_timeout?, #heckle, #increment_mutation_count, #increment_node_count, #mutate_asgn, #mutate_call, #mutate_false, #mutate_if, #mutate_iter, #mutate_lit, #mutate_node, #mutate_str, #mutate_true, #mutate_until, #mutate_while, #mutations_left, #process_asgn, #process_call, #process_cvasgn, #process_dasgn, #process_dasgn_curr, #process_defn, #process_defs, #process_false, #process_gasgn, #process_iasgn, #process_if, #process_iter, #process_lasgn, #process_lit, #process_str, #process_true, #process_until, #process_while, #rand_number, #rand_range, #rand_string, #rand_symbol, #record_passing_mutation, #reset, #reset_mutatees, #reset_tree, #run_tests, #should_heckle?, #silence_stream, timeout=, #validate, #walk_and_push
Constructor Details
#initialize(klass_name = nil, method_name = nil, nodes = Heckle::MUTATABLE_NODES) ⇒ TestUnitHeckler
Returns a new instance of TestUnitHeckler.
101
102
103
104
|
# File 'lib/test_unit_heckler.rb', line 101
def initialize(klass_name=nil, method_name=nil, nodes=Heckle::MUTATABLE_NODES)
super
self.class.load_test_files unless @@tests_loaded
end
|
Class Method Details
.focus=(value) ⇒ Object
27
28
29
|
# File 'lib/test_unit_heckler.rb', line 27
def self.focus=(value)
@@focus = value
end
|
.load_test_files ⇒ Object
31
32
33
34
|
# File 'lib/test_unit_heckler.rb', line 31
def self.load_test_files
@@tests_loaded = true
Dir.glob(@@test_pattern).each {|test| require test}
end
|
.test_pattern=(value) ⇒ Object
23
24
25
|
# File 'lib/test_unit_heckler.rb', line 23
def self.test_pattern=(value)
@@test_pattern = value
end
|
.validate(klass_name, method_name = nil, nodes = Heckle::MUTATABLE_NODES, force = false) ⇒ Object
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/test_unit_heckler.rb', line 36
def self.validate(klass_name, method_name = nil,
nodes = Heckle::MUTATABLE_NODES, force = false)
load_test_files
klass = klass_name.to_class
klass_methods = klass.singleton_methods(false).collect {|meth| "self.#{meth}"}
if method_name
if method_name =~ /self\./
abort "Unknown method: #{klass_name}.#{method_name.gsub('self.', '')}" unless klass_methods.include? method_name
else
abort "Unknown method: #{klass_name}##{method_name}" unless klass.instance_methods(false).include? method_name
end
end
initial_time = Time.now
heckle = self.new(klass_name)
passed = heckle.tests_pass?
unless force or passed then
abort "Initial run of tests failed... fix and run heckle again"
end
if self.guess_timeout? then
running_time = Time.now - initial_time
adjusted_timeout = (running_time * 2 < 5) ? 5 : (running_time * 2).ceil
self.timeout = adjusted_timeout
end
puts "Timeout set to #{adjusted_timeout} seconds."
if passed then
puts "Initial tests pass. Let's rumble."
else
puts "Initial tests failed but you forced things. Let's rumble."
end
puts
methods = method_name ? Array(method_name) : klass.instance_methods(false) + klass_methods
counts = Hash.new(0)
methods.sort.each do |method_name|
result = self.new(klass_name, method_name, nodes).validate
counts[result] += 1
end
all_good = counts[false] == 0
puts "Heckle Results:"
puts
puts "Passed : %3d" % counts[true]
puts "Failed : %3d" % counts[false]
puts "Thick Skin: %3d" % counts[nil]
puts
if all_good then
puts "All heckling was thwarted! YAY!!!"
else
puts "Improve the tests and try again."
end
all_good
end
|
Instance Method Details
#tests_pass? ⇒ Boolean
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/test_unit_heckler.rb', line 108
def tests_pass?
silence_stream do
if @@focus and @method_name then
name = normal_to_test @method_name.to_s
ARGV.clear
ARGV << "--name=/#{name}/"
end
result = Test::Unit::AutoRunner.run
ARGV.clear
result
end
end
|