Permalink
Browse files

Add some RDoc.

[git-p4: depot-paths = "//src/heckle/dev/": change = 3172]
  • Loading branch information...
drbrain committed May 16, 2007
1 parent 1205b56 commit daab296918022b664c15861edcbce32f47c47767
Showing with 101 additions and 6 deletions.
  1. +101 −6 lib/heckle.rb
View
@@ -4,22 +4,76 @@
require 'timeout'
require 'tempfile'
-class String
+class String # :nodoc:
def to_class
split(/::/).inject(Object) { |klass, name| klass.const_get(name) }
end
end
+##
+# Test Unit Sadism
+
class Heckle < SexpProcessor
+
+ ##
+ # The version of Heckle you are using.
+
VERSION = '1.3.0'
+
+ ##
+ # Nodes that can be mutated by Heckle.
+
MUTATABLE_NODES = [:if, :lit, :str, :true, :false, :while, :until]
+
+ ##
+ # Is this platform MS Windows-like?
+
WINDOZE = RUBY_PLATFORM =~ /mswin/
+
+ ##
+ # Path to the bit bucket.
+
NULL_PATH = WINDOZE ? 'NUL:' : '/dev/null'
+
+ ##
+ # diff(1) executable
+
DIFF = WINDOZE ? 'diff.exe' : 'diff'
- attr_accessor(:klass_name, :method_name, :klass, :method, :mutatees,
- :original_tree, :mutation_count, :node_count,
- :failures, :count)
+ ##
+ # Mutation count
+
+ attr_accessor :count
+
+ ##
+ # Mutations that caused failures
+
+ attr_accessor :failures
+
+ ##
+ # Class being heckled
+
+ attr_accessor :klass
+
+ ##
+ # Name of class being heckled
+
+ attr_accessor :klass_name
+
+ ##
+ # Method being heckled
+
+ attr_accessor :method
+
+ ##
+ # Name of method being heckled
+
+ attr_accessor :method_name
+
+ attr_accessor :mutatees # :nodoc:
+ attr_accessor :mutation_count # :nodoc:
+ attr_accessor :node_count # :nodoc:
+ attr_accessor :original_tree # :nodoc:
@@debug = false
@@guess_timeout = true
@@ -38,6 +92,10 @@ def self.guess_timeout?
@@guess_timeout
end
+ ##
+ # Creates a new Heckle that will heckle +klass_name+ and +method_name+,
+ # sending results to +reporter+.
+
def initialize(klass_name=nil, method_name=nil, reporter = Reporter.new)
super()
@@ -70,8 +128,9 @@ def initialize(klass_name=nil, method_name=nil, reporter = Reporter.new)
@original_mutatees = mutatees.deep_clone
end
- ############################################################
- ### Overwrite test_pass? for your own Heckle runner.
+ ##
+ # Overwrite test_pass? for your own Heckle runner.
+
def tests_pass?
raise NotImplementedError
end
@@ -170,6 +229,9 @@ def process_lit(exp)
mutate_node [:lit, exp.shift]
end
+ ##
+ # Replaces the value of the :lit node with a random value.
+
def mutate_lit(exp)
case exp[1]
when Fixnum, Float, Bignum
@@ -187,6 +249,9 @@ def process_str(exp)
mutate_node [:str, exp.shift]
end
+ ##
+ # Replaces the value of the :str node with a random value.
+
def mutate_str(node)
[:str, rand_string]
end
@@ -195,6 +260,9 @@ def process_if(exp)
mutate_node [:if, process(exp.shift), process(exp.shift), process(exp.shift)]
end
+ ##
+ # Swaps the then and else parts of the :if node.
+
def mutate_if(node)
[:if, node[1], node[3], node[2]]
end
@@ -203,6 +271,9 @@ def process_true(exp)
mutate_node [:true]
end
+ ##
+ # Swaps for a :false node.
+
def mutate_true(node)
[:false]
end
@@ -211,6 +282,9 @@ def process_false(exp)
mutate_node [:false]
end
+ ##
+ # Swaps for a :true node.
+
def mutate_false(node)
[:true]
end
@@ -220,6 +294,9 @@ def process_while(exp)
mutate_node [:while, cond, body, head_controlled]
end
+ ##
+ # Swaps for a :until node.
+
def mutate_while(node)
[:until, node[1], node[2], node[3]]
end
@@ -229,6 +306,9 @@ def process_until(exp)
mutate_node [:until, cond, body, head_controlled]
end
+ ##
+ # Swaps for a :while node.
+
def mutate_until(node)
[:while, node[1], node[2], node[3]]
end
@@ -350,30 +430,45 @@ def current_code
RubyToRuby.translate(klass_name.to_class, method_name)
end
+ ##
+ # Returns a random Fixnum.
+
def rand_number
(rand(100) + 1)*((-1)**rand(2))
end
+ ##
+ # Returns a random String
+
def rand_string
size = rand(50)
str = ""
size.times { str << rand(126).chr }
str
end
+ ##
+ # Returns a random Symbol
+
def rand_symbol
letters = ('a'..'z').to_a + ('A'..'Z').to_a
str = ""
(rand(50) + 1).times { str << letters[rand(letters.size)] }
:"#{str}"
end
+ ##
+ # Returns a random Range
+
def rand_range
min = rand(50)
max = min + rand(50)
min..max
end
+ ##
+ # Suppresses output on $stdout and $stderr.
+
def silence_stream
dead = File.open("/dev/null", "w")

0 comments on commit daab296

Please sign in to comment.