dev-utils 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.txt +36 -0
- data/MIT-LICENSE.txt +20 -0
- data/README.txt +21 -0
- data/Rakefile +135 -0
- data/VERSION +1 -0
- data/etc/doc/DebuggingAids.textile +450 -0
- data/etc/doc/UnitTestOrganisation.textile +253 -0
- data/etc/doc/generate.rb +187 -0
- data/etc/doc/index.textile +110 -0
- data/etc/doc/links.dat +9 -0
- data/etc/doc/textile.css +150 -0
- data/examples/breakpoint-example.rb +30 -0
- data/examples/debug.log +0 -0
- data/examples/log-trace-example.rb +35 -0
- data/lib/dev-utils/debug.rb +32 -0
- data/lib/dev-utils/debug/diff.rb +187 -0
- data/lib/dev-utils/debug/irb.rb +176 -0
- data/lib/dev-utils/debug/log.rb +107 -0
- data/lib/dev-utils/test.rb +267 -0
- data/test/TEST.rb +6 -0
- data/test/tc_debug.rb +153 -0
- metadata +76 -0
data/test/TEST.rb
ADDED
data/test/tc_debug.rb
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
# This is a bunch of test cases for the 'diff' method. Since that method is currently
|
2
|
+
# commented out, so too are the test cases.
|
3
|
+
|
4
|
+
=begin
|
5
|
+
|
6
|
+
|
7
|
+
#
|
8
|
+
# = test/tc_debug.rb
|
9
|
+
#
|
10
|
+
# Unit tests for the debugging utilities contained in <tt>dev-utils/debug.rb</tt>.
|
11
|
+
#
|
12
|
+
# These can be run directly, as in <tt>ruby -Ilib lib/dev-utils/test/debug-test.rb</tt>, or
|
13
|
+
# through the Rakefile, as in <tt>rake test</tt>.
|
14
|
+
#
|
15
|
+
# It's a little confusing to have <tt>dev-utils/test.rb</tt> as a library file and
|
16
|
+
# <tt>dev-utils/test/*</tt> as test cases. That's a coincidence in this case; most projects
|
17
|
+
# would not have a library file called <tt>test.rb</tt>. I'm trying out an approach to unit
|
18
|
+
# tests whereby they are placed in the <tt>lib</tt> directory, thus ensuring that they are
|
19
|
+
# accessed via the same <tt>$LOAD_PATH</tt> as the library itself. All other ways of
|
20
|
+
# organising unit tests I have found annoying, because careful load-path management is needed
|
21
|
+
# just to run them, which I find frustrating.
|
22
|
+
#
|
23
|
+
# It may turn out that I can find a really good alternative and promote that instead.
|
24
|
+
#
|
25
|
+
|
26
|
+
require 'dev-utils/debug'
|
27
|
+
|
28
|
+
require 'test/unit'
|
29
|
+
|
30
|
+
class TC_Debug < Test::Unit::TestCase
|
31
|
+
|
32
|
+
Address = Struct.new(:number, :road, :city)
|
33
|
+
class Person
|
34
|
+
attr_reader :name, :age, :address
|
35
|
+
def initialize(name, age, address)
|
36
|
+
@name, @age, @address = name, age, address
|
37
|
+
@unimportant = rand(100)
|
38
|
+
end
|
39
|
+
def ==(person)
|
40
|
+
self.name == person.name and self.age == person.age and self.address == person.address
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Test between some fundamental types. These do not have fields to compare between: they
|
46
|
+
# are immediate values.
|
47
|
+
#
|
48
|
+
def test_diff_0
|
49
|
+
assert_equal(nil, diff('abc', 'abc'))
|
50
|
+
assert_equal('Immediate values differ', diff('abc', 'def'))
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Test between a few simple Address structs. Structs don't have instance variables so
|
55
|
+
# they're a special case.
|
56
|
+
#
|
57
|
+
def test_diff_1
|
58
|
+
# No difference between objects.
|
59
|
+
a1 = Address.new(4, "Cumberland", "Sydney")
|
60
|
+
a2 = Address.new(4, "Cumberland", "Sydney")
|
61
|
+
assert_equal(nil, diff(a1, a2))
|
62
|
+
assert_equal(nil, diff(a2, a1))
|
63
|
+
|
64
|
+
# One difference between objects.
|
65
|
+
a3 = Address.new(4, "Cumberlond", "Sydney")
|
66
|
+
expected = ['road: "Cumberland"', 'road: "Cumberlond"']
|
67
|
+
assert_equal(expected, diff(a1, a3))
|
68
|
+
assert_equal(expected, diff(a2, a3))
|
69
|
+
expected = ['road: "Cumberlond"', 'road: "Cumberland"']
|
70
|
+
assert_equal(expected, diff(a3, a1))
|
71
|
+
assert_equal(expected, diff(a3, a2))
|
72
|
+
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# This continues the work of test_diff_1, but is seperated out because it's testing
|
76
|
+
# different stuff. Objects with multiple differences are compared. Differences should be
|
77
|
+
# reported in alphabetical order, since no fundamental order is guaranteed.
|
78
|
+
#
|
79
|
+
def test_diff_2
|
80
|
+
a1 = Address.new(4, "Cumberland", "Sydney")
|
81
|
+
|
82
|
+
# Two differences between objects.
|
83
|
+
a4 = Address.new(4, "Cumberlond", "Melbourne")
|
84
|
+
# Unless asked, only report the first difference.
|
85
|
+
expected = ['city: "Sydney"', 'city: "Melbourne"']
|
86
|
+
assert_equal(expected, diff(a1, a4))
|
87
|
+
# If asked, report the first or second difference.
|
88
|
+
assert_equal(expected, diff(a1, a4, 1))
|
89
|
+
expected = ['road: "Cumberland"', 'road: "Cumberlond"']
|
90
|
+
assert_equal(expected, diff(a1, a4, 2))
|
91
|
+
# If asked, report the third or greater difference, of which there is none.
|
92
|
+
assert_equal(nil, diff(a1, a4, 3))
|
93
|
+
assert_equal(nil, diff(a1, a4, 100))
|
94
|
+
# If asked, report all differences.
|
95
|
+
expected = []
|
96
|
+
expected << ['city: "Sydney"', 'city: "Melbourne"']
|
97
|
+
expected << ['road: "Cumberland"', 'road: "Cumberlond"']
|
98
|
+
assert_equal(expected, diff(a1, a4, :all))
|
99
|
+
# If asked, report number of differences.
|
100
|
+
assert_equal(2, diff(a1, a4, :n))
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Test between a few simple Person objects. They have an instance variable that is not an
|
105
|
+
# attribute, so it shouldn't influence the comparison.
|
106
|
+
#
|
107
|
+
# test_diff_2 did some testing of the advanced features, so we don't need to do those
|
108
|
+
# here.
|
109
|
+
#
|
110
|
+
def test_diff_3
|
111
|
+
p1 = Person.new('John Smith', 31, nil)
|
112
|
+
p2 = Person.new('John Smith', 31, nil) # same as p1
|
113
|
+
p3 = Person.new('John Brown', 31, nil) # name different from p1
|
114
|
+
p4 = Person.new('John Smith', 84, nil) # age different from p1
|
115
|
+
p5 = Person.new('Joan Brown', 84, nil) # name and age different from p1
|
116
|
+
|
117
|
+
assert_equal(nil, diff(p1, p2))
|
118
|
+
assert_equal(['name: "John Brown"', 'name: "John Smith"'], diff(p3, p1))
|
119
|
+
assert_equal(['name: "John Smith"', 'name: "John Brown"'], diff(p1, p3))
|
120
|
+
assert_equal(['age: 84', 'age: 31'], diff(p4, p1))
|
121
|
+
assert_equal(['age: 31', 'age: 84'], diff(p1, p4))
|
122
|
+
assert_equal(['age: 84', 'age: 31'], diff(p5, p1))
|
123
|
+
assert_equal(['name: "Joan Brown"', 'name: "John Smith"'], diff(p5, p1, 2))
|
124
|
+
assert_equal(2, diff(p5, p1, :n))
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# Now we get recursive, and compare Person objects that have Address objects within them.
|
129
|
+
#
|
130
|
+
def test_diff_4
|
131
|
+
p1 = Person.new('John Smith', 31, Address.new(4, 'Holmes', 'Sydney'))
|
132
|
+
p2 = Person.new('John Smith', 31, Address.new(4, 'Holmes', 'Sydney')) # == p1
|
133
|
+
p3 = Person.new('John Smith', 31, Address.new(4, 'Hawke', 'Sydney'))
|
134
|
+
|
135
|
+
assert_equal(p1, p2)
|
136
|
+
assert_equal(nil, diff(p1, p2))
|
137
|
+
assert_equal(nil, diff(p2, p1))
|
138
|
+
assert_equal(['address.road: "Hawke"', 'address.road: "Holmes"'], diff(p3, p1))
|
139
|
+
assert_equal(['address.road: "Hawke"', 'address.road: "Holmes"'], diff(p3, p1, 1))
|
140
|
+
assert_equal([['address.road: "Hawke"', 'address.road: "Holmes"']], diff(p3, p1, :all))
|
141
|
+
assert_equal(1, diff(p3, p1, :n))
|
142
|
+
|
143
|
+
# TODO: this should have more testing, but if that test passes, it's probably good enough
|
144
|
+
# for me to use now.
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_topology
|
148
|
+
fail "Not implemented"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
|
153
|
+
=end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.1
|
3
|
+
specification_version: 1
|
4
|
+
name: dev-utils
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "1.0"
|
7
|
+
date: 2004-10-08
|
8
|
+
summary: "Debugging utilities: breakpoints, debugging, and tracing."
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
author: Gavin Sinclair
|
12
|
+
email: gsinclair@soyabean.com.au
|
13
|
+
homepage: http://dev-utils.rubyforge.org
|
14
|
+
rubyforge_project: dev-utils
|
15
|
+
description: "Debugging utilities: breakpoints, debugging, and tracing."
|
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
|
+
- ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 1.8.1
|
26
|
+
version:
|
27
|
+
platform: ruby
|
28
|
+
files:
|
29
|
+
- HISTORY.txt
|
30
|
+
- MIT-LICENSE.txt
|
31
|
+
- Rakefile
|
32
|
+
- README.txt
|
33
|
+
- VERSION
|
34
|
+
- etc/doc
|
35
|
+
- etc/doc/DebuggingAids.textile
|
36
|
+
- etc/doc/generate.rb
|
37
|
+
- etc/doc/index.textile
|
38
|
+
- etc/doc/links.dat
|
39
|
+
- etc/doc/textile.css
|
40
|
+
- etc/doc/UnitTestOrganisation.textile
|
41
|
+
- examples/breakpoint-example.rb
|
42
|
+
- examples/debug.log
|
43
|
+
- examples/log-trace-example.rb
|
44
|
+
- lib/dev-utils
|
45
|
+
- lib/dev-utils/debug
|
46
|
+
- lib/dev-utils/debug.rb
|
47
|
+
- lib/dev-utils/test.rb
|
48
|
+
- lib/dev-utils/debug/diff.rb
|
49
|
+
- lib/dev-utils/debug/irb.rb
|
50
|
+
- lib/dev-utils/debug/log.rb
|
51
|
+
- test/tc_debug.rb
|
52
|
+
- test/TEST.rb
|
53
|
+
test_files: []
|
54
|
+
rdoc_options:
|
55
|
+
- "--main"
|
56
|
+
- README.txt
|
57
|
+
- "--title"
|
58
|
+
- dev-utils API Documentation
|
59
|
+
extra_rdoc_files:
|
60
|
+
- HISTORY.txt
|
61
|
+
- MIT-LICENSE.txt
|
62
|
+
- README.txt
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
requirements: []
|
66
|
+
dependencies:
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: extensions
|
69
|
+
version_requirement:
|
70
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
71
|
+
requirements:
|
72
|
+
-
|
73
|
+
- ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: "0.5"
|
76
|
+
version:
|