riel 1.1.16 → 1.1.17
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/README.md +2 -37
- data/lib/riel/log/log.rb +17 -24
- data/lib/riel/log/loggable.rb +13 -15
- data/lib/riel/log/logger.rb +34 -66
- data/lib/riel/log.rb +0 -63
- data/lib/riel/optproc.rb +0 -3
- data/lib/riel/string.rb +0 -2
- data/lib/riel.rb +1 -1
- data/test/riel/log/format_test.rb +48 -0
- data/test/riel/optproc_test.rb +1 -30
- data/test/riel/{log_stack_test.rb → testlog/log_stack_test.rb} +0 -0
- data/test/riel/testlog/log_test.rb +254 -0
- data/test/riel/testlog/loggable_test.rb +31 -0
- metadata +89 -133
- data/lib/riel/ansicolor.rb +0 -91
- data/lib/riel/asciitable/cell.rb +0 -82
- data/lib/riel/asciitable/column.rb +0 -26
- data/lib/riel/asciitable/row.rb +0 -105
- data/lib/riel/asciitable/table.rb +0 -295
- data/lib/riel/text/ansi/ansi_color.rb +0 -31
- data/lib/riel/text/ansi/ansi_colors.rb +0 -16
- data/lib/riel/text/ansi/ansi_highlight.rb +0 -69
- data/lib/riel/text/ansi/ansi_list.rb +0 -17
- data/lib/riel/text/ansi/ansi_palette.rb +0 -48
- data/lib/riel/text/ansi/attributes.rb +0 -21
- data/lib/riel/text/ansi/backgrounds.rb +0 -13
- data/lib/riel/text/ansi/color.rb +0 -62
- data/lib/riel/text/ansi/foregrounds.rb +0 -12
- data/lib/riel/text/ansi/grey.rb +0 -30
- data/lib/riel/text/ansi/grey_palette.rb +0 -36
- data/lib/riel/text/ansi/palette.rb +0 -18
- data/lib/riel/text/ansi/rgb_color.rb +0 -28
- data/lib/riel/text/ansi/rgb_highlighter.rb +0 -73
- data/lib/riel/text/ansi/rgb_palette.rb +0 -49
- data/lib/riel/text/highlight.rb +0 -130
- data/lib/riel/text/highlightable.rb +0 -85
- data/lib/riel/text/html_highlight.rb +0 -98
- data/lib/riel/text/non_highlight.rb +0 -17
- data/lib/riel/text/string.rb +0 -10
- data/lib/riel/text.rb +0 -4
- data/test/riel/asciitable/table_test.rb +0 -77
- data/test/riel/log_test.rb +0 -164
- data/test/riel/text/ansi/ansi_highlight_test.rb +0 -116
- data/test/riel/text/ansi/ansi_palette_test.rb +0 -65
- data/test/riel/text/ansi/grey_palette_test.rb +0 -39
- data/test/riel/text/ansi/rgb_highlighter_test.rb +0 -99
- data/test/riel/text/ansi/rgb_palette_test.rb +0 -122
- data/test/riel/text/highlightable_test.rb +0 -24
- data/test/riel/text/string_test.rb +0 -47
- data/test/riel/text_test.rb +0 -62
data/README.md
CHANGED
@@ -3,8 +3,8 @@ RIEL - Extensions to core Ruby libraries
|
|
3
3
|
|
4
4
|
## DESCRIPTION
|
5
5
|
|
6
|
-
RIEL is a library that extends core Ruby libraries
|
7
|
-
framework
|
6
|
+
RIEL is a library that extends core Ruby libraries, and adds a logging
|
7
|
+
framework and an option processor.
|
8
8
|
|
9
9
|
## CLASSES
|
10
10
|
|
@@ -22,47 +22,12 @@ array.
|
|
22
22
|
The method `run` runs a command, returning the lines of output, and optionally
|
23
23
|
calling a block with each line, and the line number, if the block takes two
|
24
24
|
arguments.
|
25
|
-
|
26
|
-
### ANSIHighlighter
|
27
|
-
|
28
|
-
This class wraps strings in ANSI colors. For example:
|
29
|
-
|
30
|
-
"foo".blue
|
31
|
-
"bar".bold.blue.on_white
|
32
|
-
|
33
|
-
It also handles RGB values (on a 0-5 scale, not 0-255):
|
34
|
-
|
35
|
-
"foo".rgb(3, 1, 5)
|
36
|
-
"bar".on_rgb(1, 0, 4)
|
37
|
-
|
38
|
-
Colors and attributes can be chained:
|
39
|
-
|
40
|
-
"hey!".rgb(0, 3, 5).on_rgb(5, 2, 1).bold.underline
|
41
|
-
|
42
|
-
Aliases (names) for colors can be defined:
|
43
|
-
|
44
|
-
Text::ANSIHighlighter.instance.add_alias :teal, 1, 4, 4
|
45
|
-
puts "hello, word".teal
|
46
|
-
|
47
|
-
Background aliases are supported:
|
48
|
-
|
49
|
-
Text::ANSIHighlighter.instance.add_alias :on_slate, 0, 1, 1
|
50
|
-
puts "hello, word".teal
|
51
25
|
|
52
26
|
### SetDiff
|
53
27
|
|
54
28
|
This class compares enumerables as sets, A fully including B, B fully including
|
55
29
|
A, or A and B having common elements.
|
56
30
|
|
57
|
-
### ANSIPalette
|
58
|
-
|
59
|
-
This class prints the set of ANSI colors as foregrounds and backgrounds.
|
60
|
-
|
61
|
-
### RGBPalette
|
62
|
-
|
63
|
-
This class prints the set of RGB (extended ANSI) colors as foregrounds,
|
64
|
-
backgrounds and combinations.
|
65
|
-
|
66
31
|
### ANSIITable
|
67
32
|
|
68
33
|
This class prints a spreadsheet-like table of data.
|
data/lib/riel/log/log.rb
CHANGED
@@ -9,9 +9,10 @@
|
|
9
9
|
# Documentation:: Author
|
10
10
|
#
|
11
11
|
|
12
|
-
require 'riel/ansicolor'
|
13
12
|
require 'riel/log/logger'
|
14
13
|
require 'riel/log/severity'
|
14
|
+
require 'rubygems'
|
15
|
+
require 'rainbow'
|
15
16
|
|
16
17
|
#
|
17
18
|
# == Log
|
@@ -53,6 +54,10 @@ require 'riel/log/severity'
|
|
53
54
|
module RIEL
|
54
55
|
class Log
|
55
56
|
$LOGGING_LEVEL = nil
|
57
|
+
|
58
|
+
DEFAULT_FILENAME_WIDTH = -25
|
59
|
+
DEFAULT_LINENUM_WIDTH = 4
|
60
|
+
DEFAULT_FUNCTION_WIDTH = -20
|
56
61
|
|
57
62
|
include Log::Severity
|
58
63
|
|
@@ -67,48 +72,36 @@ module RIEL
|
|
67
72
|
end
|
68
73
|
|
69
74
|
def self.method_missing meth, *args, &blk
|
70
|
-
|
71
|
-
|
75
|
+
validcolors = Sickill::Rainbow::TERM_COLORS
|
76
|
+
# only handling foregrounds, not backgrounds
|
77
|
+
if code = validcolors[meth]
|
78
|
+
add_color_method meth.to_s, code + 30
|
72
79
|
send meth, *args, &blk
|
73
80
|
else
|
74
81
|
super
|
75
82
|
end
|
76
83
|
end
|
77
84
|
|
85
|
+
def self.respond_to? meth
|
86
|
+
validcolors = Sickill::Rainbow::TERM_COLORS
|
87
|
+
validcolors.include?(meth) || super
|
88
|
+
end
|
89
|
+
|
78
90
|
def self.add_color_method color, code
|
79
91
|
instmeth = Array.new
|
80
|
-
instmeth << "def #{color} msg = \"\", lvl = DEBUG, depth = 1, cname = nil, &blk"
|
92
|
+
instmeth << "def #{color} msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk"
|
81
93
|
instmeth << " log(\"\\e[#{code}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
|
82
94
|
instmeth << "end"
|
83
95
|
instance_eval instmeth.join("\n")
|
84
96
|
|
85
97
|
clsmeth = Array.new
|
86
|
-
clsmeth << "def #{color} msg = \"\", lvl = DEBUG, depth = 1, cname = nil, &blk"
|
98
|
+
clsmeth << "def #{color} msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk"
|
87
99
|
clsmeth << " logger.#{color}(\"\\e[#{code}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
|
88
100
|
clsmeth << "end"
|
89
101
|
|
90
102
|
class_eval clsmeth.join("\n")
|
91
103
|
end
|
92
104
|
|
93
|
-
if false
|
94
|
-
ANSIColor::ATTRIBUTES.sort.each do |attr|
|
95
|
-
methname = attr[0]
|
96
|
-
|
97
|
-
instmeth = Array.new
|
98
|
-
instmeth << "def #{methname}(msg = \"\", lvl = DEBUG, depth = 1, cname = nil, &blk)"
|
99
|
-
instmeth << " log(\"\\e[#{attr[1]}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
|
100
|
-
instmeth << "end"
|
101
|
-
instance_eval instmeth.join("\n")
|
102
|
-
|
103
|
-
clsmeth = Array.new
|
104
|
-
clsmeth << "def #{methname}(msg = \"\", lvl = DEBUG, depth = 1, cname = nil, &blk)"
|
105
|
-
clsmeth << " logger.#{methname}(\"\\e[#{attr[1]}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
|
106
|
-
clsmeth << "end"
|
107
|
-
|
108
|
-
class_eval clsmeth.join("\n")
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
105
|
def self.set_default_widths
|
113
106
|
logger.set_default_widths
|
114
107
|
end
|
data/lib/riel/log/loggable.rb
CHANGED
@@ -10,6 +10,8 @@
|
|
10
10
|
#
|
11
11
|
|
12
12
|
require 'riel/log/log'
|
13
|
+
require 'rubygems'
|
14
|
+
require 'rainbow'
|
13
15
|
|
14
16
|
#
|
15
17
|
# == Loggable
|
@@ -73,31 +75,27 @@ module RIEL
|
|
73
75
|
end
|
74
76
|
|
75
77
|
def method_missing meth, *args, &blk
|
76
|
-
|
77
|
-
|
78
|
+
validcolors = Sickill::Rainbow::TERM_COLORS
|
79
|
+
# only handling foregrounds, not backgrounds
|
80
|
+
if code = validcolors[meth]
|
81
|
+
add_color_method meth.to_s, code + 30
|
78
82
|
send meth, *args, &blk
|
79
83
|
else
|
80
84
|
super
|
81
85
|
end
|
82
86
|
end
|
83
87
|
|
84
|
-
def
|
88
|
+
def respond_to? meth
|
89
|
+
validcolors = Sickill::Rainbow::TERM_COLORS
|
90
|
+
validcolors.include?(meth) || super
|
91
|
+
end
|
92
|
+
|
93
|
+
def add_color_method color, code
|
85
94
|
meth = Array.new
|
86
|
-
meth << "def #{color}
|
95
|
+
meth << "def #{color}(msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk)"
|
87
96
|
meth << " Log.#{color} msg, lvl, depth + 1, self.class.to_s, &blk"
|
88
97
|
meth << "end"
|
89
98
|
self.class.module_eval meth.join("\n")
|
90
99
|
end
|
91
|
-
|
92
|
-
if false
|
93
|
-
ANSIColor::ATTRIBUTES.sort.each do |attr|
|
94
|
-
methname = attr[0]
|
95
|
-
meth = Array.new
|
96
|
-
meth << "def #{methname} msg = \"\", lvl = Log::DEBUG, depth = 1, &blk"
|
97
|
-
meth << " Log.#{methname} msg, lvl, depth + 1, self.class.to_s, &blk"
|
98
|
-
meth << "end"
|
99
|
-
module_eval meth.join("\n")
|
100
|
-
end
|
101
|
-
end
|
102
100
|
end
|
103
101
|
end
|
data/lib/riel/log/logger.rb
CHANGED
@@ -9,8 +9,10 @@
|
|
9
9
|
# Documentation:: Author
|
10
10
|
#
|
11
11
|
|
12
|
-
require '
|
12
|
+
require 'rubygems'
|
13
|
+
require 'rainbow'
|
13
14
|
require 'riel/log/severity'
|
15
|
+
require 'riel/log/format'
|
14
16
|
|
15
17
|
#
|
16
18
|
# == Logger
|
@@ -71,7 +73,7 @@ module RIEL
|
|
71
73
|
end
|
72
74
|
|
73
75
|
def set_default_widths
|
74
|
-
set_widths
|
76
|
+
set_widths Log::DEFAULT_FILENAME_WIDTH, Log::DEFAULT_LINENUM_WIDTH, Log::DEFAULT_FUNCTION_WIDTH
|
75
77
|
end
|
76
78
|
|
77
79
|
def verbose
|
@@ -88,8 +90,8 @@ module RIEL
|
|
88
90
|
# lines with zeros (e.g., "00317") the line_width argument must be a string,
|
89
91
|
# not an integer.
|
90
92
|
def set_widths file_width, line_width, func_width
|
91
|
-
@file_width
|
92
|
-
@line_width
|
93
|
+
@file_width = file_width
|
94
|
+
@line_width = line_width
|
93
95
|
@function_width = func_width
|
94
96
|
|
95
97
|
@format = "[%#{file_width}s:%#{line_width}d] {%#{func_width}s}"
|
@@ -174,6 +176,11 @@ module RIEL
|
|
174
176
|
file, line, func = md[1], md[2], (md[3] || "")
|
175
177
|
# file.sub!(/.*\//, "")
|
176
178
|
|
179
|
+
# Ruby 1.9 expands the file name, but 1.8 doesn't:
|
180
|
+
pn = Pathname.new(file).expand_path
|
181
|
+
|
182
|
+
file = pn.to_s
|
183
|
+
|
177
184
|
if cname
|
178
185
|
func = cname + "#" + func
|
179
186
|
end
|
@@ -185,42 +192,12 @@ module RIEL
|
|
185
192
|
end
|
186
193
|
end
|
187
194
|
|
188
|
-
def trim_left str, maxlen
|
189
|
-
str[0 ... maxlen.to_i.abs]
|
190
|
-
end
|
191
|
-
|
192
|
-
def trim_right str, maxlen
|
193
|
-
mxln = maxlen.abs
|
194
|
-
|
195
|
-
# magic number 3 for the ellipses ...
|
196
|
-
|
197
|
-
if str.length > mxln
|
198
|
-
path = str.split('/')
|
199
|
-
newstr = "..."
|
200
|
-
path.reverse.each do |element|
|
201
|
-
if newstr.length + element.length > mxln
|
202
|
-
while newstr.length < mxln
|
203
|
-
newstr.insert 0, " "
|
204
|
-
end
|
205
|
-
return newstr
|
206
|
-
else
|
207
|
-
if newstr.length > 3
|
208
|
-
newstr.insert 3, "/"
|
209
|
-
end
|
210
|
-
newstr.insert 3, element
|
211
|
-
end
|
212
|
-
end
|
213
|
-
newstr
|
214
|
-
else
|
215
|
-
str
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
195
|
def print_formatted file, line, func, msg, lvl, &blk
|
220
196
|
if trim
|
221
|
-
|
222
|
-
|
223
|
-
|
197
|
+
fmt = Format.new
|
198
|
+
file = fmt.trim_right file, @file_width
|
199
|
+
line = fmt.trim_left line, @line_width
|
200
|
+
func = fmt.trim_left func, @function_width
|
224
201
|
end
|
225
202
|
|
226
203
|
hdr = sprintf @format, file, line, func
|
@@ -237,31 +214,41 @@ module RIEL
|
|
237
214
|
end
|
238
215
|
end
|
239
216
|
|
240
|
-
|
217
|
+
msg = msg.to_s.chomp
|
218
|
+
|
219
|
+
if lvlcol = @colors[lvl]
|
241
220
|
if colorize_line
|
242
|
-
|
221
|
+
line = hdr + " " + msg
|
222
|
+
@output.puts line.color(lvlcol)
|
243
223
|
else
|
244
|
-
@output.puts hdr + " " +
|
224
|
+
@output.puts hdr + " " + msg.color(lvlcol)
|
245
225
|
end
|
246
226
|
else
|
247
|
-
@output.puts hdr + " " + msg
|
227
|
+
@output.puts hdr + " " + msg
|
248
228
|
end
|
249
229
|
end
|
250
230
|
|
251
231
|
def set_color lvl, color
|
252
|
-
@colors[lvl] =
|
232
|
+
@colors[lvl] = color
|
253
233
|
end
|
254
234
|
|
255
|
-
def
|
256
|
-
|
257
|
-
|
235
|
+
def method_missing meth, *args, &blk
|
236
|
+
validcolors = Sickill::Rainbow::TERM_COLORS
|
237
|
+
# only handling foregrounds, not backgrounds
|
238
|
+
if code = validcolors[meth]
|
239
|
+
add_color_method meth.to_s, code + 30
|
258
240
|
send meth, *args, &blk
|
259
241
|
else
|
260
242
|
super
|
261
243
|
end
|
262
244
|
end
|
263
245
|
|
264
|
-
def
|
246
|
+
def respond_to? meth
|
247
|
+
validcolors = Sickill::Rainbow::TERM_COLORS
|
248
|
+
validcolors.include?(meth) || super
|
249
|
+
end
|
250
|
+
|
251
|
+
def add_color_method color, code
|
265
252
|
instmeth = Array.new
|
266
253
|
instmeth << "def #{color}(msg = \"\", lvl = DEBUG, depth = 1, cname = nil, &blk)"
|
267
254
|
instmeth << " log(\"\\e[#{code}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
|
@@ -275,24 +262,5 @@ module RIEL
|
|
275
262
|
|
276
263
|
class_eval clsmeth.join("\n")
|
277
264
|
end
|
278
|
-
|
279
|
-
if false
|
280
|
-
ANSIColor::ATTRIBUTES.sort.each do |attr|
|
281
|
-
methname = attr[0]
|
282
|
-
|
283
|
-
instmeth = Array.new
|
284
|
-
instmeth << "def #{methname}(msg = \"\", lvl = DEBUG, depth = 1, cname = nil, &blk)"
|
285
|
-
instmeth << " log(\"\\e[#{attr[1]}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
|
286
|
-
instmeth << "end"
|
287
|
-
instance_eval instmeth.join("\n")
|
288
|
-
|
289
|
-
clsmeth = Array.new
|
290
|
-
clsmeth << "def #{methname}(msg = \"\", lvl = DEBUG, depth = 1, cname = nil, &blk)"
|
291
|
-
clsmeth << " logger.#{methname}(\"\\e[#{attr[1]}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)"
|
292
|
-
clsmeth << "end"
|
293
|
-
|
294
|
-
class_eval clsmeth.join("\n")
|
295
|
-
end
|
296
|
-
end
|
297
265
|
end
|
298
266
|
end
|
data/lib/riel/log.rb
CHANGED
@@ -19,66 +19,3 @@ module RIEL
|
|
19
19
|
end
|
20
20
|
|
21
21
|
include RIEL
|
22
|
-
|
23
|
-
if __FILE__ == $0
|
24
|
-
Log.verbose = true
|
25
|
-
Log.set_widths 15, -5, -35
|
26
|
-
#Log.outfile = "/tmp/log." + $$.to_s
|
27
|
-
|
28
|
-
class Demo
|
29
|
-
include Loggable
|
30
|
-
|
31
|
-
def initialize
|
32
|
-
# log "hello"
|
33
|
-
Log.set_color Log::DEBUG, "cyan"
|
34
|
-
Log.set_color Log::INFO, "bold cyan"
|
35
|
-
Log.set_color Log::WARN, "reverse"
|
36
|
-
Log.set_color Log::ERROR, "bold red"
|
37
|
-
Log.set_color Log::FATAL, "bold white on red"
|
38
|
-
end
|
39
|
-
|
40
|
-
def meth
|
41
|
-
# log
|
42
|
-
|
43
|
-
i = 4
|
44
|
-
# info { "i: #{i}" }
|
45
|
-
|
46
|
-
i /= 3
|
47
|
-
debug { "i: #{i}" }
|
48
|
-
|
49
|
-
i **= 3
|
50
|
-
info "i: #{i}"
|
51
|
-
|
52
|
-
i **= 2
|
53
|
-
warn "i: #{i}"
|
54
|
-
|
55
|
-
i <<= 4
|
56
|
-
error "i: #{i}"
|
57
|
-
|
58
|
-
i <<= 1
|
59
|
-
fatal "i: #{i}"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
class Another
|
64
|
-
include Loggable
|
65
|
-
|
66
|
-
def Another.cmeth
|
67
|
-
# /// "Log" only in instance methods
|
68
|
-
# log "I'm sorry, Dave, I'm afraid I can't do that."
|
69
|
-
|
70
|
-
# But this is legal.
|
71
|
-
Log.log "happy, happy, joy, joy"
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
demo = Demo.new
|
76
|
-
demo.meth
|
77
|
-
|
78
|
-
# Log.colorize_line = true
|
79
|
-
|
80
|
-
# demo.meth
|
81
|
-
# Another.cmeth
|
82
|
-
|
83
|
-
# Log.info "we are done."
|
84
|
-
end
|
data/lib/riel/optproc.rb
CHANGED
data/lib/riel/string.rb
CHANGED
data/lib/riel.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/ruby -w
|
2
|
+
# -*- ruby -*-
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'stringio'
|
7
|
+
require 'riel/log/format'
|
8
|
+
require 'riel/log/loggable'
|
9
|
+
|
10
|
+
module RIEL
|
11
|
+
class FormatTestCase < Test::Unit::TestCase
|
12
|
+
include RIEL::Loggable
|
13
|
+
|
14
|
+
def run_trim_left_test expected, length, str = "something"
|
15
|
+
trimmed = Format.new.trim_left(str, length)
|
16
|
+
assert_equal expected, trimmed
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_trim_left_short_positive_number
|
20
|
+
run_trim_left_test "some", 4
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_trim_left_long
|
24
|
+
run_trim_left_test "something", 10
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_trim_left_short_negative_number
|
28
|
+
run_trim_left_test "some", -4
|
29
|
+
end
|
30
|
+
|
31
|
+
def run_trim_right_test expected, length, str = "something"
|
32
|
+
trimmed = Format.new.trim_right(str, length)
|
33
|
+
assert_equal expected, trimmed
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_trim_right_short_positive_number
|
37
|
+
run_trim_right_test " ...", 5
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_trim_right_long
|
41
|
+
run_trim_right_test "something", 10
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_trim_right_short_negative_number
|
45
|
+
run_trim_right_test " ...", -5
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/test/riel/optproc_test.rb
CHANGED
@@ -12,35 +12,6 @@ class OptProcTestCase < Test::Unit::TestCase
|
|
12
12
|
ENV['HOME'] = '/this/should/not/exist'
|
13
13
|
end
|
14
14
|
|
15
|
-
def run_test args, exp, &blk
|
16
|
-
expected = DEFAULTS.merge(exp)
|
17
|
-
|
18
|
-
# ignore what they have in ENV[HOME]
|
19
|
-
ENV['HOME'] = '/this/should/not/exist'
|
20
|
-
|
21
|
-
origargs = args.dup
|
22
|
-
|
23
|
-
gopt = GlarkOptions.instance
|
24
|
-
gopt.run args
|
25
|
-
|
26
|
-
expected.sort { |a, b| a[0].to_s <=> b[0].to_s }.each do |opt, exval|
|
27
|
-
meth = gopt.method(opt)
|
28
|
-
val = meth.call
|
29
|
-
if val.kind_of? Array
|
30
|
-
assert_equal exval.length, val.length, "#{opt} => #{exval.class}.length #{exval.inspect}; #{val.class}.length #{val.inspect}; #{origargs.inspect}"
|
31
|
-
(0 ... exval.length).each do |idx|
|
32
|
-
assert_equal exval[idx], val[idx], "#{opt}[#{idx}] => #{exval.class}.length #{exval.inspect}; #{val.class}.length #{val.inspect}; #{origargs.inspect}"
|
33
|
-
end
|
34
|
-
else
|
35
|
-
assert_equal exval, val, "#{opt} => #{exval.class} #{exval.inspect}; #{val.class} #{val.inspect}; #{origargs.inspect}"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
blk.call(gopt) if blk
|
40
|
-
|
41
|
-
gopt.reset
|
42
|
-
end
|
43
|
-
|
44
15
|
def run_match_tag_test opt, exp, tag
|
45
16
|
m = opt.match [ tag ]
|
46
17
|
match = nil
|
@@ -80,7 +51,7 @@ class OptProcTestCase < Test::Unit::TestCase
|
|
80
51
|
end
|
81
52
|
end
|
82
53
|
|
83
|
-
def run_match_value_test
|
54
|
+
def run_match_value_test opt, exp, val
|
84
55
|
m = opt.match_value val
|
85
56
|
assert !!m == !!exp, "match value #{val}; expected: #{exp.inspect}; actual: #{m.inspect}"
|
86
57
|
end
|
File without changes
|