facets 2.0.2 → 2.0.3

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.
Files changed (114) hide show
  1. data/AUTHORS +3 -3
  2. data/README +6 -7
  3. data/lib/core/facets.rb +1 -46
  4. data/lib/core/facets/array.rb +3 -0
  5. data/lib/core/facets/array/indexable.rb +6 -1
  6. data/lib/core/facets/array/only.rb +20 -0
  7. data/lib/core/facets/dir/multiglob.rb +12 -1
  8. data/lib/core/facets/enumerable.rb +0 -1
  9. data/lib/core/facets/enumerable/collect.rb +1 -0
  10. data/lib/core/facets/enumerable/combination.rb +44 -90
  11. data/lib/core/facets/facets.rb +46 -0
  12. data/lib/core/facets/file/write.rb +46 -58
  13. data/lib/core/facets/hash.rb +2 -0
  14. data/lib/core/facets/hash/select.rb +14 -0
  15. data/lib/core/facets/integer/multiples.rb +12 -55
  16. data/lib/core/facets/kernel/val.rb +14 -0
  17. data/lib/core/facets/module/alias.rb +28 -9
  18. data/lib/core/facets/module/methods.rb +18 -0
  19. data/lib/core/facets/module/traits.rb +65 -70
  20. data/lib/core/facets/proc/compose.rb +15 -12
  21. data/lib/core/facets/stackable.rb +3 -2
  22. data/lib/core/facets/string/format.rb +4 -6
  23. data/lib/core/facets/string/tabs.rb +34 -0
  24. data/lib/core/facets/symbol.rb +1 -0
  25. data/lib/core/facets/symbol/succ.rb +1 -42
  26. data/lib/core/facets/symbol/to_proc.rb +34 -0
  27. data/lib/methods/facets/array/contains.rb +1 -0
  28. data/lib/methods/facets/facets/require_core.rb +1 -0
  29. data/lib/methods/facets/file/writelines.rb +1 -0
  30. data/lib/methods/facets/io/writelines.rb +1 -0
  31. data/lib/methods/facets/kernel/not_nil.rb +1 -0
  32. data/lib/methods/facets/module/conflict.rb +1 -0
  33. data/lib/methods/facets/module/instance_method_defined.rb +1 -0
  34. data/lib/methods/facets/module/module_method_defined.rb +1 -0
  35. data/lib/methods/facets/module/private_conflict.rb +1 -0
  36. data/lib/methods/facets/module/protected_conflict.rb +1 -0
  37. data/lib/methods/facets/module/public_conflict.rb +1 -0
  38. data/lib/methods/facets/string/expand_tabs.rb +1 -0
  39. data/lib/methods/facets/string/outdent.rb +1 -0
  40. data/lib/methods/facets/string/taballto.rb +1 -0
  41. data/lib/more/facets/arguments.rb +1 -1
  42. data/lib/more/facets/association.rb +0 -46
  43. data/lib/more/facets/autoarray.rb +0 -28
  44. data/lib/more/facets/command.rb +341 -8
  45. data/lib/more/facets/dictionary.rb +25 -131
  46. data/lib/more/facets/downloader.rb +1 -1
  47. data/lib/more/facets/infinity.rb +3 -3
  48. data/lib/more/facets/interval.rb +0 -161
  49. data/lib/more/facets/multiton.rb +16 -12
  50. data/lib/more/facets/namespace.rb +1 -1
  51. data/lib/more/facets/ostruct.rb +46 -10
  52. data/lib/more/facets/overload.rb +0 -51
  53. data/lib/more/facets/paramix.rb +0 -97
  54. data/lib/more/facets/pp_s.rb +30 -0
  55. data/lib/more/facets/progressbar.rb +18 -10
  56. data/lib/more/facets/prototype.rb +1 -40
  57. data/lib/more/facets/random.rb +1 -0
  58. data/lib/more/facets/rbsystem.rb +4 -1
  59. data/lib/more/facets/snapshot.rb +8 -1
  60. data/lib/more/facets/stylize.rb +2 -0
  61. data/meta/{project.yaml → facets-2.0.3.roll} +22 -14
  62. data/meta/manifest.txt +38 -8
  63. data/task/{config.yaml → config/general.yaml} +7 -2
  64. data/task/{rdoc.yaml → config/rdoc.yaml} +1 -1
  65. data/task/crosstest +309 -0
  66. data/task/isotest +293 -0
  67. data/task/loadtest +28 -0
  68. data/task/methods +4 -4
  69. data/task/prepare +5 -0
  70. data/task/publish +2 -2
  71. data/task/rdoc +1 -0
  72. data/task/syntax +29 -0
  73. data/task/test +0 -1
  74. data/task/testeach +42 -0
  75. data/task/testpairs +50 -0
  76. data/test/lib/rq.rb +15 -0
  77. data/test/unit/array/test_merge.rb +21 -43
  78. data/test/unit/array/test_only.rb +21 -0
  79. data/test/unit/enumerable/test_collect.rb +1 -21
  80. data/test/unit/enumerable/test_combination.rb +50 -44
  81. data/test/unit/file/test_topath.rb +48 -57
  82. data/test/unit/file/test_write.rb +82 -0
  83. data/test/unit/hash/test_select.rb +43 -0
  84. data/test/unit/integer/test_multiples.rb +28 -32
  85. data/test/unit/kernel/test_report.rb +9 -12
  86. data/test/unit/kernel/test_val.rb +50 -45
  87. data/test/unit/module/test_include.rb +56 -57
  88. data/test/unit/module/test_name.rb +42 -55
  89. data/test/unit/module/test_traits.rb +46 -47
  90. data/test/unit/string/test_filter.rb +19 -34
  91. data/test/unit/string/test_format.rb +87 -96
  92. data/test/unit/string/test_regesc.rb +18 -26
  93. data/test/unit/string/test_tabs.rb +226 -119
  94. data/test/unit/symbol/test_succ.rb +14 -23
  95. data/test/unit/symbol/test_to_proc.rb +41 -0
  96. data/test/unit/test_association.rb +38 -47
  97. data/test/unit/test_attributes.rb +24 -33
  98. data/test/unit/test_autoarray.rb +23 -32
  99. data/test/unit/test_command.rb +26 -0
  100. data/test/unit/test_dictionary.rb +123 -117
  101. data/test/unit/test_infinity.rb +41 -47
  102. data/test/unit/test_inheritor.rb +133 -142
  103. data/test/unit/test_interval.rb +129 -93
  104. data/test/unit/test_ostruct.rb +148 -101
  105. data/test/unit/test_overload.rb +8 -15
  106. data/test/unit/test_paramix.rb +67 -73
  107. data/test/unit/test_pp_s.rb +23 -0
  108. data/test/unit/test_prototype.rb +28 -38
  109. metadata +47 -11
  110. data/lib/core/facets/enumerable/instance_map.rb +0 -0
  111. data/lib/more/facets/command_options.rb +0 -328
  112. data/meta/version.txt +0 -1
  113. data/task/load +0 -39
  114. data/test/unit/test_command_options.rb +0 -29
@@ -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
@@ -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
- formats : [ gem, tgz ]
24
- document : false
25
- #distribute : [ -dev, -doc ]
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
- libpaths:
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
- #manifest : meta/Manifest
33
- #stamp : meta/Version
35
+ # Packaging information
36
+
37
+ formats : [ gem, tgz ]
38
+ document : false
39
+
40
+ #manifest : meta/manifest.txt
41
+ #distribute : [ -dev, -doc, -pkg ]
34
42
 
@@ -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/load
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
- folder : lib/methods/facets
8
+ output : lib/methods/facets
9
9
  ignore : [As, Functor, Indexable, Stackable]
10
10
 
11
11
  publish:
12
12
  project : facets
13
- source : doc/site
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
@@ -407,7 +407,7 @@ Shellwords:
407
407
  files:
408
408
  facets/shellwords.rb
409
409
 
410
- SMTP_TLS:
410
+ SMTP-TLS:
411
411
  chdir: lib/more
412
412
  files:
413
413
  facets/smtp_tls.rb
@@ -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