heckle 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +8 -0
- data/README.txt +49 -0
- data/Rakefile +15 -0
- data/bin/heckle +15 -0
- data/lib/heckle.rb +89 -0
- data/test/test_heckle.rb +33 -0
- metadata +61 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
heckle
|
2
|
+
by Ryan Davis
|
3
|
+
http://www.rubyforge.org/projects/seattlerb
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Unit Testing Sadism. More description coming soon. I'm punting to get
|
8
|
+
this launched ASAP.
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
* needs some love. haha.
|
13
|
+
|
14
|
+
== SYNOPSYS:
|
15
|
+
|
16
|
+
FIX
|
17
|
+
|
18
|
+
== REQUIREMENTS:
|
19
|
+
|
20
|
+
+ FIX
|
21
|
+
|
22
|
+
== INSTALL:
|
23
|
+
|
24
|
+
+ sudo gem install heckle
|
25
|
+
|
26
|
+
== LICENSE:
|
27
|
+
|
28
|
+
(The MIT License)
|
29
|
+
|
30
|
+
Copyright (c) 2006 FIX
|
31
|
+
|
32
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
33
|
+
a copy of this software and associated documentation files (the
|
34
|
+
'Software'), to deal in the Software without restriction, including
|
35
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
36
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
37
|
+
permit persons to whom the Software is furnished to do so, subject to
|
38
|
+
the following conditions:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be
|
41
|
+
included in all copies or substantial portions of the Software.
|
42
|
+
|
43
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
44
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
45
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
46
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
47
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
48
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
49
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/heckle.rb'
|
6
|
+
|
7
|
+
Hoe.new('heckle', Heckle::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'seattlerb'
|
9
|
+
p.summary = 'Unit Test Sadism'
|
10
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
11
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
12
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
# vim: syntax=Ruby
|
data/bin/heckle
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/local/bin/ruby -w
|
2
|
+
|
3
|
+
$: << 'lib'
|
4
|
+
require 'heckle'
|
5
|
+
|
6
|
+
file = ARGV.shift
|
7
|
+
impl = ARGV.shift
|
8
|
+
meth = ARGV.shift
|
9
|
+
|
10
|
+
unless file and impl and meth then
|
11
|
+
abort "usage: #{File.basename($0)} file.rb impl_class_name impl_method_name"
|
12
|
+
end
|
13
|
+
|
14
|
+
heckle = Heckle.new(file, impl, meth)
|
15
|
+
heckle.validate
|
data/lib/heckle.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'parse_tree'
|
3
|
+
require 'ruby2ruby'
|
4
|
+
require 'test/unit/autorunner'
|
5
|
+
|
6
|
+
class String
|
7
|
+
def to_class
|
8
|
+
split(/::/).inject(Object) { |klass, name| klass.const_get(name) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Heckle < SexpProcessor
|
13
|
+
VERSION = '1.0.0'
|
14
|
+
|
15
|
+
attr_accessor :file, :klass_name, :method_name, :klass, :method
|
16
|
+
def initialize(file=nil, klass_name=nil, method_name=nil)
|
17
|
+
super()
|
18
|
+
|
19
|
+
@file, @klass_name, @method_name = file, klass_name, method_name.intern
|
20
|
+
@klass = @method = nil
|
21
|
+
|
22
|
+
self.strict = false
|
23
|
+
self.auto_shift_type = true
|
24
|
+
self.expected = Array
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate
|
28
|
+
puts "Validating #{file}"
|
29
|
+
|
30
|
+
load file
|
31
|
+
if Test::Unit::AutoRunner.run then
|
32
|
+
puts "Tests passed -- heckling"
|
33
|
+
|
34
|
+
process(ParseTree.translate(klass_name.to_class, method_name))
|
35
|
+
|
36
|
+
if Test::Unit::AutoRunner.run then
|
37
|
+
puts
|
38
|
+
abort "*** Tests passed again after heckling, your tests are incomplete"
|
39
|
+
else
|
40
|
+
puts "Tests failed -- this is good"
|
41
|
+
end
|
42
|
+
else
|
43
|
+
puts "Tests failed... fix and run heckle again"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
############################################################
|
48
|
+
|
49
|
+
def process_defn(exp)
|
50
|
+
self.method = exp.shift
|
51
|
+
result = [:defn, method]
|
52
|
+
|
53
|
+
result << process(exp.shift) until exp.empty?
|
54
|
+
|
55
|
+
heckle(result) if should_heckle?
|
56
|
+
|
57
|
+
return result
|
58
|
+
end
|
59
|
+
|
60
|
+
def process_if(exp)
|
61
|
+
cond = process(exp.shift)
|
62
|
+
t = process(exp.shift)
|
63
|
+
f = process(exp.shift)
|
64
|
+
|
65
|
+
if should_heckle? then
|
66
|
+
[:if, cond, f, t]
|
67
|
+
else
|
68
|
+
[:if, cond, t, f]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def should_heckle?
|
73
|
+
method == method_name
|
74
|
+
end
|
75
|
+
|
76
|
+
def heckle(exp)
|
77
|
+
puts "Heckling #{klass_name}##{method_name}"
|
78
|
+
|
79
|
+
r2r = RubyToRuby.new
|
80
|
+
src = r2r.process(exp)
|
81
|
+
|
82
|
+
puts
|
83
|
+
puts "Replacing #{klass}##{method_name} with:"
|
84
|
+
puts src
|
85
|
+
puts
|
86
|
+
|
87
|
+
klass_name.to_class.class_eval(src)
|
88
|
+
end
|
89
|
+
end
|
data/test/test_heckle.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require 'test/unit/testcase'
|
3
|
+
require 'test/unit' if $0 == __FILE__
|
4
|
+
|
5
|
+
class TestHeckle < Test::Unit::TestCase
|
6
|
+
|
7
|
+
############################################################
|
8
|
+
# Our method under test - in here just for demo...
|
9
|
+
|
10
|
+
def many? n
|
11
|
+
if n >= 3 then
|
12
|
+
true
|
13
|
+
else
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
############################################################
|
19
|
+
|
20
|
+
if false then
|
21
|
+
def test_many_eh_good
|
22
|
+
assert ! many?(0)
|
23
|
+
assert ! many?(1)
|
24
|
+
assert many?(3)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
def test_many_eh_bad
|
28
|
+
# obviously bad - need a better example for my demo
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
puts 'loaded'
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: heckle
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2006-10-22 00:00:00 -06:00
|
8
|
+
summary: Unit Test Sadism
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
- test
|
12
|
+
email: ryand-ruby@zenspider.com
|
13
|
+
homepage: " by Ryan Davis"
|
14
|
+
rubyforge_project: seattlerb
|
15
|
+
description: "== FEATURES/PROBLEMS: * needs some love. haha. == SYNOPSYS: FIX == REQUIREMENTS:"
|
16
|
+
autorequire:
|
17
|
+
default_executable:
|
18
|
+
bindir: bin
|
19
|
+
has_rdoc: true
|
20
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">"
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 0.0.0
|
25
|
+
version:
|
26
|
+
platform: ruby
|
27
|
+
signing_key:
|
28
|
+
cert_chain:
|
29
|
+
post_install_message:
|
30
|
+
authors:
|
31
|
+
- Ryan Davis
|
32
|
+
files:
|
33
|
+
- History.txt
|
34
|
+
- Manifest.txt
|
35
|
+
- README.txt
|
36
|
+
- Rakefile
|
37
|
+
- bin/heckle
|
38
|
+
- lib/heckle.rb
|
39
|
+
- test/test_heckle.rb
|
40
|
+
test_files: []
|
41
|
+
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
extra_rdoc_files: []
|
45
|
+
|
46
|
+
executables:
|
47
|
+
- heckle
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
dependencies:
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: hoe
|
55
|
+
version_requirement:
|
56
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.1.2
|
61
|
+
version:
|