Permalink
Browse files

Class method support

[git-p4: depot-paths = "//src/heckle/dev/": change = 2904]
  • Loading branch information...
1 parent 88afdf2 commit 273e59bf9f2518407a8983b3d5c85b4e6f077aca @kevinclark kevinclark committed Jan 14, 2007
Showing with 94 additions and 27 deletions.
  1. +4 −1 History.txt
  2. +35 −22 lib/heckle.rb
  3. +9 −4 lib/test_unit_heckler.rb
  4. +4 −0 sample/lib/heckled.rb
  5. +4 −0 sample/test/test_heckled.rb
  6. +4 −0 test/fixtures/heckled.rb
  7. +34 −0 test/test_heckle.rb
View
@@ -1,7 +1,10 @@
== svn
* 1 minor enhancement
* -b allows heckling of branches only
-
+* 2 major enhancement
+ * Timeout for tests set dynamically and overridable with -T
+ * Class method support with "self.method_name"
+
== 1.1.1 / 2006-12-20
* 3 bug fixes:
View
@@ -10,7 +10,7 @@ def to_class
end
class Heckle < SexpProcessor
- VERSION = '1.1.1'
+ VERSION = '1.1.2'
MUTATABLE_NODES = [:if, :lit, :str, :true, :false, :while, :until]
WINDOZE = RUBY_PLATFORM =~ /mswin/
NULL_PATH = WINDOZE ? 'NUL:' : '/dev/null'
@@ -38,28 +38,32 @@ def self.guess_timeout?
def initialize(klass_name=nil, method_name=nil, reporter = Reporter.new)
super()
-
- @klass_name, @method_name = klass_name, method_name.intern
- @klass = @method = nil
+
+ @klass_name = klass_name
+ @method_name = method_name.intern if method_name
+
+ @klass = klass_name.to_class
+
+ @method = nil
@reporter = reporter
-
+
self.strict = false
self.auto_shift_type = true
self.expected = Array
-
+
@mutatees = Hash.new
@mutation_count = Hash.new
@node_count = Hash.new
@count = 0
-
+
MUTATABLE_NODES.each {|type| @mutatees[type] = [] }
-
+
@failures = []
-
+
@mutated = false
-
+
grab_mutatees
-
+
@original_tree = current_tree.deep_clone
@original_mutatees = mutatees.deep_clone
end
@@ -127,13 +131,19 @@ def heckle(exp)
raise e
end
@reporter.replacing(klass_name, method_name, src) if @@debug
- klass = klass_name.to_class
+
+ clean_name = method_name.to_s.gsub(/self\./, '')
+
self.count += 1
- new_name = "#{method_name}_#{count}"
- klass.send :undef_method, new_name rescue nil
- klass.send :alias_method, new_name, method_name
- klass.class_eval(src)
+ new_name = "#{clean_name}_#{count}"
+
+ aliasing_class = (method_name.to_s =~ /self\./) ? (class << @klass; self end) : @klass
+
+ aliasing_class.send :undef_method, new_name rescue nil
+ aliasing_class.send :alias_method, new_name, clean_name
+
+ @klass.class_eval(src)
end
############################################################
@@ -259,13 +269,16 @@ def reset_tree
return unless original_tree != current_tree
@mutated = false
- klass = klass_name.to_class
-
self.count += 1
- new_name = "#{method_name}_#{count}"
- klass.send :undef_method, new_name rescue nil
- klass.send :alias_method, new_name, method_name
- klass.send :alias_method, method_name, "#{method_name}_1"
+
+ clean_name = method_name.to_s.gsub(/self\./, '')
+ new_name = "#{clean_name}_#{count}"
+
+ aliasing_class = (method_name.to_s =~ /self\./) ? (class << @klass; self end) : @klass
+
+ aliasing_class.send :undef_method, new_name rescue nil
+ aliasing_class.send :alias_method, new_name, clean_name
+ aliasing_class.send :alias_method, clean_name, "#{clean_name}_1"
end
def reset_mutatees
View
@@ -20,8 +20,9 @@ def self.load_test_files
def self.validate(klass_name, method_name = nil)
load_test_files
klass = klass_name.to_class
-
+
initial_time = Time.now
+
unless self.new(klass_name).tests_pass? then
abort "Initial run of tests failed... fix and run heckle again"
end
@@ -35,9 +36,13 @@ def self.validate(klass_name, method_name = nil)
end
puts "Initial tests pass. Let's rumble."
-
- methods = method_name ? Array(method_name) : klass.instance_methods(false)
-
+ self.timeout = adjusted_timeout
+
+ puts "Initial tests pass. Let's rumble."
+
+ klass_methods = klass.singleton_methods(false).collect {|meth| "self.#{meth}"}
+ methods = method_name ? Array(method_name) : klass.instance_methods(false) + klass_methods
+
methods.each do |method_name|
self.new(klass_name, method_name).validate
end
View
@@ -5,6 +5,10 @@ def initialize
@names = []
end
+ def self.is_a_klass_method?
+ true
+ end
+
def uses_while
i = 1
while i < 10
@@ -20,4 +20,8 @@ def test_uses_strings
def test_uses_infinite_loop
@heckled.uses_infinite_loop?
end
+
+ def test_is_a_klass_method
+ assert_equal true, Heckled.is_a_klass_method?
+ end
end
View
@@ -95,6 +95,10 @@ def uses_ranges
def uses_nothing
end
+
+ def self.is_a_klass_method?
+ true
+ end
private
View
@@ -385,3 +385,37 @@ def test_flips_until_to_while
assert_equal expected, @heckler.current_tree
end
end
+
+class TestHeckleClassMethod < Test::Unit::TestCase
+ def setup
+ @heckler = TestHeckler.new("Heckled", "self.is_a_klass_method?")
+ end
+
+ def teardown
+ @heckler.reset
+ end
+
+ def test_default_structure
+ expected = [:defn, :"self.is_a_klass_method?",
+ [:scope,
+ [:block,
+ [:args],
+ [:true]]]]
+ assert_equal expected, @heckler.current_tree
+ end
+
+ def test_heckle_class_methods
+ expected = [:defn, :"self.is_a_klass_method?",
+ [:scope,
+ [:block,
+ [:args],
+ [:false]]]]
+ @heckler.process(@heckler.current_tree)
+ assert_equal expected, @heckler.current_tree
+ end
+end
+
+
+
+
+

0 comments on commit 273e59b

Please sign in to comment.