verify 0.3 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/RELEASE +8 -0
- data/lib/verify.rb +119 -88
- data/test/verify-verify-01.rb +1 -1
- metadata +1 -1
data/RELEASE
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
v 0.3.1
|
2
|
+
2009-06-24 Verify
|
3
|
+
-----------------
|
4
|
+
* Heavy refactoring, the code sucks much less now.
|
5
|
+
* Trying to get it to run with JRuby --1.9, no such luck, waiting for the next release.
|
6
|
+
|
7
|
+
|
8
|
+
v 0.3
|
1
9
|
2009-06-18 Verify ( Mockify )
|
2
10
|
-----------------------------
|
3
11
|
|
data/lib/verify.rb
CHANGED
@@ -63,77 +63,100 @@
|
|
63
63
|
|
64
64
|
module Lab419
|
65
65
|
module Verify
|
66
|
-
VERSION = "0.3"
|
66
|
+
VERSION = "0.3.1"
|
67
67
|
AUTHOR = "Robert Dober"
|
68
68
|
URLS = %w{http://labrador.rubyforge.org/verify}
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
|
73
|
-
|
74
|
-
report_stream = $stderr
|
72
|
+
# First we will create an annonymous statistics object into which
|
73
|
+
# we will extend all the functionalities now expressed by lambdas
|
75
74
|
|
76
|
-
|
77
|
-
|
75
|
+
ignore_messages = Object::new
|
76
|
+
ignore_messages.instance_eval do
|
77
|
+
def method_missing *args, &blk; nil end
|
78
78
|
end
|
79
79
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
80
|
+
new_stats = lambda do | parent = ignore_messages |
|
81
|
+
{ failed: 0,
|
82
|
+
verified: 0,
|
83
|
+
report_stream: $stderr,
|
84
|
+
messages: [],
|
85
|
+
parent: parent
|
86
|
+
}.extend(
|
87
|
+
Module::new do
|
88
|
+
def success
|
89
|
+
self[ :verified ] += 1
|
90
|
+
self[ :parent ].success
|
91
|
+
end
|
92
|
+
def failure
|
93
|
+
self[ :failed ] += 1
|
94
|
+
self[ :parent ].failure
|
95
|
+
end
|
84
96
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
report_stream << ( resume << "\n" )
|
96
|
-
report_stream << "+++" << " " * ( s - 6 ) << "+++"
|
97
|
-
report_stream << "\n"
|
98
|
-
report_stream << ( rchar * resume.size.pred << "\n" )
|
99
|
-
end
|
97
|
+
def fail_verification level, msg
|
98
|
+
p caller if $DEBUG
|
99
|
+
messages = fetch :messages
|
100
|
+
if level then
|
101
|
+
messages << "Error: #{msg} #{caller[level - 1]}"
|
102
|
+
else
|
103
|
+
messages << "Error: #{msg}"
|
104
|
+
end
|
105
|
+
failure
|
106
|
+
end
|
100
107
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
report = lambda do | msg = nil, stream = $stderr |
|
120
|
-
#stream << "\n"
|
121
|
-
messages.map{ |m| m << "\n" }.each do | line |
|
122
|
-
stream << line
|
108
|
+
def percentage
|
109
|
+
verified, failed = values_at( :verified, :failed )
|
110
|
+
total = verified + failed
|
111
|
+
total.zero? ?
|
112
|
+
"(***.**%)" :
|
113
|
+
"(%6.2f%%)" % ( 10_000 * ( verified ).to_f / total / 100 )
|
114
|
+
end
|
115
|
+
|
116
|
+
define_method :report do | msg = nil |
|
117
|
+
report_stream, messages, verified, failed = values_at( :report_stream, :messages, :verified, :failed )
|
118
|
+
messages.map{ |m| m << "\n" }.each do | line |
|
119
|
+
report_stream << line
|
120
|
+
end
|
121
|
+
|
122
|
+
rchar = failed.zero? ? "=" : "*"
|
123
|
+
resume =
|
124
|
+
"#{rchar}#{rchar} #{msg ? "#{msg}: " : ""}Verifications: #{verified+failed}, failed: #{failed}, succeeded: #{verified} #{percentage}"
|
125
|
+
report_stream << ( resume << "\n" )
|
123
126
|
end
|
124
127
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
128
|
+
def summary
|
129
|
+
report_stream, verified, failed = values_at( :report_stream, :verified, :failed )
|
130
|
+
report_stream << "\n"
|
131
|
+
resume =
|
132
|
+
"+++ S u m m a r y: Verifications: #{verified+failed}, failed: #{failed}, succeeded: #{verified} #{percentage} +++"
|
133
|
+
rchar = failed.zero? ? "=" : "*"
|
134
|
+
s = resume.size
|
135
|
+
report_stream << "+" * s
|
136
|
+
report_stream << "\n"
|
137
|
+
report_stream << "+++" << " " * ( s - 6 ) << "+++"
|
138
|
+
report_stream << "\n"
|
139
|
+
report_stream << ( resume << "\n" )
|
140
|
+
report_stream << "+++" << " " * ( s - 6 ) << "+++"
|
141
|
+
report_stream << "\n"
|
142
|
+
report_stream << ( rchar * resume.size.pred << "\n" )
|
143
|
+
end
|
131
144
|
|
132
|
-
|
133
|
-
verified += 1
|
134
|
-
total_verified += 1
|
135
|
-
end
|
145
|
+
end)
|
136
146
|
|
147
|
+
end
|
148
|
+
|
149
|
+
total_stats = new_stats.call
|
150
|
+
|
151
|
+
at_exit do
|
152
|
+
at_exit do
|
153
|
+
at_exit do
|
154
|
+
total_stats.summary
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
new_verifer = lambda do | stats |
|
137
160
|
Module::new do
|
138
161
|
|
139
162
|
begin
|
@@ -149,14 +172,14 @@ include( Module::new do
|
|
149
172
|
a = msg[ :actual ]
|
150
173
|
msg = msg[ :message ] || msg[ :msg ]
|
151
174
|
return fail_verification [ 2, "#{msg}\n.. target: #{t.inspect}\n.. actual: #{a.inspect}\n.. #{msg} in " ] unless t==a
|
152
|
-
return
|
175
|
+
return stats.success
|
153
176
|
end
|
154
|
-
return fail_verification
|
155
|
-
|
177
|
+
return stats.fail_verification( 2, "#{msg} in " ) unless blk[]
|
178
|
+
stats.success
|
156
179
|
rescue Exception => e
|
157
|
-
fail_verification
|
180
|
+
stats.fail_verification( nil, "#{msg} #{e.message} in #{e.backtrace.first}" )
|
158
181
|
end
|
159
|
-
end
|
182
|
+
end # :verify
|
160
183
|
|
161
184
|
define_method :refute do | msg=nil, &blk |
|
162
185
|
begin
|
@@ -164,42 +187,50 @@ include( Module::new do
|
|
164
187
|
t = msg[ :target ]
|
165
188
|
a = msg[ :actual ]
|
166
189
|
msg = msg[ :message ] || msg[ :msg ]
|
167
|
-
return fail_verification
|
168
|
-
return
|
190
|
+
return stats.fail_verification( 2, "#{msg}\n.. target: #{t.inspect}\n.. actual: #{a.inspect}\n.. #{msg} in " ) if t==a
|
191
|
+
return stats.success
|
169
192
|
end
|
170
|
-
return fail_verification
|
171
|
-
|
193
|
+
return stats.fail_verification( 2, "#{msg} in " ) if blk[]
|
194
|
+
stats.success
|
172
195
|
rescue Exception => e
|
173
|
-
fail_verification
|
196
|
+
stats.fail_verification( nil, "#{msg} #{e.message} in #{e.backtrace.first}" )
|
174
197
|
end
|
175
|
-
end
|
198
|
+
end # :refute
|
176
199
|
|
177
200
|
define_method :verify_exceptions do | *excpts, &blk |
|
178
201
|
begin
|
179
202
|
blk[]
|
180
203
|
fail_verification[ 2, "None of #{excpts} thrown in " ]
|
181
204
|
rescue *excpts
|
182
|
-
|
205
|
+
stats.success
|
183
206
|
rescue Exception => e
|
184
|
-
fail_verification
|
207
|
+
stats.fail_verification( 3, "#{e} #{e.class} was thrown, but one of \"#{excpts}\" was expected in " )
|
185
208
|
end
|
186
|
-
end
|
209
|
+
end # :verify_exception
|
187
210
|
|
188
211
|
extend self
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
212
|
+
end # Module::new
|
213
|
+
end # new_verifier
|
214
|
+
|
215
|
+
include( Module::new do
|
216
|
+
if RUBY_ENGINE =~ /jruby/i then # BEGIN go away after fix of JRUBY-3774
|
217
|
+
define_method :__Verify__JRUBY_3774_workaround do |ver_msg, ver_blk|
|
218
|
+
stats = new_stats[ total_stats ]
|
219
|
+
verifier = new_verifer[ stats ]
|
220
|
+
verifier.module_eval( &ver_blk )
|
221
|
+
stats.report ver_msg
|
222
|
+
end
|
223
|
+
def Verify ver_msg = nil, &ver_rvlk
|
224
|
+
__Verify__JRUBY_3774_workaround ver_msg, ver_rvlk
|
225
|
+
end
|
226
|
+
else # END go away after fix of JRUBY-3774
|
227
|
+
define_method :Verify do |ver_msg=nil, &ver_blk|
|
228
|
+
stats = new_stats[ total_stats ]
|
229
|
+
verifier = new_verifer[ stats ]
|
230
|
+
verifier.module_eval( &ver_blk )
|
231
|
+
stats.report ver_msg
|
232
|
+
end # : Verify
|
233
|
+
end # go away after fix of JRUBY-3774
|
234
|
+
end )
|
235
|
+
|
236
|
+
# vim: sw=2 sts=2 ft=ruby nu expandtab:
|
data/test/verify-verify-01.rb
CHANGED