reap 6.0.0 → 6.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,62 @@
1
+ require 'nano/string/pull'
2
+
3
+ module Test
4
+ module Unit
5
+ class CommentAutoRunner < AutoRunner
6
+ def self.run(current_file=nil, default_dir=nil, argv=ARGV, &block)
7
+ if(!current_file || current_file == $0)
8
+ r = new(!current_file, &block)
9
+ if !r.process_args(argv) && default_dir
10
+ r.to_run << default_dir
11
+ end
12
+ r.run
13
+ end
14
+ end
15
+
16
+ def load_commented_tests( filepath )
17
+ rbfile = File.read( filepath )
18
+ rblines = rbfile.split("\n")
19
+
20
+ tests = []
21
+ intest = nil
22
+ comment = nil
23
+ hcomment = nil
24
+
25
+ rblines.each_with_index do |l,i|
26
+ if /^(\ *#\ *)?=\ *begin testing/ =~ l
27
+ intest = true
28
+ comment = true unless $1
29
+ next
30
+ elsif intest and /^(\ *#\ *)?=\ *end/ =~ l
31
+ intest = false
32
+ comment = false
33
+ next
34
+ end
35
+ hcomment = true if /^\ *#/ =~ l
36
+
37
+ if intest and (comment or hcomment)
38
+ l.pull if hcomment
39
+ tests << l
40
+ end
41
+ end
42
+
43
+ tests = tests.join("\n")
44
+ tests.gsub!( %r{^([ ]*)testcase[ ]+(\w+)} ) { "#{$1}class TC_#{$2} < Test::Unit::TestCase" }
45
+ tests.gsub!( %r{^([ ]*)test[ ]+(\w+)} ) { |md| "#{$1}def test_#{$2}" }
46
+
47
+ tests
48
+ end
49
+
50
+ end
51
+ end
52
+ end
53
+
54
+ # Test::Unit::CommentAutoRunner.start( __FILE__ )
55
+ #
56
+ # puts tests, "\n" if $VERBOSE
57
+ #
58
+ # require 'test/unit'
59
+ #
60
+ # load ARGV[0]
61
+ #
62
+ # eval tests
@@ -0,0 +1,17 @@
1
+
2
+ module Unit
3
+ def self.run=(flag)
4
+ @run = flag
5
+ end
6
+
7
+ def self.run?
8
+ @run ||= false
9
+ end
10
+ end
11
+ end
12
+
13
+ at_exit do
14
+ unless $! || Test::Unit.run?
15
+ exit Test::Unit::CommentAutoRunner.run($0 != "-e" && $0)
16
+ end
17
+ end
@@ -0,0 +1,91 @@
1
+ require 'drb'
2
+ require 'test/unit/collector'
3
+ require 'test/unit/collector/objectspace'
4
+ require 'test/unit/ui/testrunnermediator'
5
+
6
+ class Test::Unit::UI::ForkedTestRunner
7
+
8
+ def initialize(suite) #, output_level=NORMAL, io=STDOUT)
9
+ if (suite.respond_to?(:suite))
10
+ @suite = suite.suite
11
+ else
12
+ @suite = suite
13
+ end
14
+ #@output_level = output_level
15
+ #@io = io
16
+ #@already_outputted = false
17
+ #@faults = []
18
+ end
19
+
20
+ def start
21
+
22
+ serialized_tests = Marshal.dump(@test)
23
+
24
+ src = %{
25
+ $output = STDOUT.dup
26
+ STDOUT.reopen( PLATFORM =~ /mswin/ ? "NUL" : "/dev/null" )
27
+
28
+ tests = Marshal.load <<HERE_TESTS_HERE
29
+ #{serialized_tests}
30
+ HERE_TESTS_HERE
31
+
32
+ runner = TestRunnerMediator.new( tests )
33
+
34
+ result = runner.run_suite
35
+
36
+ output << Marshal.dump(result)
37
+
38
+ STDOUT.reopen($output)
39
+ $output.close
40
+
41
+ exit 0
42
+ }
43
+
44
+ result = IO.popen("ruby","w+") do |ruby|
45
+ ruby.puts src
46
+ ruby.close_write
47
+ ruby.read
48
+ end
49
+
50
+ p testfile if $VERBOSE
51
+
52
+ return Marshal.load(result)
53
+
54
+ end
55
+
56
+ private
57
+ def load_comment_tests( filepath )
58
+ rbfile = File.read( filepath )
59
+ rblines = rbfile.split("\n")
60
+
61
+ tests = []
62
+ intest = nil
63
+ comment = nil
64
+ hcomment = nil
65
+
66
+ rblines.each_with_index do |l,i|
67
+ if /^(\ *#\ *)?=\ *begin testing/ =~ l
68
+ intest = true
69
+ comment = true unless $1
70
+ next
71
+ elsif intest and /^(\ *#\ *)?=\ *end/ =~ l
72
+ intest = false
73
+ comment = false
74
+ next
75
+ end
76
+ hcomment = true if /^\ *#/ =~ l
77
+
78
+ if intest and (comment or hcomment)
79
+ l.pull if hcomment
80
+ tests << l
81
+ end
82
+ end
83
+
84
+ tests = tests.join("\n")
85
+ tests.gsub!( %r{^([ ]*)testcase[ ]+(\w+)} ) { "#{$1}class TC_#{$2} < Test::Unit::TestCase" }
86
+ tests.gsub!( %r{^([ ]*)test[ ]+(\w+)} ) { |md| "#{$1}def test_#{$2}" }
87
+
88
+ tests
89
+ end
90
+
91
+ end
@@ -0,0 +1,16 @@
1
+
2
+ # Here's a sample of commentary unit testcase.
3
+ #
4
+ # =begin testing
5
+ #
6
+ # testcase Sample
7
+ # test one
8
+ # assert ( Sample.one == 1 )
9
+ # end
10
+ # end
11
+ #
12
+ # =end
13
+
14
+ class Sample
15
+ def self.one ; 1 ; end
16
+ end
@@ -35,11 +35,10 @@ module Reap
35
35
 
36
36
  include TaskUtils
37
37
 
38
- attr_accessor :dir, :trunk, :files, :options
38
+ attr_accessor :dir, :files, :options
39
39
 
40
40
  def initialize( tst )
41
41
  @dir = 'test'
42
- #@trunk = 'trunk' if File.directory?('trunk')
43
42
  @files = [ 'lib/**/*.rb' ]
44
43
  @options = {}
45
44
 
@@ -51,11 +50,7 @@ module Reap
51
50
  # Extract tests.
52
51
 
53
52
  def extract
54
- if @trunk
55
- Dir.chdir( @trunk ) { extract_tests }
56
- else
57
- extract_tests
58
- end
53
+ extract_tests
59
54
  end
60
55
 
61
56
  alias_method :call, :extract
@@ -28,9 +28,7 @@ module Reap
28
28
 
29
29
  MUST_EXCLUDE = [ 'InstalledFiles', '**/CVS/**/*', '**/*~' ] #, 'dist', 'pkg' ]
30
30
 
31
- # Note that ++dir++ is not offset by ++trunk++. But ++include++ and ++exclude++ are offset.
32
-
33
- attr_accessor :trunk, :dir, :include, :exclude
31
+ attr_accessor :dir, :include, :exclude
34
32
 
35
33
  def initialize( man )
36
34
  @dir = '.'
@@ -39,7 +37,6 @@ module Reap
39
37
 
40
38
  super
41
39
 
42
- @trunk = '.' unless @trunk
43
40
  @exclude |= MUST_EXCLUDE
44
41
  end
45
42
 
@@ -48,13 +45,12 @@ module Reap
48
45
  def generate #( type=nil )
49
46
  manifest_file = File.join( File.expand_path( @dir ), 'MANIFEST' )
50
47
  package_files = FileList.new
51
- Dir.chdir( @trunk ) do
52
- package_files.include(*@include)
53
- package_files.exclude(*@exclude) #if @exclude and not @exclude.empty?
54
- File.open( manifest_file, 'w+') do |f|
55
- package_files.each do |pf|
56
- f << "#{salt(pf)} #{pf}\n" if File.file?(pf)
57
- end
48
+
49
+ package_files.include(*@include)
50
+ package_files.exclude(*@exclude) #if @exclude and not @exclude.empty?
51
+ File.open( manifest_file, 'w+') do |f|
52
+ package_files.each do |pf|
53
+ f << "#{salt(pf)} #{pf}\n" if File.file?(pf)
58
54
  end
59
55
  end
60
56
  end
@@ -54,8 +54,9 @@ module Reap
54
54
 
55
55
  include TaskUtils
56
56
 
57
+ KINDS = [ 'bin', 'lib', 'ext', 'data', 'conf', 'doc' ]
58
+ LOCATIONS = [ 'dist', 'pkg', 'release', 'package', 'distribution' ]
57
59
  MUST_EXCLUDE = [ 'InstalledFiles', '**/CVS/**/*', '**/*~', 'dist', 'pkg', 'release' ]
58
- LOCATIONS = [ 'dist', 'pkg', 'release', 'package', 'distribution' ]
59
60
 
60
61
  attr :pkg
61
62
 
@@ -64,14 +65,6 @@ module Reap
64
65
  def initialize( pkg )
65
66
  @pkg = pkg
66
67
 
67
- #pkg.name ||= master.name
68
- #pkg.title ||= master.title
69
- #pkg.version ||= master.version
70
- #pkg.project ||= master.project || master.rubyforge.project
71
- #pkg.homepage ||= master.homepage || master.rubyforge.homepage
72
-
73
- pkg.trunk ||= '.' # '.' probably will become the mater default.
74
-
75
68
  pkg.status ||= 'development'
76
69
  pkg.series ||= '1'
77
70
  pkg.author ||= "Anonymous"
@@ -134,8 +127,54 @@ module Reap
134
127
  end
135
128
  #@autorequire
136
129
  end
130
+
131
+ # for a mirror image (but no rules does this too)
132
+ # pkg.rules ||= %{
133
+ # bin bin *
134
+ # ext ext **/*
135
+ # lib lib **/*
136
+ # data data **/*
137
+ # conf conf **/*
138
+ # }
139
+
140
+ # for a typical Rolls versioned package
141
+ # pkg.rules ||= %{
142
+ # bin bin *
143
+ # ext ext/$name **/* $name/$version
144
+ # lib lib/$name **/* $name/$version
145
+ # data data/$name **/* $name/$version
146
+ # conf conf/$name **/* $name/$version
147
+ # }
148
+
149
+ @transfer = parse_rules( pkg.rules )
150
+ end
151
+
152
+ private
153
+
154
+ #--
155
+ # TODO use shellwords
156
+ #++
157
+ def parse_rules( spec )
158
+ return [] unless spec
159
+ rules = [] #Hash.new { |h,k| h[k] = [] }
160
+ lines = spec.strip.split("\n")
161
+ lines.each { |line|
162
+ words = line.strip.split(/\s+/)
163
+ kind, from, glob, to = *words
164
+ rules << [ kind, vsub(from), vsub(glob), vsub(to) ]
165
+ }
166
+ rules
167
+ end
168
+
169
+ def vsub( str )
170
+ return nil if str.nil?
171
+ str = str.gsub( '$version', pkg.version.to_s ) #@version.to_s )
172
+ str = str.gsub( '$name', pkg.name.to_s )
173
+ str
137
174
  end
138
175
 
176
+ public
177
+
139
178
  # Generate packages.
140
179
 
141
180
  def generate_packages
@@ -149,7 +188,7 @@ module Reap
149
188
  if FileTest.directory?(release_folder)
150
189
  if $FORCE
151
190
  puts "Removing old directory '#{File.expand_path(release_folder)}'..."
152
- FileUtils.rm_r(release_folder)
191
+ FileUtils.rm_r(release_folder) unless $PRETEND
153
192
  else
154
193
  puts "Package directory '#{pkg.package_name}' already exists. Use -f option to overwrite."
155
194
  return nil
@@ -160,28 +199,44 @@ module Reap
160
199
 
161
200
  # First we make a copy of the files to be distributed.
162
201
 
163
- FileUtils.mkdir_p( mirror_folder ) #pkg.dir #rescue nil
164
- @package_files = nil
165
- Dir.chdir( pkg.trunk ) do
166
- @package_files = ::FileList.new(*pkg.include)
167
- #package_files.include(*pkg.include)
168
- @package_files.exclude(*pkg.exclude) if pkg.exclude #and not pkg.exclude.empty?
169
- @package_files.resolve # reslove FileList here to be sure we get the right files!
170
-
171
- @package_files.each do |f|
172
- from = f #pkg.trunk ? File.join( pkg.trunk, f ) : f
173
- to = File.join( @mirror_path, f )
174
- to_dir = File.dirname( to )
175
- FileUtils.mkdir_p( to_dir ) if not File.exist?(to_dir)
202
+ if $PRETEND
203
+ puts "mkdir_p #{mirror_folder}"
204
+ else
205
+ FileUtils.mkdir_p( mirror_folder )
206
+ end
207
+
208
+ @package_files = ::FileList.new
209
+ @package_files.include(*pkg.include)
210
+ @package_files.exclude(*pkg.exclude) if pkg.exclude #and not pkg.exclude.empty?
211
+ #@package_files.resolve # reslove FileList here to be sure we get the right files!
212
+ @package_files.each do |from|
213
+ to = apply_rules( from )
214
+ to = File.join( mirror_folder, to )
215
+
216
+ if $PRETEND
176
217
  if File.directory?( from )
177
- FileUtils.mkdir_p( to )
218
+ puts "mkdir_p #{to}" if not File.exist?( to )
178
219
  else
220
+ to_dir = File.dirname( to )
221
+ puts "mkdir_p #{to_dir}" if not File.exist?( to_dir )
222
+ puts "rm_f #{to}" #if File.exist?( to )
223
+ puts "safe_ln #{from}, #{to}"
224
+ end
225
+ else
226
+ if File.directory?( from )
227
+ FileUtils.mkdir_p( to ) if not File.exist?( to )
228
+ else
229
+ to_dir = File.dirname( to )
230
+ FileUtils.mkdir_p( to_dir ) if not File.exist?( to_dir )
179
231
  FileUtils.rm_f( to )
180
232
  FileUtils.safe_ln( from, to )
181
233
  end
182
234
  end
183
235
  end
184
236
 
237
+ # TODO Finish pretend mode for the distribution types.
238
+ return if $PRETEND
239
+
185
240
  # Now we create standard packages from the copy.
186
241
 
187
242
  FileUtils.chdir( @release_path ) do
@@ -251,7 +306,47 @@ module Reap
251
306
 
252
307
  private
253
308
 
254
- # This builds the gem package.
309
+ # # Copy the files into the release package folder.
310
+ #
311
+ # def package( kind, from, glob, to )
312
+ # mkdirp = []
313
+ # Dir.chdir( @trunk ) do
314
+ # next unless File.directory?( from )
315
+ # Dir.chdir( from ) do
316
+ # files = Dir.glob( glob ).reject { |f| File.directory?( f ) }
317
+ # files.each do |file|
318
+ # f = File.join( from, file )
319
+ # t = to ? File.join( @mirror_path, kind, to, file ) : File.join( @mirror_path, kind, file )
320
+ # #m = "mode(:#{kind})" # MODES[kind]
321
+ # d = File.dirname(t)
322
+ # unless mkdirp.include?(d)
323
+ # puts "makedir_p #{d}"
324
+ # mkdirp << d
325
+ # end
326
+ # puts "safe_ln #{f} => ...#{t.sub(@release_path,'')}"
327
+ # end
328
+ # end
329
+ # end
330
+ # end
331
+
332
+ #
333
+
334
+ def apply_rules( file )
335
+ @transfer.each do |rule|
336
+ kind, from, glob, to = *rule
337
+ if File.fnmatch( File.join( from, glob ), file )
338
+ if to
339
+ return File.join( kind, to, file.sub(from,'') )
340
+ else
341
+ return File.join( kind, file.sub(from,'') )
342
+ end
343
+ end
344
+ end
345
+ return file
346
+ end
347
+
348
+
349
+ # Build a gem package.
255
350
 
256
351
  def run_gem
257
352
 
@@ -28,13 +28,10 @@ module Reap
28
28
 
29
29
  MUST_EXCLUDE = [ 'InstalledFiles', 'CVS/**/*', '_darcs/**/*' ]
30
30
 
31
- # Note that ++dir++ is not offset by trunk.
32
-
33
31
  attr_accessor :dir,
34
32
  :main,
35
33
  :title,
36
34
  :template,
37
- :trunk,
38
35
  :include,
39
36
  :exclude,
40
37
  :options
@@ -60,12 +57,7 @@ module Reap
60
57
 
61
58
  def generate
62
59
  @rdoc_dir = File.expand_path(@dir)
63
-
64
- if @trunk
65
- Dir.chdir( @trunk ) { generate_rdocs }
66
- else
67
- generate_rdocs
68
- end
60
+ generate_rdocs
69
61
  end
70
62
 
71
63
  alias_method :call, :generate
@@ -42,10 +42,9 @@ module Reap
42
42
 
43
43
  include TaskUtils
44
44
 
45
- attr_accessor :trunk, :files, :requires, :live, :libs
45
+ attr_accessor :files, :requires, :live, :libs
46
46
 
47
47
  def initialize( tst )
48
- #@trunk = 'trunk' if File.directory?('trunk')
49
48
  @files = [ 'test/*/**/*.rb', 'test/**/tc*.rb', 'test/**/test*.rb', 'test/**/*test.rb' ]
50
49
  @requires = []
51
50
  @live = false
@@ -57,11 +56,7 @@ module Reap
57
56
  # Start testing.
58
57
 
59
58
  def test
60
- if @trunk
61
- Dir.chdir( @trunk ) { run_tests }
62
- else
63
- run_tests
64
- end
59
+ run_tests
65
60
  end
66
61
 
67
62
  alias_method :call, :test
data/lib/reap/tasks.rb CHANGED
@@ -134,7 +134,6 @@ module Tasks
134
134
 
135
135
  task name do
136
136
  data = data.to_openobject
137
- data.trunk ||= master.trunk
138
137
  Reap::ExTest.new( data ).extract
139
138
  end
140
139
 
@@ -175,50 +174,53 @@ module Tasks
175
174
  ProjectInfo.exists?
176
175
  end
177
176
 
178
- # == Installer
179
- #
180
- # The installer task generates a specialized
181
- # install.rb script specifically for your
182
- # project. It currently does not support c/c++
183
- # ext/ compilation.
184
- #
185
- # template Template for installation. (See below)
186
- # options Hash of variable options. Project name
187
- # and version are automatically added this.
188
- #
189
- # The template is a special configuration for installation.
190
- # It should be a literal string with each line containing
191
- # four parts seprated by spaces.
192
- #
193
- # [type] [from] [glob] [to]
194
- #
195
- # There are five types: bin, lib, ext, etc (or conf) and data.
196
- #
197
- # The template use variables in the from of $name. These are filled
198
- # in using the options hash.
199
- #
200
- # Here's a basic example of an entry:
201
- #
202
- # ins: !!installer
203
- # template: |
204
- # bin bin * .
205
- # lib lib **/* $name/$version
206
- #
207
-
208
- def installer( name, &data )
209
-
210
- require 'reap/class/installer'
211
-
212
- desc "Generate install.rb script" unless desc
213
-
214
- task name do
215
- data = data.to_openobject
216
- data.options[:name] ||= master.name
217
- data.options[:version] ||= master.version
218
- Reap::Installer.new( data ).compile_and_write
219
- end
220
-
221
- end
177
+ # # == Installer
178
+ # #
179
+ # # The installer task generates a specialized
180
+ # # install.rb script specifically for your
181
+ # # project. It currently does not support c/c++
182
+ # # ext/ compilation.
183
+ # #
184
+ # # template Template for installation. (See below)
185
+ # # options Hash of variable options. Project name
186
+ # # and version are automatically added this.
187
+ # #
188
+ # # The template is a special configuration for installation.
189
+ # # It should be a literal string with each line containing
190
+ # # four parts seprated by spaces.
191
+ # #
192
+ # # [type] [from] [glob] [to]
193
+ # #
194
+ # # There are five types: bin, lib, ext, etc (or conf) and data.
195
+ # #
196
+ # # The template use variables in the from of $name. These are filled
197
+ # # in using the options hash.
198
+ # #
199
+ # # Here's a basic example of an entry:
200
+ # #
201
+ # # ins: !!installer
202
+ # # template: |
203
+ # # bin bin * .
204
+ # # lib lib **/* $name/$version
205
+ # #
206
+ #
207
+ # def installer( name, &data )
208
+ #
209
+ # require 'reap/class/installer'
210
+ #
211
+ # desc "Generate install.rb script" unless desc
212
+ #
213
+ # task name do
214
+ # data = data.to_openobject
215
+ #
216
+ # data.name ||= master.name
217
+ # data.version ||= master.version
218
+ #
219
+ # i = Reap::Installer.new( data )
220
+ # puts i.compile #_and_write
221
+ # end
222
+ #
223
+ # end
222
224
 
223
225
  # == Count
224
226
  #
@@ -233,7 +235,7 @@ module Tasks
233
235
 
234
236
  task name do
235
237
  data = data.to_openobject
236
- incl = data.include || 'lib/**/*' # TODO maybe check trunk too
238
+ incl = data.include || 'lib/**/*'
237
239
 
238
240
  fc, l, c, t, bt, r, rb = 0, 0, 0, 0, false, 0, false
239
241
  Dir.glob( incl ).each do |fname|
@@ -288,7 +290,6 @@ module Tasks
288
290
 
289
291
  task name do
290
292
  data = data.to_openobject
291
- data.trunk ||= master.trunk
292
293
  Reap::Manifest.new( data ).generate
293
294
  end
294
295
 
@@ -356,7 +357,6 @@ module Tasks
356
357
  data.license ||= master.license
357
358
  data.project ||= master.project
358
359
  data.homepage ||= master.homepage
359
- data.trunk ||= master.trunk
360
360
 
361
361
  Reap::Package.new( data ).generate_packages
362
362
  end
@@ -447,7 +447,6 @@ module Tasks
447
447
  data = data.to_openobject
448
448
 
449
449
  data.title ||= master.title
450
- data.trunk ||= master.trunk
451
450
 
452
451
  Reap::RDoc.new( data ).call
453
452
  end
@@ -565,10 +564,9 @@ module Tasks
565
564
  task name do
566
565
  data = data.to_openobject
567
566
 
568
- data.trunk ||= master.trunk || '.'
569
567
  data.options ||= []
570
568
 
571
- unless provide_setup_rb( data.trunk )
569
+ unless provide_setup_rb
572
570
  puts "Setup.rb is missing. Forced to cancel task."
573
571
  return nil
574
572
  end
@@ -583,10 +581,8 @@ module Tasks
583
581
  exe << data.options.join(' ')
584
582
  exe << ' all'
585
583
 
586
- success = false
587
- Dir.chdir( data.trunk ) do
588
- success = sh( exe )
589
- end
584
+ #success = false
585
+ success = sh( exe )
590
586
 
591
587
  puts "Setup complete!" if success
592
588
  end
@@ -663,9 +659,6 @@ module Tasks
663
659
 
664
660
  task name do
665
661
  data = data.to_openobject
666
-
667
- data.trunk ||= master.trunk
668
-
669
662
  Reap::Test.new( data ).call
670
663
  end
671
664