facets 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env ratch
2
+
3
+ #
4
+ require 'facets/hash/rekey'
5
+ require 'facets/string/tabs'
6
+ require 'facets/progressbar'
7
+
8
+ require 'test/unit/ui/testrunnermediator' #require 'test/unit'
9
+ ::Test::Unit.run = true # Don't autorun tests!
10
+
11
+ main :isotestsolid do
12
+ run_isotests
13
+ end
14
+
15
+ # Run unit-tests. Each test is run in a separate interpretor
16
+ # to prevent script clash. This makes for a more robust test
17
+ # facility and prevents potential conflicts between test scripts.
18
+ #
19
+ # tests Test files (eg. test/tc_**/*.rb) [test/**/*]
20
+ # libs Directories to include in load path.
21
+ # ('./lib' is always included)
22
+ # live Deactive use of local libs and test against install.
23
+ # reqs List of files to require prior to running tests.
24
+ # extract Extract embedded tests first? [false]
25
+ #
26
+ # To isolate tests this tool marshals test results across a
27
+ # stdout->stdin shell pipe. This prevents interfence of one
28
+ # script's tests on another. But consequently it is not always
29
+ # possible to send debug info to stdout in the tests themselves
30
+ # (eg. #p and #puts).
31
+
32
+ def run_isotests
33
+ info = configuration['test']
34
+
35
+ tests = info['files'] || 'test/unit/**/test_*.rb'
36
+ libs = info['libpath']
37
+ reqs = info['require']
38
+ live = info['live']
39
+ #extract = info['extract']
40
+
41
+ tests = [ tests ].flatten
42
+ libs = [ libs ].flatten
43
+
44
+ #files = [ @files ].flatten
45
+ #extract_tests if extract
46
+
47
+ results = TestResults.new #(style)
48
+
49
+ # get test files
50
+ test_libs = libs.join(':')
51
+ test_files = Dir.multiglob( *tests )
52
+ if test_files.empty?
53
+ puts "Tests [NONE]"
54
+ return
55
+ end
56
+
57
+ # run tests
58
+
59
+ if trace?
60
+ pbar = nil
61
+ size = test_files.collect{|f| f.size}.max + 5
62
+ dots = '.' * size
63
+ else
64
+ pbar = Console::ProgressBar.new( 'Testing', test_files.size )
65
+ pbar.inc
66
+ end
67
+
68
+ test_files.each do |test_file|
69
+ pbar.inc if pbar
70
+ if ! File.file?(test_file)
71
+ next #r = nil
72
+ else
73
+ unless pbar
74
+ print test_file + dots[test_file.size..-1]
75
+ $stdout.flush
76
+ end
77
+ r = fork_test( test_file, :libs=>libs, :reqs=>reqs, :live=>live )
78
+ unless pbar
79
+ puts r.passed? ? "[PASS]" : "[FAIL]"
80
+ end
81
+ end
82
+ results << r
83
+ end
84
+
85
+ pbar.finish if pbar
86
+
87
+ # display results
88
+ puts results
89
+
90
+ fails, errrs = results.failure_count, results.error_count
91
+ #CHECKLIST << :test if fails > 0
92
+ #CHECKLIST << :test if errrs > 0
93
+ return (fails + errrs > 0)
94
+ end
95
+
96
+ # Run a test in a separate process.
97
+ #
98
+ # Currently send program output to null device.
99
+ # Could send to a logger in future version.
100
+ #
101
+ # Key parameters are libs, reqs, live.
102
+
103
+ def fork_test( file, keys )
104
+ keys = keys.rekey(:to_s)
105
+
106
+ libs = keys['lib'] || []
107
+ reqs = keys['req'] || []
108
+ live = keys['live']
109
+
110
+ src = ''
111
+
112
+ unless live
113
+ l = File.join( Dir.pwd, 'lib' )
114
+ if File.directory?( l )
115
+ src << %{$:.unshift('#{l}')\n}
116
+ end
117
+ libs.each { |r| src << %{$:.unshift('#{r}')\n} }
118
+ end
119
+
120
+ src << %{
121
+ #require 'test/unit'
122
+ require 'test/unit/collector'
123
+ require 'test/unit/collector/objectspace'
124
+ require 'test/unit/ui/testrunnermediator'
125
+ }
126
+
127
+ reqs.each do |fix|
128
+ src << %Q{
129
+ require '#{fix}'
130
+ }
131
+ end
132
+
133
+ src << %{
134
+ def warn(*null); end # silence warnings
135
+
136
+ output = STDOUT.dup
137
+ STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" )
138
+
139
+ load('#{file}')
140
+ tests = Test::Unit::Collector::ObjectSpace.new.collect
141
+ runner = Test::Unit::UI::TestRunnerMediator.new( tests )
142
+ result = runner.run_suite
143
+
144
+ begin
145
+ marshalled = Marshal.dump(result)
146
+ rescue TypeError => e
147
+ $stderr << "MARSHAL ERROR\n"
148
+ $stderr << "TEST: #{file}\n"
149
+ $stderr << "DATA:" << result.inspect
150
+ exit -1
151
+ end
152
+ output << marshalled
153
+
154
+ STDOUT.reopen(output)
155
+ output.close
156
+ }
157
+
158
+ result = IO.popen("ruby","w+") do |ruby|
159
+ ruby.puts src
160
+ ruby.close_write
161
+ ruby.read
162
+ end
163
+
164
+ begin
165
+ marsh = Marshal.load(result)
166
+ rescue ArgumentError
167
+ $stderr << "\nCannot load marshalled test data.\n"
168
+ $stderr << result << "\n"
169
+ exit -1
170
+ end
171
+
172
+ return marsh
173
+ end
174
+
175
+ #
176
+ # Support class for collecting test results.
177
+ #
178
+
179
+ class TestResults
180
+ attr_reader :assertion_count,
181
+ :run_count,
182
+ :failure_count,
183
+ :error_count
184
+
185
+ attr_accessor :style
186
+
187
+ def initialize( style=nil )
188
+ @style = style
189
+
190
+ @results = []
191
+
192
+ @assertion_count = 0
193
+ @run_count = 0
194
+ @failure_count = 0
195
+ @error_count = 0
196
+ end
197
+
198
+ # Add a result to the results collection.
199
+
200
+ def <<( result )
201
+ @results << result
202
+
203
+ @assertion_count += result.assertion_count
204
+ @run_count += result.run_count
205
+ @failure_count += result.failure_count
206
+ @error_count += result.error_count
207
+ end
208
+
209
+ #
210
+
211
+ def errors
212
+ errors = []
213
+ @results.each do |r|
214
+ unless r.passed?
215
+ errors << r.instance_variable_get('@errors')
216
+ end
217
+ end
218
+ errors.reject! { |e| e == [] }
219
+ errors
220
+ end
221
+
222
+ #
223
+
224
+ def failures
225
+ failures = []
226
+ @results.each do |r|
227
+ unless r.passed?
228
+ failures << r.instance_variable_get('@failures')
229
+ end
230
+ end
231
+ failures.reject! { |e| e == [] }
232
+ failures
233
+ end
234
+
235
+ # Output format for test results.
236
+
237
+ def to_s
238
+ return @results.to_s if style == 'pease'
239
+
240
+ s = []
241
+ # Display failures
242
+ unless failures.empty?
243
+ s << ''
244
+ s << "FAILURES:"
245
+ failures.reverse.each do |fails|
246
+ fails.reverse.each do |failure|
247
+ #puts
248
+ s << %{ - test : #{failure.test_name}}
249
+ s << %{ location : #{failure.location}}
250
+ if failure.message.index("\n")
251
+ s << %{ message : >}
252
+ s << failure.message.tabto(6)
253
+ else
254
+ s << %{ message : #{failure.message}}
255
+ end
256
+ end
257
+ end
258
+ end
259
+
260
+ # Display errors
261
+ unless errors.empty?
262
+ s << ''
263
+ s << "ERRORS:"
264
+ errors.reverse.each do |errs|
265
+ errs.reverse.each do |err|
266
+ s << ''
267
+ s << %{ - test : #{err.test_name}}
268
+ s << %{ message : #{err.exception.message}}
269
+ s << %{ backtrace :}
270
+ err.exception.backtrace[0...-1].each { |bt| s << %Q{ - #{bt}} }
271
+ end
272
+ end
273
+ end
274
+
275
+ # Display final results
276
+ s << ''
277
+ s << "Summary:"
278
+ s << " Tests : #{@run_count}"
279
+ s << " Assertions : #{@assertion_count}"
280
+ s << " Failures : #{@failure_count}"
281
+ s << " Errors : #{@error_count}"
282
+ s << ''
283
+ s << ''
284
+
285
+ return s.join("\n")
286
+ end
287
+
288
+ # Delegate missing call to the results array.
289
+
290
+ def method_missing(*a,&b)
291
+ @results.send(*a,&b)
292
+ end
293
+ end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ratch
2
+
3
+ main :syntax do
4
+ scripts = "lib/**/*.rb"
5
+ libpath = [ 'lib/methods', 'lib/core', 'lib/more' ].join(':')
6
+
7
+ checklist = []
8
+ cnt = 0
9
+ scripts = multiglob(*scripts) #- multiglob_r(ignore)
10
+ scripts.each do |s|
11
+ next unless File.file?(s)
12
+ #if not system "ruby -c -Ibin:lib:test #{s} &> /dev/null" then
13
+ if r = system "ruby -I#{libpath} #{s} > /dev/null"
14
+ puts "#{s} [PASS]" #if verbose?
15
+ else
16
+ puts "Load Issue: #{s}"
17
+ checklist << :load
18
+ cnt += 1
19
+ end
20
+ end
21
+
22
+ if cnt == 0
23
+ puts "Load dependencies check out."
24
+ else
25
+ puts "#{cnt} Load Failures:\n "
26
+ puts checklist.join("\n ")
27
+ end
28
+ end
@@ -17,7 +17,7 @@ require 'facets/module/require'
17
17
  config = configuration['methods']
18
18
 
19
19
  source = config['source'] # from where
20
- folder = config['folder'] # to where
20
+ output = config['output'] # to where
21
21
  ignore = config['ignore'] # classes/modules to ignore
22
22
 
23
23
  REDIRECT_WRITE = []
@@ -29,7 +29,7 @@ main :methods => [ :generate_redirects, :remove_redirects ] do
29
29
  REDIRECT_WRITE.each do |file, klass, meth|
30
30
  meth = meth.chomp('!').chomp('=').chomp('?')
31
31
  meth = op_esc(meth)
32
- meth_file = "#{folder}/#{klass.to_s.downcase}/#{meth}.rb"
32
+ meth_file = "#{output}/#{klass.to_s.downcase}/#{meth}.rb"
33
33
  # if the the redirect has the same name as the original, don't botther.
34
34
  next if file == "facets/#{klass.to_s.downcase}/#{meth}.rb"
35
35
  # create redirection file
@@ -49,7 +49,7 @@ end
49
49
  # Remove previous redirection directory.
50
50
 
51
51
  task :remove_redirects do
52
- dst = File.join('lib', folder)
52
+ dst = File.join('lib', output)
53
53
  rm_r(dst) if dir?(dst) #File.directory?(dst)
54
54
  end
55
55
 
@@ -63,7 +63,7 @@ task :generate_redirects => [ :neuter_module ] do
63
63
  redirect_libs.each do |file|
64
64
  next if dir?(file) #File.directory?(file)
65
65
 
66
- puts "#{file}..."
66
+ puts "#{file}"
67
67
 
68
68
  mod = Module.new
69
69
  mod.module_eval do
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ratch
2
+
3
+ manifest -u meta/manifest.txt
4
+ box
5
+
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Publish website to rubyforge
4
4
  #
5
- # This task publishes the source dir (deafult 'doc/site')
5
+ # This task publishes the source dir (deafult 'doc')
6
6
  # to a rubyforge website.
7
7
 
8
8
  main :publish do
@@ -10,7 +10,7 @@ main :publish do
10
10
 
11
11
  project = config['project']
12
12
  subdir = config['subdir']
13
- source = config['source'] || "doc/site"
13
+ source = config['source'] || "doc"
14
14
  username = config['username']
15
15
  protect = %w{usage statcvs statsvn robot.txt wiki}
16
16
  exclude = %w{.svn}
data/task/rdoc CHANGED
@@ -24,6 +24,7 @@ targets.each do |name, files|
24
24
  targets[name] = files.split(/\s+/) if String===files
25
25
  end
26
26
 
27
+
27
28
  # Build RDocs.
28
29
 
29
30
  main :rdoc => [ :rdoc_targets, :insert_ads ]
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ratch
2
+
3
+ main :syntax do
4
+ scripts = "lib/**/*.rb"
5
+ libpath = [ 'lib/methods', 'lib/core', 'lib/more' ].join(':')
6
+
7
+ checklist = []
8
+ cnt = 0
9
+ scripts = multiglob(*scripts) #- multiglob_r(ignore)
10
+ scripts.each do |s|
11
+ next unless File.file?(s)
12
+ #if not system "ruby -c -Ibin:lib:test #{s} &> /dev/null" then
13
+ r = system "ruby -c -I#{libpath} #{s} > /dev/null"
14
+ if r
15
+ puts "#{s} [PASS]" #if verbose?
16
+ else
17
+ puts "Syntax Error: #{s}"
18
+ checklist << :syntax
19
+ cnt += 1
20
+ end
21
+ end
22
+
23
+ if cnt == 0
24
+ puts "Syntax checks out."
25
+ else
26
+ puts "#{cnt} Syntax Failures:\n "
27
+ puts checklist.join("\n ")
28
+ end
29
+ end
data/task/test CHANGED
@@ -24,4 +24,3 @@ main :test do
24
24
  load file
25
25
  end
26
26
  end
27
-
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ratch
2
+
3
+ # cross-run unit tests
4
+ #
5
+ # This tool runs all tests against each other in pairs
6
+ # to ensure across the board compatibility.
7
+
8
+ require "./lib/more/facets/progressbar"
9
+
10
+ main :test do
11
+ output = 'doc/log/isotest.txt'
12
+
13
+ live = ARGV.delete('--live')
14
+
15
+ find = 'test/**/test_*.rb'
16
+
17
+ tests = Dir.glob(find).reject{ |f| dir?(f) }
18
+ tests = tests.sort{ |a,b| File.basename(a) <=> File.basename(b) }
19
+
20
+ File.open(output, 'w'){ |f|
21
+ f << "= ISO TESTING\n\n==#{Time.now}\n\n"
22
+ }
23
+
24
+ total = tests.size
25
+
26
+ pbar = Console::ProgressBar.new("IsoTest", total+1)
27
+ pbar.inc
28
+
29
+ tests.each do |file|
30
+ pbar.title = File.basename(file)
31
+ pbar.inc
32
+ pbar.flush
33
+
34
+ if live
35
+ sh %{ruby #{file} >> #{output}}
36
+ else
37
+ sh %{ruby -Ilib/more -Ilib/core -Ilib/methods #{file} >> #{output}}
38
+ end
39
+ end
40
+
41
+ pbar.finish
42
+ end