core_ex 0.2.0 → 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/NEWS +39 -1
- data/SPEC.dyn.yml +6 -6
- data/SPEC.gemspec +13 -0
- data/SPEC.yml +3 -3
- data/lib/core_ex/dependencies_ext/constant_load_path.rb +23 -0
- data/lib/core_ex/embedded_tests.rb +29 -23
- data/lib/core_ex/enumerable.rb +10 -18
- data/lib/core_ex/exception.rb +24 -21
- data/lib/core_ex/file_utils.rb +51 -0
- data/lib/core_ex/module/attr_once.rb +41 -0
- data/lib/core_ex/module/import.rb +28 -0
- data/lib/core_ex/module/mix_in_with_args.rb +267 -0
- data/lib/core_ex/object/instance_eval_with_args.rb +56 -0
- data/lib/core_ex/object/singleton_class.rb +78 -0
- data/lib/core_ex/object/the_first_time.rb +32 -0
- data/lib/core_ex/pathname.rb +268 -164
- data/lib/core_ex/proc.rb +77 -0
- data/lib/core_ex/rakefile_base.rf +93 -51
- data/lib/core_ex/require.rb +43 -384
- data/lib/core_ex/string.rb +52 -41
- data/lib/core_ex/time.rb +26 -41
- data/lib/core_ex/try_dup.rb +68 -0
- data/lib/core_ex/yaml.rb +103 -100
- data/lib/core_ex.rb +246 -35
- data/lib/{core_ex/dtime.rb → d_time.rb} +36 -22
- data/lib/{core_ex/dumpable_proc.rb → dumpable_proc.rb} +1 -2
- data/lib/{core_ex/pathlist.rb → path_list.rb} +111 -63
- data/lib/{core_ex/temp_path.rb → temp_path.rb} +55 -41
- data/lib/{core_ex/test/unit/ui/yaml/testrunner.rb → test/unit/u_i/yaml/test_runner.rb} +7 -10
- data/lib/{core_ex/version.rb → version.rb} +4 -7
- data/lib/yaml_extension.rb +78 -0
- data/test/check-core_ex.yml +6 -8
- data/test/check-pkg-core_ex.yml +3 -6
- data/test/sanity/multiple-requires.yml +41 -17
- data/test/sanity/single-requires.yml +36 -20
- data/test/sanity-suite.yml +5 -7
- data/test/test-unit-setup.rb +11 -3
- data/test/unit-suite.yml +8 -9
- metadata +35 -13
- data/lib/core_ex/attr_once.rb +0 -36
- data/lib/core_ex/fileutils.rb +0 -44
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
2
|
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License:: Gnu General Public License.
|
4
|
-
# Revision:: $Id:
|
4
|
+
# Revision:: $Id: path_list.rb 336 2005-09-06 20:32:49Z ertai $
|
5
5
|
#--
|
6
6
|
# Copyright (c) 2003, 2004 Jim Weirich
|
7
7
|
#
|
@@ -26,48 +26,6 @@
|
|
26
26
|
#++
|
27
27
|
#
|
28
28
|
|
29
|
-
# Some objects are dupable, some are not. So we define a version of
|
30
|
-
# dup (called rake_dup) that returns self on the handful of classes
|
31
|
-
# that are not dupable.
|
32
|
-
|
33
|
-
unless respond_to? :rake_dup
|
34
|
-
module Kernel
|
35
|
-
# Duplicate an object if it can be duplicated. If it can not be
|
36
|
-
# cloned or duplicated, then just return the original object.
|
37
|
-
def rake_dup()
|
38
|
-
dup
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
[NilClass, FalseClass, TrueClass, Fixnum, Symbol].each do |clazz|
|
43
|
-
clazz.class_eval {
|
44
|
-
# Duplicate an object if it can be duplicated. If it can not be
|
45
|
-
# cloned or duplicated, then just return the original object.
|
46
|
-
def rake_dup() self end
|
47
|
-
}
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
######################################################################
|
52
|
-
# User defined methods to be added to String.
|
53
|
-
#
|
54
|
-
class String
|
55
|
-
unless instance_methods.include? "ext"
|
56
|
-
# Replace the file extension with +newext+. If there is no
|
57
|
-
# extenson on the string, append the new extension to the end. If
|
58
|
-
# the new extension is not given, or is the empty string, remove
|
59
|
-
# any existing extension.
|
60
|
-
#
|
61
|
-
# +ext+ is a user added method for the String class.
|
62
|
-
def ext(newext='')
|
63
|
-
return self.dup if ['.', '..'].include? self
|
64
|
-
if newext != ''
|
65
|
-
newext = (newext =~ /^\./) ? newext : ("." + newext)
|
66
|
-
end
|
67
|
-
dup.sub!(%r(([^/\\])\.[^./\\]*$)) { $1 + newext } || self + newext
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
29
|
|
72
30
|
#
|
73
31
|
# PathList is essentially based on FileList from Rake.
|
@@ -88,17 +46,17 @@ end
|
|
88
46
|
# element of the PathList/Array is requested, the pending patterns
|
89
47
|
# are resolved into a real list of file names.
|
90
48
|
#
|
91
|
-
class PathList
|
49
|
+
class PathList
|
92
50
|
|
93
51
|
def clone
|
94
52
|
sibling = self.class.new
|
95
53
|
instance_variables.each do |ivar|
|
96
54
|
value = self.instance_variable_get(ivar)
|
97
|
-
sibling.instance_variable_set(ivar, value.
|
55
|
+
sibling.instance_variable_set(ivar, value.try_dup)
|
98
56
|
end
|
99
57
|
sibling
|
100
58
|
end
|
101
|
-
|
59
|
+
alias_method :dup, :clone
|
102
60
|
|
103
61
|
# == Method Delegation
|
104
62
|
#
|
@@ -137,9 +95,9 @@ class PathList
|
|
137
95
|
compact flatten uniq values_at
|
138
96
|
+ - & |
|
139
97
|
]
|
140
|
-
|
98
|
+
|
141
99
|
DELEGATING_METHODS = (ARRAY_METHODS + MUST_DEFINE - MUST_NOT_DEFINE).sort.uniq
|
142
|
-
|
100
|
+
|
143
101
|
# Now do the delegation.
|
144
102
|
DELEGATING_METHODS.each_with_index do |sym, i|
|
145
103
|
if SPECIAL_RETURN.include?(sym)
|
@@ -148,7 +106,7 @@ class PathList
|
|
148
106
|
def #{sym}(*args, &block)
|
149
107
|
resolve if @pending
|
150
108
|
result = @items.send(:#{sym}, *args, &block)
|
151
|
-
PathList.
|
109
|
+
PathList.import result
|
152
110
|
end
|
153
111
|
}, __FILE__, ln
|
154
112
|
else
|
@@ -203,8 +161,8 @@ class PathList
|
|
203
161
|
@pending = true
|
204
162
|
self
|
205
163
|
end
|
206
|
-
|
207
|
-
|
164
|
+
alias_method :add, :include
|
165
|
+
|
208
166
|
# Register a list of file name patterns that should be excluded
|
209
167
|
# from the list. Patterns may be regular expressions, glob
|
210
168
|
# patterns or regular strings.
|
@@ -235,7 +193,7 @@ class PathList
|
|
235
193
|
|
236
194
|
|
237
195
|
|
238
|
-
|
196
|
+
|
239
197
|
# Clear all the exclude patterns so that we exclude nothing.
|
240
198
|
def clear_exclude
|
241
199
|
@exclude_patterns = []
|
@@ -264,7 +222,7 @@ class PathList
|
|
264
222
|
result = @items * other
|
265
223
|
case result
|
266
224
|
when Array
|
267
|
-
PathList.
|
225
|
+
PathList.import result
|
268
226
|
else
|
269
227
|
result
|
270
228
|
end
|
@@ -305,7 +263,7 @@ class PathList
|
|
305
263
|
case fn
|
306
264
|
when Array
|
307
265
|
fn.each { |f| self.resolve_add(f) }
|
308
|
-
when %r{[
|
266
|
+
when %r{[*?\{]}
|
309
267
|
add_matching(fn)
|
310
268
|
else
|
311
269
|
# >>>>
|
@@ -368,7 +326,7 @@ class PathList
|
|
368
326
|
self
|
369
327
|
end
|
370
328
|
|
371
|
-
# Return a new array with <tt>
|
329
|
+
# Return a new array with <tt>Pathname#ext</tt> method applied to
|
372
330
|
# each member of the array.
|
373
331
|
#
|
374
332
|
# This method is a shortcut for:
|
@@ -383,32 +341,61 @@ class PathList
|
|
383
341
|
|
384
342
|
# PathList version of partition. Needed because the nested arrays
|
385
343
|
# should be PathLists in this version.
|
386
|
-
def partition(&block)
|
344
|
+
def partition(&block) # :nodoc:
|
387
345
|
resolve
|
388
346
|
result = @items.partition(&block)
|
389
347
|
[
|
390
|
-
PathList.
|
391
|
-
PathList.
|
348
|
+
PathList.import(result[0]),
|
349
|
+
PathList.import(result[1]),
|
392
350
|
]
|
393
351
|
end
|
394
|
-
|
352
|
+
|
395
353
|
# Convert a PathList to a string by joining all elements with a space.
|
396
354
|
def to_s
|
397
355
|
resolve if @pending
|
398
356
|
self.join(' ')
|
399
357
|
end
|
400
358
|
|
359
|
+
have YamlExtension, :pathlist, :filelist
|
360
|
+
|
361
|
+
def self.yaml_load ( val )
|
362
|
+
new(val)
|
363
|
+
end
|
364
|
+
|
401
365
|
def to_yaml ( opts={} )
|
402
366
|
resolve if @pending
|
403
367
|
to_a.to_yaml(opts)
|
404
368
|
end
|
405
369
|
|
370
|
+
class PathAndMatchData < Pathname
|
371
|
+
attr_reader :match
|
372
|
+
def initialize ( path, match )
|
373
|
+
super(path)
|
374
|
+
@match = match
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
406
378
|
# Add matching glob patterns.
|
407
379
|
def add_matching(pattern)
|
408
380
|
# <<<<
|
381
|
+
pattern = pattern.to_s
|
382
|
+
re = Regexp.quote(pattern)
|
383
|
+
re.gsub!(/\\\{([^}]+)\\\}/) do
|
384
|
+
'(?:' + $1.gsub(/,/, '|') + ')'
|
385
|
+
end
|
386
|
+
re.gsub!(/\\\*\\\*\//, '(?:.+/)?')
|
387
|
+
re.gsub!(/\\\*/, '[^/]*')
|
388
|
+
re.gsub!(/\\\?/, '[^/]')
|
389
|
+
re.gsub!(/\\([()])/, '\1')
|
390
|
+
pattern.gsub!(/[()]/, '')
|
409
391
|
Pathname.glob(pattern) do |fn|
|
410
392
|
# >>>>
|
411
|
-
|
393
|
+
next if exclude?(fn)
|
394
|
+
if match_data = Regexp.new(re).match(fn.to_s)
|
395
|
+
self << PathAndMatchData.new(fn, match_data)
|
396
|
+
else
|
397
|
+
self << fn
|
398
|
+
end
|
412
399
|
end
|
413
400
|
end
|
414
401
|
# <<<<
|
@@ -446,6 +433,10 @@ class PathList
|
|
446
433
|
new(*args)
|
447
434
|
end
|
448
435
|
|
436
|
+
def import(array)
|
437
|
+
new.import(array)
|
438
|
+
end
|
439
|
+
|
449
440
|
# Set the ignore patterns back to the default value. The
|
450
441
|
# default patterns will ignore files
|
451
442
|
# * containing "CVS" in the file path
|
@@ -468,12 +459,69 @@ class PathList
|
|
468
459
|
end
|
469
460
|
|
470
461
|
# <<<<
|
471
|
-
|
472
|
-
|
462
|
+
alias_method :traditional_each, :each
|
463
|
+
def each ( &block )
|
464
|
+
traditional_each do |x|
|
465
|
+
if x.is_a? PathAndMatchData
|
466
|
+
block[x, *x.match.to_a[1..-1]]
|
467
|
+
else
|
468
|
+
block[x]
|
469
|
+
end
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
def import!
|
474
|
+
traditional_each { |x| x.import! }
|
475
|
+
end
|
476
|
+
|
477
|
+
def load_path!
|
478
|
+
traditional_each { |x| x.load_path! }
|
473
479
|
end
|
474
480
|
|
475
|
-
def
|
481
|
+
def stringify
|
476
482
|
map { |path| path.to_s }
|
477
483
|
end
|
478
484
|
# >>>>
|
479
485
|
end
|
486
|
+
|
487
|
+
test_section __FILE__ do
|
488
|
+
|
489
|
+
class PathListTest < Test::Unit::TestCase
|
490
|
+
include YamlExtension::Assertions
|
491
|
+
|
492
|
+
def setup
|
493
|
+
@r = TempPath.new
|
494
|
+
@r.mkpath
|
495
|
+
@l = PathList[]
|
496
|
+
@args = []
|
497
|
+
@mo = lambda { |*a| @args << a }
|
498
|
+
%w[ foo barbar bazfoo foo/a foo/b ].each do |x|
|
499
|
+
(@r/x).mkpath
|
500
|
+
@l << @r/x
|
501
|
+
end
|
502
|
+
@l2 = PathList[@r/'(f?o)', @r/'b(a*)', @r/'fo,',
|
503
|
+
@r/'f.o', @r/'**/({a,b})']
|
504
|
+
@l3 = PathList[@r/'ba{rbar,zfoo}']
|
505
|
+
end
|
506
|
+
|
507
|
+
def test_each
|
508
|
+
@l.each(&@mo)
|
509
|
+
@l2.each(&@mo)
|
510
|
+
@l3.each(&@mo)
|
511
|
+
assert_equal([
|
512
|
+
[@r/'foo'], [@r/'barbar'], [@r/'bazfoo'], [@r/'foo/a'], [@r/'foo/b'],
|
513
|
+
[@r/'foo', 'foo'], [@r/'barbar', 'arbar'], [@r/'bazfoo', 'azfoo'],
|
514
|
+
[@r/'fo,'], [@r/'f.o'], [@r/'foo/a', 'a'], [@r/'foo/b', 'b'],
|
515
|
+
[@r/'barbar'], [@r/'bazfoo']
|
516
|
+
], @args)
|
517
|
+
end
|
518
|
+
|
519
|
+
def test_pathlist
|
520
|
+
ls = __FILE__.to_path.dirname + '*.rb'
|
521
|
+
assert_yaml_load "--- !filelist #{ls}", PathList, PathList[ls]
|
522
|
+
assert_yaml_dump @val, @val.to_a.to_yaml
|
523
|
+
end
|
524
|
+
|
525
|
+
end # class PathListTest
|
526
|
+
|
527
|
+
end
|
@@ -2,25 +2,17 @@
|
|
2
2
|
# Author: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
3
|
# License: Gnu General Public License.
|
4
4
|
|
5
|
-
# $LastChangedBy:
|
6
|
-
# $Id: temp_path.rb
|
5
|
+
# $LastChangedBy: ertai $
|
6
|
+
# $Id: temp_path.rb 351 2005-09-14 08:33:42Z ertai $
|
7
7
|
|
8
|
-
require 'core_ex'
|
9
8
|
require 'tempfile'
|
10
9
|
require 'tmpdir'
|
11
|
-
require 'set'
|
12
10
|
require 'thread'
|
13
11
|
|
14
12
|
class TempPath < Pathname
|
15
13
|
|
16
|
-
@@tmps = Set.new
|
17
|
-
@@mutex = Mutex.new
|
18
|
-
@@progname = Pathname.new($0).basename
|
19
|
-
@@tmpdir = Pathname.new(Dir.tmpdir) + "#{@@progname}.#{$$}"
|
20
|
-
@@tmpdir.freeze
|
21
14
|
@@initialized = false
|
22
|
-
@@
|
23
|
-
@@auto_clean = true
|
15
|
+
@@mutex = Mutex.new
|
24
16
|
|
25
17
|
# You can use a temporary pathname like that:
|
26
18
|
#
|
@@ -58,11 +50,12 @@ class TempPath < Pathname
|
|
58
50
|
# which follow this format:
|
59
51
|
# => 'base.pid.uniq.ext
|
60
52
|
#
|
61
|
-
def initialize ( base
|
62
|
-
if base.to_s =~ /\//
|
53
|
+
def initialize ( base=nil, ext='' )
|
54
|
+
if base and base.to_s =~ /\//
|
63
55
|
raise ArgumentError, "bad basename, you give me a pathname #{base}"
|
64
56
|
end
|
65
57
|
self.class.init
|
58
|
+
base ||= @@progname
|
66
59
|
ext = ".#{ext}" unless ext.empty? or ext[0] == ?.
|
67
60
|
res = nil
|
68
61
|
@@mutex.synchronize do
|
@@ -103,42 +96,63 @@ class TempPath < Pathname
|
|
103
96
|
true
|
104
97
|
end
|
105
98
|
|
106
|
-
|
107
|
-
|
108
|
-
|
99
|
+
class << self
|
100
|
+
|
101
|
+
def init ( tmp_base_dir=nil ) #:nodoc:
|
109
102
|
return if @@initialized
|
110
|
-
@@
|
111
|
-
|
112
|
-
|
103
|
+
@@mutex.synchronize do
|
104
|
+
return if @@initialized
|
105
|
+
@@tmps = Set.new
|
106
|
+
@@progname = Pathname.new($0).basename
|
107
|
+
@@tmpdir = (tmp_base_dir || Dir.tmpdir).to_path + "#{@@progname}.#{$$}"
|
108
|
+
@@tmpdir.freeze
|
109
|
+
@@clean_planned = false
|
110
|
+
@@auto_clean = true
|
111
|
+
@@tmpdir.mkpath
|
112
|
+
@@initialized = true
|
113
|
+
at_exit { clean if @@auto_clean }
|
114
|
+
end
|
113
115
|
end
|
114
|
-
end
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
@@
|
117
|
+
# Call TempPath.fork_init when you want to reset the global TempPath status.
|
118
|
+
# For example when you make a fork and you don't want that the child have
|
119
|
+
# and destroy the same temporary directory as the father.
|
120
|
+
# This method setup a child TempPath environement where the temporary directory
|
121
|
+
# of the child is in the father one (unless if you set +sub_dir+ to false)
|
122
|
+
def fork_init ( sub_dir=true )
|
123
|
+
@@tmpdir ||= nil
|
124
|
+
@@initialized = false
|
125
|
+
init((sub_dir)? @@tmpdir : nil)
|
124
126
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
|
128
|
+
# By default the autoclean is on.
|
129
|
+
# But in some case (if you use your temppaths in at_exit)
|
130
|
+
# You must disable the autoclean.
|
131
|
+
# And manually call TempPath.clean at the very of the program.
|
132
|
+
def clean ( &block )
|
133
|
+
@@mutex.synchronize do
|
134
|
+
return if @@clean_planned
|
135
|
+
@@clean_planned = true
|
136
|
+
end
|
137
|
+
begin
|
138
|
+
block[] if block_given?
|
139
|
+
ensure
|
140
|
+
if @@tmpdir.exist?
|
141
|
+
@@tmpdir.rmtree
|
142
|
+
@@initialized = false
|
143
|
+
end
|
131
144
|
end
|
132
145
|
end
|
133
|
-
end
|
134
146
|
|
135
|
-
|
136
|
-
|
137
|
-
|
147
|
+
def auto_clean= ( aBool )
|
148
|
+
@@auto_clean = aBool
|
149
|
+
end
|
150
|
+
|
151
|
+
def tmpdir
|
152
|
+
init
|
153
|
+
@@tmpdir
|
154
|
+
end
|
138
155
|
|
139
|
-
def self.tmpdir
|
140
|
-
init
|
141
|
-
@@tmpdir
|
142
156
|
end
|
143
157
|
|
144
158
|
end # class TempPath
|
@@ -3,14 +3,13 @@
|
|
3
3
|
# License:: Ruby license.
|
4
4
|
|
5
5
|
# $LastChangedBy: ertai $
|
6
|
-
# $Id:
|
6
|
+
# $Id: test_runner.rb 351 2005-09-14 08:33:42Z ertai $
|
7
7
|
|
8
8
|
|
9
9
|
require 'test/unit/autorunner'
|
10
10
|
require 'test/unit/ui/testrunnermediator'
|
11
11
|
require 'test/unit/ui/testrunnermediator'
|
12
12
|
require 'test/unit/ui/testrunnerutilities'
|
13
|
-
require 'core_ex'
|
14
13
|
|
15
14
|
|
16
15
|
module Test
|
@@ -81,15 +80,13 @@ module Test
|
|
81
80
|
private
|
82
81
|
def test_started(name)
|
83
82
|
@test_start_time = Time.now
|
84
|
-
@io.print(" #{name}:")
|
83
|
+
@io.print(" '#{name}':")
|
85
84
|
@io.flush
|
86
85
|
end
|
87
86
|
|
88
87
|
private
|
89
88
|
def test_finished(name)
|
90
|
-
|
91
|
-
# feature
|
92
|
-
@io.puts(" \"[ #@test_outcome, #{Time.now - @test_start_time} ]\"")
|
89
|
+
@io.puts(" [ #@test_outcome, #{Time.now - @test_start_time} ]")
|
93
90
|
@test_outcome = 'S'
|
94
91
|
@io.flush
|
95
92
|
end
|
@@ -101,15 +98,15 @@ module Test
|
|
101
98
|
|
102
99
|
private
|
103
100
|
def add_fault(fault)
|
104
|
-
case fault
|
105
|
-
when
|
101
|
+
case fault
|
102
|
+
when Test::Unit::Failure
|
106
103
|
@test_outcome = 'F'
|
107
104
|
@failures << fault
|
108
|
-
when
|
105
|
+
when Test::Unit::Error
|
109
106
|
@test_outcome = 'E'
|
110
107
|
@errors << fault
|
111
108
|
else
|
112
|
-
raise(Exception,
|
109
|
+
raise(Exception, "unexpected fault (#{fault})!!")
|
113
110
|
end
|
114
111
|
end
|
115
112
|
|
@@ -1,11 +1,8 @@
|
|
1
|
-
# Copyright
|
2
|
-
# Author
|
3
|
-
# License
|
1
|
+
# Copyright:: Copyright (c) 2004 Nicolas Despres. All rights reserved.
|
2
|
+
# Author:: Nicolas Despres <polrop@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: version.rb 334 2005-09-04 14:29:40Z ertai $
|
4
5
|
|
5
|
-
# $LastChangedBy: polrop $
|
6
|
-
# $Id: version.rb 290 2005-06-11 06:48:17Z polrop $
|
7
|
-
|
8
|
-
require 'core_ex'
|
9
6
|
|
10
7
|
class Version
|
11
8
|
include Comparable
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: yaml_extension.rb 355 2005-09-15 23:18:43Z ertai $
|
5
|
+
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
module YamlExtension
|
9
|
+
|
10
|
+
setup do |*aliases|
|
11
|
+
theYamlType = aliases.shift
|
12
|
+
case theYamlType
|
13
|
+
when NilClass
|
14
|
+
theYamlType = self.name.downcase
|
15
|
+
when String
|
16
|
+
when Symbol
|
17
|
+
else
|
18
|
+
raise ArgumentError, "Expect a symbol or a string not: #{theYamlType}"
|
19
|
+
end
|
20
|
+
|
21
|
+
yamlTypes = aliases.dup
|
22
|
+
yamlTypes << theYamlType
|
23
|
+
yamlTypes.map! { |x| x.to_s.sub(/^!/, '') }
|
24
|
+
|
25
|
+
undef_method :to_yaml_type
|
26
|
+
old_to_yaml = :"#{theYamlType}_to_yaml"
|
27
|
+
alias_method old_to_yaml, :to_yaml
|
28
|
+
suppress(NoMethodError, NameError) { remove_method :to_yaml }
|
29
|
+
|
30
|
+
define_method(:to_yaml_type) { "!#{theYamlType}" }
|
31
|
+
|
32
|
+
theClass = self
|
33
|
+
yamlTypes.each do |yamlType|
|
34
|
+
YAML.add_builtin_type(yamlType) do |type, val|
|
35
|
+
theClass.yaml_load val
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_yaml ( opts={} )
|
41
|
+
if respond_to? :to_yaml_string
|
42
|
+
YAML::quick_emit(self.object_id, opts) do |out|
|
43
|
+
out << "#{to_yaml_type} #{to_yaml_string}"
|
44
|
+
end
|
45
|
+
else
|
46
|
+
send(old_to_yaml, opts)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
module Assertions
|
52
|
+
|
53
|
+
# @val is here to receive the result of YAML::load,
|
54
|
+
# @str receives the result of X.to_yaml,
|
55
|
+
# @ref is the reference string
|
56
|
+
attr_accessor :val, :str, :ref
|
57
|
+
|
58
|
+
def assert_yaml_load ( aString, aClass, anObject=nil )
|
59
|
+
assert_nothing_raised { @val = YAML::load(aString) }
|
60
|
+
assert_kind_of(aClass, @val)
|
61
|
+
assert_equal(anObject, @val) unless anObject.nil?
|
62
|
+
@ref = aString
|
63
|
+
end
|
64
|
+
|
65
|
+
def assert_yaml_dump ( anObject, ref, options={} )
|
66
|
+
assert_nothing_raised { @str = anObject.to_yaml(options) }
|
67
|
+
if ref.is_a? Regexp
|
68
|
+
assert_match(ref, @str)
|
69
|
+
else
|
70
|
+
assert_equal(ref, @str)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end # module Assertions
|
75
|
+
|
76
|
+
|
77
|
+
end # module YamlExtension
|
78
|
+
|
data/test/check-core_ex.yml
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
---
|
2
2
|
|
3
|
-
CoreEx Main Test Suite:
|
3
|
+
CoreEx Main Test Suite: !S::Iterate
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
regexp : !re ([^/]*)\.yml$
|
5
|
+
over: !pathlist <<pwd>>/(*-suite.yml)
|
6
|
+
iter: [it_file, it_name]
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
import : <<path>>
|
8
|
+
test:
|
9
|
+
<<it_name>>: !S::Import
|
10
|
+
import: <<it_file>>
|
data/test/check-pkg-core_ex.yml
CHANGED
@@ -1,15 +1,12 @@
|
|
1
1
|
---
|
2
2
|
|
3
3
|
# Run this suite with -S 'url: scheme://the/url/to/the/ttk/package'
|
4
|
-
CoreEx Package Test Suite:
|
5
|
-
strategy: Suite
|
4
|
+
CoreEx Package Test Suite: !S::Suite
|
6
5
|
contents:
|
7
6
|
|
8
|
-
- Checkout:
|
9
|
-
strategy: Checkout
|
7
|
+
- Checkout: !S::Checkout
|
10
8
|
url: <<url>>
|
11
9
|
fatal: true
|
12
10
|
|
13
|
-
- Check the package:
|
14
|
-
strategy: Import
|
11
|
+
- Check the package: !S::Import
|
15
12
|
import: <<checkout_dir>>/test/check-core_ex.yml
|
@@ -1,20 +1,44 @@
|
|
1
1
|
---
|
2
2
|
|
3
|
-
CoreEx Sanity Multiple Requires Test Suite:
|
3
|
+
CoreEx Sanity Multiple Requires Test Suite: !S::Suite
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
5
|
+
attributes: !S::Cmd
|
6
|
+
command: ruby
|
7
|
+
exit: 0
|
8
|
+
error: ""
|
9
|
+
output: !re 0 failures, 0 errors$
|
10
|
+
args: -I<<pwd>>/../../lib
|
11
|
+
|
12
|
+
contents:
|
13
|
+
- require:
|
14
|
+
input: |
|
15
|
+
require 'core_ex'
|
16
|
+
require 'test/unit'
|
17
|
+
class TC_ < Test::Unit::TestCase
|
18
|
+
def test_definitions
|
19
|
+
path_list = PathList['<<pwd>>/../../lib/(*).rb']
|
20
|
+
path_list.each do |path, name|
|
21
|
+
path = path.cleanpath.to_s
|
22
|
+
require path
|
23
|
+
assert($LOADED_FEATURES.include?(path),
|
24
|
+
"#{path} not in $LOADED_FEATURES #{$LOADED_FEATURES.inspect}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
- lazy loading:
|
30
|
+
input: |
|
31
|
+
require 'core_ex'
|
32
|
+
require 'test/unit'
|
33
|
+
class TC_ < Test::Unit::TestCase
|
34
|
+
def test_definitions
|
35
|
+
PathList['<<pwd>>/../../lib/(*).rb'].each do |path, name|
|
36
|
+
assert_nothing_raised("cannot camelize #{name}") do
|
37
|
+
@camel = name.camelize
|
38
|
+
end
|
39
|
+
assert_nothing_raised("#@camel not defined?") do
|
40
|
+
@camel.constantize
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|