facets 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +3 -3
- data/README +6 -7
- data/lib/core/facets.rb +1 -46
- data/lib/core/facets/array.rb +3 -0
- data/lib/core/facets/array/indexable.rb +6 -1
- data/lib/core/facets/array/only.rb +20 -0
- data/lib/core/facets/dir/multiglob.rb +12 -1
- data/lib/core/facets/enumerable.rb +0 -1
- data/lib/core/facets/enumerable/collect.rb +1 -0
- data/lib/core/facets/enumerable/combination.rb +44 -90
- data/lib/core/facets/facets.rb +46 -0
- data/lib/core/facets/file/write.rb +46 -58
- data/lib/core/facets/hash.rb +2 -0
- data/lib/core/facets/hash/select.rb +14 -0
- data/lib/core/facets/integer/multiples.rb +12 -55
- data/lib/core/facets/kernel/val.rb +14 -0
- data/lib/core/facets/module/alias.rb +28 -9
- data/lib/core/facets/module/methods.rb +18 -0
- data/lib/core/facets/module/traits.rb +65 -70
- data/lib/core/facets/proc/compose.rb +15 -12
- data/lib/core/facets/stackable.rb +3 -2
- data/lib/core/facets/string/format.rb +4 -6
- data/lib/core/facets/string/tabs.rb +34 -0
- data/lib/core/facets/symbol.rb +1 -0
- data/lib/core/facets/symbol/succ.rb +1 -42
- data/lib/core/facets/symbol/to_proc.rb +34 -0
- data/lib/methods/facets/array/contains.rb +1 -0
- data/lib/methods/facets/facets/require_core.rb +1 -0
- data/lib/methods/facets/file/writelines.rb +1 -0
- data/lib/methods/facets/io/writelines.rb +1 -0
- data/lib/methods/facets/kernel/not_nil.rb +1 -0
- data/lib/methods/facets/module/conflict.rb +1 -0
- data/lib/methods/facets/module/instance_method_defined.rb +1 -0
- data/lib/methods/facets/module/module_method_defined.rb +1 -0
- data/lib/methods/facets/module/private_conflict.rb +1 -0
- data/lib/methods/facets/module/protected_conflict.rb +1 -0
- data/lib/methods/facets/module/public_conflict.rb +1 -0
- data/lib/methods/facets/string/expand_tabs.rb +1 -0
- data/lib/methods/facets/string/outdent.rb +1 -0
- data/lib/methods/facets/string/taballto.rb +1 -0
- data/lib/more/facets/arguments.rb +1 -1
- data/lib/more/facets/association.rb +0 -46
- data/lib/more/facets/autoarray.rb +0 -28
- data/lib/more/facets/command.rb +341 -8
- data/lib/more/facets/dictionary.rb +25 -131
- data/lib/more/facets/downloader.rb +1 -1
- data/lib/more/facets/infinity.rb +3 -3
- data/lib/more/facets/interval.rb +0 -161
- data/lib/more/facets/multiton.rb +16 -12
- data/lib/more/facets/namespace.rb +1 -1
- data/lib/more/facets/ostruct.rb +46 -10
- data/lib/more/facets/overload.rb +0 -51
- data/lib/more/facets/paramix.rb +0 -97
- data/lib/more/facets/pp_s.rb +30 -0
- data/lib/more/facets/progressbar.rb +18 -10
- data/lib/more/facets/prototype.rb +1 -40
- data/lib/more/facets/random.rb +1 -0
- data/lib/more/facets/rbsystem.rb +4 -1
- data/lib/more/facets/snapshot.rb +8 -1
- data/lib/more/facets/stylize.rb +2 -0
- data/meta/{project.yaml → facets-2.0.3.roll} +22 -14
- data/meta/manifest.txt +38 -8
- data/task/{config.yaml → config/general.yaml} +7 -2
- data/task/{rdoc.yaml → config/rdoc.yaml} +1 -1
- data/task/crosstest +309 -0
- data/task/isotest +293 -0
- data/task/loadtest +28 -0
- data/task/methods +4 -4
- data/task/prepare +5 -0
- data/task/publish +2 -2
- data/task/rdoc +1 -0
- data/task/syntax +29 -0
- data/task/test +0 -1
- data/task/testeach +42 -0
- data/task/testpairs +50 -0
- data/test/lib/rq.rb +15 -0
- data/test/unit/array/test_merge.rb +21 -43
- data/test/unit/array/test_only.rb +21 -0
- data/test/unit/enumerable/test_collect.rb +1 -21
- data/test/unit/enumerable/test_combination.rb +50 -44
- data/test/unit/file/test_topath.rb +48 -57
- data/test/unit/file/test_write.rb +82 -0
- data/test/unit/hash/test_select.rb +43 -0
- data/test/unit/integer/test_multiples.rb +28 -32
- data/test/unit/kernel/test_report.rb +9 -12
- data/test/unit/kernel/test_val.rb +50 -45
- data/test/unit/module/test_include.rb +56 -57
- data/test/unit/module/test_name.rb +42 -55
- data/test/unit/module/test_traits.rb +46 -47
- data/test/unit/string/test_filter.rb +19 -34
- data/test/unit/string/test_format.rb +87 -96
- data/test/unit/string/test_regesc.rb +18 -26
- data/test/unit/string/test_tabs.rb +226 -119
- data/test/unit/symbol/test_succ.rb +14 -23
- data/test/unit/symbol/test_to_proc.rb +41 -0
- data/test/unit/test_association.rb +38 -47
- data/test/unit/test_attributes.rb +24 -33
- data/test/unit/test_autoarray.rb +23 -32
- data/test/unit/test_command.rb +26 -0
- data/test/unit/test_dictionary.rb +123 -117
- data/test/unit/test_infinity.rb +41 -47
- data/test/unit/test_inheritor.rb +133 -142
- data/test/unit/test_interval.rb +129 -93
- data/test/unit/test_ostruct.rb +148 -101
- data/test/unit/test_overload.rb +8 -15
- data/test/unit/test_paramix.rb +67 -73
- data/test/unit/test_pp_s.rb +23 -0
- data/test/unit/test_prototype.rb +28 -38
- metadata +47 -11
- data/lib/core/facets/enumerable/instance_map.rb +0 -0
- data/lib/more/facets/command_options.rb +0 -328
- data/meta/version.txt +0 -1
- data/task/load +0 -39
- data/test/unit/test_command_options.rb +0 -29
data/lib/more/facets/snapshot.rb
CHANGED
@@ -124,7 +124,6 @@ class Snapshot::ValueHolder
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
-
|
128
127
|
#--
|
129
128
|
# Extend some base classes of Ruby (Object, Array, String, Hash,
|
130
129
|
# Struct) for the two methods #take_snapshot and
|
@@ -139,12 +138,20 @@ class Object
|
|
139
138
|
end
|
140
139
|
snap
|
141
140
|
end
|
141
|
+
|
142
|
+
def to_data
|
143
|
+
task_snapshot
|
144
|
+
end
|
142
145
|
|
143
146
|
def restore_snapshot(snap)
|
144
147
|
instance_variables.each do |iv|
|
145
148
|
instance_variable_set(iv, snap[iv])
|
146
149
|
end
|
147
150
|
end
|
151
|
+
|
152
|
+
def from_data(snap)
|
153
|
+
restore_snapshot(snap)
|
154
|
+
end
|
148
155
|
end
|
149
156
|
|
150
157
|
class Array
|
data/lib/more/facets/stylize.rb
CHANGED
@@ -87,9 +87,11 @@ class String
|
|
87
87
|
# "this is a test".capitalize_all #=> "This Is A Test"
|
88
88
|
|
89
89
|
def title( pattern=$;, *limit )
|
90
|
+
#gsub(/\b\w/){$&.upcase}
|
90
91
|
split(pattern, *limit).select{ |w| w.capitalize! || w }.join(" ")
|
91
92
|
end
|
92
93
|
alias_method :titleize, :title
|
94
|
+
alias_method :titlecase, :title
|
93
95
|
alias_method :capitalize_all, :title
|
94
96
|
|
95
97
|
# Converts a string into a valid ruby method name
|
@@ -1,15 +1,10 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
name : facets
|
4
|
-
author : Thomas Sawyer <transfire@gmail.com>
|
5
|
-
email : facets-universal@rubyforge.org
|
6
|
-
homepage : 'http://facets.rubyforge.org'
|
7
|
-
download : 'http://rubyforge.org/projects/facets'
|
8
|
-
created : '2004-12-16'
|
9
|
-
|
10
2
|
title : Facets
|
11
3
|
subtitle : Premium Core Extensions and Standard Additions
|
12
4
|
slogan : ALL YOUR BASE ARE BELONG TO RUBY!
|
5
|
+
created : '2004-12-16'
|
6
|
+
status : stable
|
7
|
+
|
13
8
|
description :
|
14
9
|
Facets is a large collection of core extension methods
|
15
10
|
and standard additions for the Ruby programming language.
|
@@ -20,15 +15,28 @@ description :
|
|
20
15
|
and microframeworks, from the Functor to a complete
|
21
16
|
Annotations system.
|
22
17
|
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
author : Thomas Sawyer <transfire@gmail.com>
|
19
|
+
email : facets-universal@rubyforge.org
|
20
|
+
homepage : 'http://facets.rubyforge.org'
|
21
|
+
download : 'http://rubyforge.org/projects/facets'
|
22
|
+
|
23
|
+
index_file: facets.rb
|
26
24
|
|
27
|
-
|
25
|
+
load_paths:
|
26
|
+
- lib/core/facets
|
27
|
+
- lib/more/facets
|
28
|
+
- lib/methods/facets
|
29
|
+
|
30
|
+
gem_paths:
|
28
31
|
- lib/core
|
29
32
|
- lib/more
|
30
33
|
- lib/methods
|
31
34
|
|
32
|
-
#
|
33
|
-
|
35
|
+
# Packaging information
|
36
|
+
|
37
|
+
formats : [ gem, tgz ]
|
38
|
+
document : false
|
39
|
+
|
40
|
+
#manifest : meta/manifest.txt
|
41
|
+
#distribute : [ -dev, -doc, -pkg ]
|
34
42
|
|
data/meta/manifest.txt
CHANGED
@@ -24,6 +24,7 @@ lib/core/facets/array/conjoin.rb
|
|
24
24
|
lib/core/facets/array/delete.rb
|
25
25
|
lib/core/facets/array/indexable.rb
|
26
26
|
lib/core/facets/array/merge.rb
|
27
|
+
lib/core/facets/array/only.rb
|
27
28
|
lib/core/facets/array/pad.rb
|
28
29
|
lib/core/facets/array/rotate.rb
|
29
30
|
lib/core/facets/array/select.rb
|
@@ -59,10 +60,10 @@ lib/core/facets/enumerable/collate.rb
|
|
59
60
|
lib/core/facets/enumerable/collect.rb
|
60
61
|
lib/core/facets/enumerable/combination.rb
|
61
62
|
lib/core/facets/enumerable/count.rb
|
62
|
-
lib/core/facets/enumerable/instance_map.rb
|
63
63
|
lib/core/facets/enumerable/permutation.rb
|
64
64
|
lib/core/facets/enumerable/probability.rb
|
65
65
|
lib/core/facets/enumerable.rb
|
66
|
+
lib/core/facets/facets.rb
|
66
67
|
lib/core/facets/file
|
67
68
|
lib/core/facets/file/read.rb
|
68
69
|
lib/core/facets/file/topath.rb
|
@@ -87,6 +88,7 @@ lib/core/facets/hash/merge.rb
|
|
87
88
|
lib/core/facets/hash/new.rb
|
88
89
|
lib/core/facets/hash/op.rb
|
89
90
|
lib/core/facets/hash/rekey.rb
|
91
|
+
lib/core/facets/hash/select.rb
|
90
92
|
lib/core/facets/hash/traverse.rb
|
91
93
|
lib/core/facets/hash/update.rb
|
92
94
|
lib/core/facets/hash/weave.rb
|
@@ -181,6 +183,7 @@ lib/core/facets/symbol/generate.rb
|
|
181
183
|
lib/core/facets/symbol/not.rb
|
182
184
|
lib/core/facets/symbol/shadow.rb
|
183
185
|
lib/core/facets/symbol/succ.rb
|
186
|
+
lib/core/facets/symbol/to_proc.rb
|
184
187
|
lib/core/facets/symbol.rb
|
185
188
|
lib/core/facets/time
|
186
189
|
lib/core/facets/time/change.rb
|
@@ -194,6 +197,7 @@ lib/core/facets.rb
|
|
194
197
|
lib/methods
|
195
198
|
lib/methods/facets
|
196
199
|
lib/methods/facets/array
|
200
|
+
lib/methods/facets/array/contains.rb
|
197
201
|
lib/methods/facets/array/delete_unless.rb
|
198
202
|
lib/methods/facets/array/delete_values.rb
|
199
203
|
lib/methods/facets/array/delete_values_at.rb
|
@@ -291,6 +295,8 @@ lib/methods/facets/enumerable/sum.rb
|
|
291
295
|
lib/methods/facets/enumerable/to_h.rb
|
292
296
|
lib/methods/facets/enumerable/to_hash.rb
|
293
297
|
lib/methods/facets/enumerable/uniq_by.rb
|
298
|
+
lib/methods/facets/facets
|
299
|
+
lib/methods/facets/facets/require_core.rb
|
294
300
|
lib/methods/facets/falseclass
|
295
301
|
lib/methods/facets/falseclass/to_bool.rb
|
296
302
|
lib/methods/facets/file
|
@@ -303,6 +309,7 @@ lib/methods/facets/file/rewrite.rb
|
|
303
309
|
lib/methods/facets/file/rootname.rb
|
304
310
|
lib/methods/facets/file/sanitize.rb
|
305
311
|
lib/methods/facets/file/split_all.rb
|
312
|
+
lib/methods/facets/file/writelines.rb
|
306
313
|
lib/methods/facets/filetest
|
307
314
|
lib/methods/facets/filetest/root.rb
|
308
315
|
lib/methods/facets/float
|
@@ -368,6 +375,8 @@ lib/methods/facets/integer/test_bit.rb
|
|
368
375
|
lib/methods/facets/integer/test_bitmask.rb
|
369
376
|
lib/methods/facets/integer/times_collect.rb
|
370
377
|
lib/methods/facets/integer/times_map.rb
|
378
|
+
lib/methods/facets/io
|
379
|
+
lib/methods/facets/io/writelines.rb
|
371
380
|
lib/methods/facets/kernel
|
372
381
|
lib/methods/facets/kernel/__DIR__.rb
|
373
382
|
lib/methods/facets/kernel/__assign__.rb
|
@@ -414,6 +423,7 @@ lib/methods/facets/kernel/meta_def.rb
|
|
414
423
|
lib/methods/facets/kernel/meta_eval.rb
|
415
424
|
lib/methods/facets/kernel/metaclass.rb
|
416
425
|
lib/methods/facets/kernel/method.rb
|
426
|
+
lib/methods/facets/kernel/not_nil.rb
|
417
427
|
lib/methods/facets/kernel/object_class.rb
|
418
428
|
lib/methods/facets/kernel/object_clone.rb
|
419
429
|
lib/methods/facets/kernel/object_dup.rb
|
@@ -465,16 +475,19 @@ lib/methods/facets/module/class.rb
|
|
465
475
|
lib/methods/facets/module/clone_removing.rb
|
466
476
|
lib/methods/facets/module/clone_renaming.rb
|
467
477
|
lib/methods/facets/module/clone_using.rb
|
478
|
+
lib/methods/facets/module/conflict.rb
|
468
479
|
lib/methods/facets/module/dirname.rb
|
469
480
|
lib/methods/facets/module/include_and_extend.rb
|
470
481
|
lib/methods/facets/module/include_as.rb
|
471
482
|
lib/methods/facets/module/include_function_module.rb
|
472
483
|
lib/methods/facets/module/instance_method.rb
|
484
|
+
lib/methods/facets/module/instance_method_defined.rb
|
473
485
|
lib/methods/facets/module/integrate.rb
|
474
486
|
lib/methods/facets/module/is.rb
|
475
487
|
lib/methods/facets/module/modspace.rb
|
476
488
|
lib/methods/facets/module/module_load.rb
|
477
489
|
lib/methods/facets/module/module_method.rb
|
490
|
+
lib/methods/facets/module/module_method_defined.rb
|
478
491
|
lib/methods/facets/module/module_require.rb
|
479
492
|
lib/methods/facets/module/nesting.rb
|
480
493
|
lib/methods/facets/module/nodef.rb
|
@@ -482,6 +495,9 @@ lib/methods/facets/module/on_included.rb
|
|
482
495
|
lib/methods/facets/module/op_minus.rb
|
483
496
|
lib/methods/facets/module/op_mul.rb
|
484
497
|
lib/methods/facets/module/op_plus.rb
|
498
|
+
lib/methods/facets/module/private_conflict.rb
|
499
|
+
lib/methods/facets/module/protected_conflict.rb
|
500
|
+
lib/methods/facets/module/public_conflict.rb
|
485
501
|
lib/methods/facets/module/redef.rb
|
486
502
|
lib/methods/facets/module/redefine_method.rb
|
487
503
|
lib/methods/facets/module/redirect.rb
|
@@ -541,6 +557,7 @@ lib/methods/facets/string/each_char.rb
|
|
541
557
|
lib/methods/facets/string/each_character.rb
|
542
558
|
lib/methods/facets/string/each_word.rb
|
543
559
|
lib/methods/facets/string/ends_with.rb
|
560
|
+
lib/methods/facets/string/expand_tabs.rb
|
544
561
|
lib/methods/facets/string/first.rb
|
545
562
|
lib/methods/facets/string/fold.rb
|
546
563
|
lib/methods/facets/string/format.rb
|
@@ -553,6 +570,7 @@ lib/methods/facets/string/lines.rb
|
|
553
570
|
lib/methods/facets/string/lowercase.rb
|
554
571
|
lib/methods/facets/string/margin.rb
|
555
572
|
lib/methods/facets/string/mscan.rb
|
573
|
+
lib/methods/facets/string/outdent.rb
|
556
574
|
lib/methods/facets/string/peek.rb
|
557
575
|
lib/methods/facets/string/poke.rb
|
558
576
|
lib/methods/facets/string/pop.rb
|
@@ -569,6 +587,7 @@ lib/methods/facets/string/starts_with.rb
|
|
569
587
|
lib/methods/facets/string/store.rb
|
570
588
|
lib/methods/facets/string/succ.rb
|
571
589
|
lib/methods/facets/string/tab.rb
|
590
|
+
lib/methods/facets/string/taballto.rb
|
572
591
|
lib/methods/facets/string/tabto.rb
|
573
592
|
lib/methods/facets/string/to_b.rb
|
574
593
|
lib/methods/facets/string/to_const.rb
|
@@ -622,7 +641,6 @@ lib/more/facets/class_extension.rb
|
|
622
641
|
lib/more/facets/classmethods.rb
|
623
642
|
lib/more/facets/cloneable.rb
|
624
643
|
lib/more/facets/command.rb
|
625
|
-
lib/more/facets/command_options.rb
|
626
644
|
lib/more/facets/compare_on.rb
|
627
645
|
lib/more/facets/console.rb
|
628
646
|
lib/more/facets/coroutine.rb
|
@@ -676,6 +694,7 @@ lib/more/facets/paramix.rb
|
|
676
694
|
lib/more/facets/pathlist.rb
|
677
695
|
lib/more/facets/pathname.rb
|
678
696
|
lib/more/facets/pool.rb
|
697
|
+
lib/more/facets/pp_s.rb
|
679
698
|
lib/more/facets/pqueue.rb
|
680
699
|
lib/more/facets/prepend.rb
|
681
700
|
lib/more/facets/progressbar.rb
|
@@ -707,29 +726,37 @@ lib/more/facets/version.rb
|
|
707
726
|
lib/more/facets/yaml.rb
|
708
727
|
lib/more/facets/ziputils.rb
|
709
728
|
meta
|
729
|
+
meta/facets-2.0.3.roll
|
710
730
|
meta/manifest.txt
|
711
|
-
meta/project.yaml
|
712
|
-
meta/version.txt
|
713
731
|
task
|
714
732
|
task/clean
|
715
733
|
task/config
|
716
|
-
task/config.yaml
|
734
|
+
task/config/general.yaml
|
735
|
+
task/config/rdoc.yaml
|
736
|
+
task/crosstest
|
717
737
|
task/extest
|
718
738
|
task/groups
|
719
739
|
task/install
|
720
|
-
task/
|
740
|
+
task/isotest
|
741
|
+
task/loadtest
|
721
742
|
task/methods
|
743
|
+
task/prepare
|
722
744
|
task/publish
|
723
745
|
task/rdoc
|
724
|
-
task/rdoc.yaml
|
725
746
|
task/stats
|
747
|
+
task/syntax
|
726
748
|
task/test
|
749
|
+
task/testeach
|
750
|
+
task/testpairs
|
727
751
|
test
|
752
|
+
test/lib
|
753
|
+
test/lib/rq.rb
|
728
754
|
test/unit
|
729
755
|
test/unit/array
|
730
756
|
test/unit/array/test_delete.rb
|
731
757
|
test/unit/array/test_indexable.rb
|
732
758
|
test/unit/array/test_merge.rb
|
759
|
+
test/unit/array/test_only.rb
|
733
760
|
test/unit/array/test_pad.rb
|
734
761
|
test/unit/array/test_rotate.rb
|
735
762
|
test/unit/array/test_select.rb
|
@@ -756,6 +783,7 @@ test/unit/enumerable/test_permutation.rb
|
|
756
783
|
test/unit/enumerable/test_probability.rb
|
757
784
|
test/unit/file
|
758
785
|
test/unit/file/test_topath.rb
|
786
|
+
test/unit/file/test_write.rb
|
759
787
|
test/unit/hash
|
760
788
|
test/unit/hash/test_at.rb
|
761
789
|
test/unit/hash/test_delete.rb
|
@@ -768,6 +796,7 @@ test/unit/hash/test_merge.rb
|
|
768
796
|
test/unit/hash/test_new.rb
|
769
797
|
test/unit/hash/test_op.rb
|
770
798
|
test/unit/hash/test_rekey.rb
|
799
|
+
test/unit/hash/test_select.rb
|
771
800
|
test/unit/hash/test_traverse.rb
|
772
801
|
test/unit/hash/test_update.rb
|
773
802
|
test/unit/hash/test_weave.rb
|
@@ -836,6 +865,7 @@ test/unit/symbol/test_generate.rb
|
|
836
865
|
test/unit/symbol/test_not.rb
|
837
866
|
test/unit/symbol/test_shadow.rb
|
838
867
|
test/unit/symbol/test_succ.rb
|
868
|
+
test/unit/symbol/test_to_proc.rb
|
839
869
|
test/unit/test_1stclassmethod.rb
|
840
870
|
test/unit/test_advice.rb
|
841
871
|
test/unit/test_annotations.rb
|
@@ -855,7 +885,6 @@ test/unit/test_bytes.rb
|
|
855
885
|
test/unit/test_class_extension.rb
|
856
886
|
test/unit/test_classmethods.rb
|
857
887
|
test/unit/test_command.rb
|
858
|
-
test/unit/test_command_options.rb
|
859
888
|
test/unit/test_compare_on.rb
|
860
889
|
test/unit/test_conversion.rb
|
861
890
|
test/unit/test_coroutine.rb
|
@@ -888,6 +917,7 @@ test/unit/test_openobject.rb
|
|
888
917
|
test/unit/test_ostruct.rb
|
889
918
|
test/unit/test_overload.rb
|
890
919
|
test/unit/test_paramix.rb
|
920
|
+
test/unit/test_pp_s.rb
|
891
921
|
test/unit/test_prototype.rb
|
892
922
|
test/unit/test_random.rb
|
893
923
|
test/unit/test_recorder.rb
|
@@ -5,14 +5,19 @@ rdoc:
|
|
5
5
|
|
6
6
|
methods:
|
7
7
|
source : lib/core/facets
|
8
|
-
|
8
|
+
output : lib/methods/facets
|
9
9
|
ignore : [As, Functor, Indexable, Stackable]
|
10
10
|
|
11
11
|
publish:
|
12
12
|
project : facets
|
13
|
-
source : doc
|
13
|
+
source : doc
|
14
14
|
username : transami
|
15
15
|
|
16
|
+
test:
|
17
|
+
libpath:
|
18
|
+
- lib/methods
|
19
|
+
- lib/core
|
20
|
+
- lib/more
|
16
21
|
|
17
22
|
# announce:
|
18
23
|
# template : README
|
data/task/crosstest
ADDED
@@ -0,0 +1,309 @@
|
|
1
|
+
#!/usr/bin/env ratch
|
2
|
+
|
3
|
+
# Run cross comparison tests.
|
4
|
+
#
|
5
|
+
# This tool runs unit tests in pairs to make
|
6
|
+
# sure there is cross library compatibility.
|
7
|
+
|
8
|
+
require 'facets/hash/rekey'
|
9
|
+
require 'facets/string/tabs'
|
10
|
+
require 'facets/progressbar'
|
11
|
+
|
12
|
+
require 'test/unit/ui/testrunnermediator' #require 'test/unit'
|
13
|
+
::Test::Unit.run = true # Don't autorun tests!
|
14
|
+
|
15
|
+
|
16
|
+
main :crosstest do
|
17
|
+
run_crosstests
|
18
|
+
end
|
19
|
+
|
20
|
+
# Run unit-tests. The tests are run in pairs in a separate interpretor
|
21
|
+
# to prevent script clash. This makes for a more robust test
|
22
|
+
# facility and discover potential conflicts between test scripts.
|
23
|
+
#
|
24
|
+
# tests Test files (eg. test/tc_**/*.rb) [test/**/*]
|
25
|
+
# libs Directories to include in load path.
|
26
|
+
# ('./lib' is always included)
|
27
|
+
# live Deactive use of local libs and test against install.
|
28
|
+
# reqs List of files to require prior to running tests.
|
29
|
+
#
|
30
|
+
# To isolate tests this tool marshals test results across a
|
31
|
+
# stdout->stdin shell pipe. This prevents interfence of one
|
32
|
+
# pair of script's tests on another. But consequently it is
|
33
|
+
# not always possible to send debug info to stdout in the tests
|
34
|
+
# themselves (eg. #p and #puts).
|
35
|
+
|
36
|
+
def run_crosstests
|
37
|
+
info = configuration['test']
|
38
|
+
|
39
|
+
if commandline.arguments.empty?
|
40
|
+
tests = info['files'] || 'test/unit/**/test_*.rb'
|
41
|
+
else
|
42
|
+
tests = commandline.arguments
|
43
|
+
end
|
44
|
+
|
45
|
+
libs = info['libpath']
|
46
|
+
reqs = info['require']
|
47
|
+
live = info['live']
|
48
|
+
#extract = info['extract']
|
49
|
+
|
50
|
+
tests = [ tests ].flatten
|
51
|
+
libs = [ libs ].flatten
|
52
|
+
|
53
|
+
results = TestResults.new #(style)
|
54
|
+
|
55
|
+
# get test files
|
56
|
+
test_libs = libs.join(':')
|
57
|
+
test_files = Dir.multiglob(*tests)
|
58
|
+
if test_files.empty?
|
59
|
+
puts "Tests [NONE]"
|
60
|
+
return
|
61
|
+
end
|
62
|
+
|
63
|
+
# run tests
|
64
|
+
|
65
|
+
if trace?
|
66
|
+
pbar = nil
|
67
|
+
size = test_files.collect{|f| f.size}.max * 2 + 5
|
68
|
+
dots = '.' * size
|
69
|
+
else
|
70
|
+
pbar = Console::ProgressBar.new('Testing', test_files.size ** 2)
|
71
|
+
pbar.inc
|
72
|
+
end
|
73
|
+
|
74
|
+
test_files.each do |test_file|
|
75
|
+
next unless File.file?(test_file)
|
76
|
+
|
77
|
+
test_files.each do |test_file_x|
|
78
|
+
next unless File.file?(test_file_x)
|
79
|
+
next if test_file == test_file_x
|
80
|
+
|
81
|
+
pbar.inc if pbar
|
82
|
+
unless pbar
|
83
|
+
out = test_file +' : ' + test_file_x
|
84
|
+
print out + dots[out.size..-1]
|
85
|
+
$stdout.flush
|
86
|
+
end
|
87
|
+
|
88
|
+
r = fork_test( test_file, test_file_x, :libs=>libs, :reqs=>reqs, :live=>live )
|
89
|
+
|
90
|
+
unless pbar
|
91
|
+
puts r.passed? ? "[PASS]" : "[FAIL]"
|
92
|
+
end
|
93
|
+
|
94
|
+
results << r
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
pbar.finish if pbar
|
99
|
+
|
100
|
+
# display results
|
101
|
+
puts results
|
102
|
+
|
103
|
+
fails, errrs = results.failure_count, results.error_count
|
104
|
+
#CHECKLIST << :test if fails > 0
|
105
|
+
#CHECKLIST << :test if errrs > 0
|
106
|
+
return (fails + errrs > 0)
|
107
|
+
end
|
108
|
+
|
109
|
+
# Run a test in a separate process.
|
110
|
+
#
|
111
|
+
# Currently send program output to null device.
|
112
|
+
# Could send to a logger in future version.
|
113
|
+
#
|
114
|
+
# Key parameters are libs, reqs, live.
|
115
|
+
|
116
|
+
def fork_test( file, xfile, keys )
|
117
|
+
keys = keys.rekey(:to_s)
|
118
|
+
|
119
|
+
libs = keys['lib'] || []
|
120
|
+
reqs = keys['req'] || []
|
121
|
+
live = keys['live']
|
122
|
+
|
123
|
+
src = ''
|
124
|
+
|
125
|
+
unless live
|
126
|
+
l = File.join( Dir.pwd, 'lib' )
|
127
|
+
if File.directory?( l )
|
128
|
+
src << %{$:.unshift('#{l}')\n}
|
129
|
+
end
|
130
|
+
libs.each { |r| src << %{$:.unshift('#{r}')\n} }
|
131
|
+
end
|
132
|
+
|
133
|
+
src << %{
|
134
|
+
#require 'test/unit'
|
135
|
+
require 'test/unit/collector'
|
136
|
+
require 'test/unit/collector/objectspace'
|
137
|
+
require 'test/unit/ui/testrunnermediator'
|
138
|
+
}
|
139
|
+
|
140
|
+
reqs.each do |fix|
|
141
|
+
src << %Q{
|
142
|
+
require '#{fix}'
|
143
|
+
}
|
144
|
+
end
|
145
|
+
|
146
|
+
src << %{
|
147
|
+
def warn(*null); end # silence warnings
|
148
|
+
|
149
|
+
output = STDOUT.dup
|
150
|
+
STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" )
|
151
|
+
|
152
|
+
load('#{file}')
|
153
|
+
load('#{xfile}')
|
154
|
+
|
155
|
+
tests = Test::Unit::Collector::ObjectSpace.new.collect
|
156
|
+
runner = Test::Unit::UI::TestRunnerMediator.new( tests )
|
157
|
+
result = runner.run_suite
|
158
|
+
|
159
|
+
begin
|
160
|
+
marshalled = Marshal.dump(result)
|
161
|
+
rescue TypeError => e
|
162
|
+
$stderr << "MARSHAL ERROR\n"
|
163
|
+
$stderr << "TEST: #{file}\n"
|
164
|
+
$stderr << "XTEST: #{xfile}\n"
|
165
|
+
$stderr << "DATA:" << result.inspect
|
166
|
+
exit -1
|
167
|
+
end
|
168
|
+
output << marshalled
|
169
|
+
|
170
|
+
STDOUT.reopen(output)
|
171
|
+
output.close
|
172
|
+
}
|
173
|
+
|
174
|
+
result = IO.popen("ruby","w+") do |ruby|
|
175
|
+
ruby.puts src
|
176
|
+
ruby.close_write
|
177
|
+
ruby.read
|
178
|
+
end
|
179
|
+
|
180
|
+
begin
|
181
|
+
marsh = Marshal.load(result)
|
182
|
+
rescue ArgumentError
|
183
|
+
$stderr << "\nCannot load marshalled test data.\n"
|
184
|
+
$stderr << result << "\n"
|
185
|
+
exit -1
|
186
|
+
end
|
187
|
+
|
188
|
+
return marsh
|
189
|
+
end
|
190
|
+
|
191
|
+
#
|
192
|
+
# Support class for collecting test results.
|
193
|
+
#
|
194
|
+
|
195
|
+
class TestResults
|
196
|
+
attr_reader :assertion_count,
|
197
|
+
:run_count,
|
198
|
+
:failure_count,
|
199
|
+
:error_count
|
200
|
+
|
201
|
+
attr_accessor :style
|
202
|
+
|
203
|
+
def initialize( style=nil )
|
204
|
+
@style = style
|
205
|
+
|
206
|
+
@results = []
|
207
|
+
|
208
|
+
@assertion_count = 0
|
209
|
+
@run_count = 0
|
210
|
+
@failure_count = 0
|
211
|
+
@error_count = 0
|
212
|
+
end
|
213
|
+
|
214
|
+
# Add a result to the results collection.
|
215
|
+
|
216
|
+
def <<( result )
|
217
|
+
@results << result
|
218
|
+
|
219
|
+
@assertion_count += result.assertion_count
|
220
|
+
@run_count += result.run_count
|
221
|
+
@failure_count += result.failure_count
|
222
|
+
@error_count += result.error_count
|
223
|
+
end
|
224
|
+
|
225
|
+
#
|
226
|
+
|
227
|
+
def errors
|
228
|
+
errors = []
|
229
|
+
@results.each do |r|
|
230
|
+
unless r.passed?
|
231
|
+
errors << r.instance_variable_get('@errors')
|
232
|
+
end
|
233
|
+
end
|
234
|
+
errors.reject! { |e| e == [] }
|
235
|
+
errors
|
236
|
+
end
|
237
|
+
|
238
|
+
#
|
239
|
+
|
240
|
+
def failures
|
241
|
+
failures = []
|
242
|
+
@results.each do |r|
|
243
|
+
unless r.passed?
|
244
|
+
failures << r.instance_variable_get('@failures')
|
245
|
+
end
|
246
|
+
end
|
247
|
+
failures.reject! { |e| e == [] }
|
248
|
+
failures
|
249
|
+
end
|
250
|
+
|
251
|
+
# Output format for test results.
|
252
|
+
|
253
|
+
def to_s
|
254
|
+
return @results.to_s if style == 'pease'
|
255
|
+
|
256
|
+
s = []
|
257
|
+
# Display failures
|
258
|
+
unless failures.empty?
|
259
|
+
s << ''
|
260
|
+
s << "FAILURES:"
|
261
|
+
failures.reverse.each do |fails|
|
262
|
+
fails.reverse.each do |failure|
|
263
|
+
#puts
|
264
|
+
s << %{ - test : #{failure.test_name}}
|
265
|
+
s << %{ location : #{failure.location}}
|
266
|
+
if failure.message.index("\n")
|
267
|
+
s << %{ message : >}
|
268
|
+
s << failure.message.tabto(6)
|
269
|
+
else
|
270
|
+
s << %{ message : #{failure.message}}
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
# Display errors
|
277
|
+
unless errors.empty?
|
278
|
+
s << ''
|
279
|
+
s << "ERRORS:"
|
280
|
+
errors.reverse.each do |errs|
|
281
|
+
errs.reverse.each do |err|
|
282
|
+
s << ''
|
283
|
+
s << %{ - test : #{err.test_name}}
|
284
|
+
s << %{ message : #{err.exception.message}}
|
285
|
+
s << %{ backtrace :}
|
286
|
+
err.exception.backtrace[0...-1].each { |bt| s << %Q{ - #{bt}} }
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
# Display final results
|
292
|
+
s << ''
|
293
|
+
s << "Summary:"
|
294
|
+
s << " Tests : #{@run_count}"
|
295
|
+
s << " Assertions : #{@assertion_count}"
|
296
|
+
s << " Failures : #{@failure_count}"
|
297
|
+
s << " Errors : #{@error_count}"
|
298
|
+
s << ''
|
299
|
+
s << ''
|
300
|
+
|
301
|
+
return s.join("\n")
|
302
|
+
end
|
303
|
+
|
304
|
+
# Delegate missing call to the results array.
|
305
|
+
|
306
|
+
def method_missing(*a,&b)
|
307
|
+
@results.send(*a,&b)
|
308
|
+
end
|
309
|
+
end
|