rubygems-test 0.2.6 → 0.3.0

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/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ === 0.3.0 / 2011-01-30
2
+
3
+ * More fixes for garbagecollect
4
+ * Removed --trace. It was buggy and didn't work as expected.
5
+ * Reworked I/O loop. Some testing to do still but it's looking good for most cases.
6
+ * Fixed issue with on_install_test.rb, solves issue #11
7
+ * Fixes for Rake; should be a little cleaner and run in a few more places.
8
+ * Use temporary paths rather than system paths during tests. [James Tucker]
9
+ * Clarify predicates.
10
+
1
11
  === 0.2.6 / 2011-01-15
2
12
 
3
13
  * Big refactor of rake locating to get running on mswin32
data/Manifest.txt CHANGED
@@ -1,12 +1,13 @@
1
1
  .gemtest
2
- LICENSE
3
- README.txt
4
2
  History.txt
3
+ LICENSE
5
4
  Manifest.txt
5
+ README.txt
6
6
  Rakefile
7
7
  gems/Rakefile
8
8
  gems/template.gemspec
9
9
  gems/test/test_pass.rb
10
+ lib/exceptions.rb
10
11
  lib/open4-vendor.rb
11
12
  lib/rubygems/commands/test_command.rb
12
13
  lib/rubygems/on_install_test.rb
data/Rakefile CHANGED
@@ -12,7 +12,7 @@ Hoe.spec 'rubygems-test' do
12
12
 
13
13
  # doin' it wrong because we're a gem plugin
14
14
  # that means I can be "special"!
15
- self.version = '0.2.6'
15
+ self.version = '0.3.0'
16
16
 
17
17
  self.rubyforge_name = nil
18
18
 
data/lib/exceptions.rb ADDED
@@ -0,0 +1,2 @@
1
+ class Gem::TestError < Gem::Exception; end
2
+ class Gem::RakeNotFoundError < Gem::Exception; end
@@ -2,14 +2,13 @@ Gem.autoload(:VersionOption, 'rubygems/version_option')
2
2
  Gem.autoload(:Specification, 'rubygems/specification')
3
3
  Gem.autoload(:DefaultUserInteraction, 'rubygems/user_interaction')
4
4
  Gem.autoload(:DependencyInstaller, 'rubygems/dependency_installer')
5
+ Gem.autoload(:RakeNotFoundError, 'exceptions')
6
+ Gem.autoload(:TestError, 'exceptions')
5
7
  require 'rbconfig'
6
8
  autoload(:YAML, 'yaml')
7
9
  require 'net/http'
8
10
  require 'uri'
9
11
 
10
- class Gem::TestError < Gem::Exception; end
11
- class Gem::RakeNotFoundError < Gem::Exception; end
12
-
13
12
  class Gem::Commands::TestCommand < Gem::Command
14
13
  include Gem::VersionOption
15
14
  include Gem::DefaultUserInteraction
@@ -95,23 +94,27 @@ class Gem::Commands::TestCommand < Gem::Command
95
94
  # Locate rake itself, prefer gems version.
96
95
  #
97
96
  def find_rake
98
-
99
- rake_finder = proc do |rake_name|
100
- Gem.bin_path('rake') rescue File.join(RbConfig::CONFIG["bindir"], rake_name || 'rake')
101
- end
102
-
103
- rake_path = rake_finder.call(nil)
104
-
105
- unless File.exist?(rake_path)
106
- rake_path = rake_finder.call('rake.bat')
107
-
108
- unless File.exist?(rake_path)
97
+ begin
98
+ rake_path = Gem.bin_path('rake')
99
+ rescue
100
+ unless RUBY_VERSION > '1.9'
109
101
  alert_error "Couldn't find rake; rubygems-test will not work without it. Aborting."
110
102
  raise Gem::RakeNotFoundError, "Couldn't find rake; rubygems-test will not work without it."
111
103
  end
112
104
  end
113
105
 
114
- return rake_path
106
+ if RUBY_VERSION > '1.9'
107
+ if RUBY_PLATFORM =~ /mswin/
108
+ #
109
+ # XXX GarbageCollect breaks ruby -S with rake.
110
+ #
111
+ return File.join(RbConfig::CONFIG["bindir"], 'rake.bat')
112
+ else
113
+ return rake_path || 'rake'
114
+ end
115
+ else
116
+ return rake_path
117
+ end
115
118
  end
116
119
 
117
120
  #
@@ -209,119 +212,123 @@ class Gem::Commands::TestCommand < Gem::Command
209
212
  }.to_yaml
210
213
  end
211
214
 
212
-
213
215
  #
214
- # Run the tests with the appropriate spec and rake_path, and capture all
215
- # output.
216
+ # Inner loop for platform_reader
216
217
  #
217
- def run_tests(spec, rake_path)
218
- output = ""
219
- exit_status = nil
218
+ def read_output(stdout, stderr)
219
+ require 'thread'
220
220
 
221
- [STDOUT, STDERR, $stdout, $stderr].map { |x| x.sync = true }
221
+ STDOUT.sync = true
222
+ STDERR.sync = true
223
+ stdout.sync = true
224
+ stderr.sync = true
222
225
 
223
- Dir.chdir(spec.full_gem_path) do
224
- reader_proc = proc do |orig_handles|
225
- current_handles = orig_handles.dup
226
-
227
- handles, _, _ = IO.select(current_handles, nil, nil, 0.1)
228
- bufs = Hash.new { |h, k| h[k] = "" }
229
-
230
- if handles
231
- handles.compact.each do |io|
232
- begin
233
- bufs[io] += io.readpartial(8)
234
- rescue EOFError
235
- bufs[io] += io.read rescue ""
236
- current_handles.reject! { |x| x == io }
237
- end
238
- end
226
+ output = ""
227
+ mutex = Mutex.new
228
+
229
+ err_t = Thread.new do
230
+ while !stderr.eof?
231
+ tmp = stderr.readline
232
+ mutex.synchronize do
233
+ output << tmp
234
+ print tmp
239
235
  end
236
+ end
237
+ end
240
238
 
241
- [bufs, current_handles]
239
+ out_t = Thread.new do
240
+ while !stdout.eof?
241
+ tmp = stdout.read(1)
242
+ mutex.synchronize do
243
+ output << tmp
244
+ print tmp
245
+ end
242
246
  end
247
+ end
243
248
 
244
- outer_reader_proc = proc do |stdout, stderr|
245
- stderr_buf = ""
246
-
247
- loop do
248
- tmp_output = ""
249
- handles = [stderr, stdout]
250
- bufs, handles = reader_proc.call(handles)
251
-
252
- # hello mom, I've rewritten unix i/o and it probably sucks.
253
- # basically, we only "flush" stderr on newline and stdout
254
- # "flushes" immediately. and by "flush" I mean "concatenates".
255
- if bufs.has_key?(stderr)
256
- stderr_buf += bufs[stderr]
257
- buf_ary = stderr_buf.split($/)
258
- if buf_ary.length > 1
259
- tmp_output += buf_ary[0..-2].join($/) + $/
260
- stderr_buf = buf_ary[-1]
261
- end
262
- end
249
+ while !stderr.eof? or !stdout.eof?
250
+ Thread.pass
251
+ end
263
252
 
264
- tmp_output += bufs[stdout] if bufs.has_key?(stdout)
253
+ return output
254
+ end
265
255
 
266
- print tmp_output
267
- output += tmp_output
268
- break if handles.empty?
256
+ #
257
+ # platform-specific reading routines.
258
+ #
259
+ def platform_reader(rake_args)
260
+ # jruby stuffs it under IO, so we'll use that if it's available
261
+ # if we're on 1.9, use open3 regardless of platform.
262
+ # If we're not:
263
+ # * on windows use win32/open3 from win32-open3 gem
264
+ # * on unix use open4-vendor
265
+
266
+ output, exit_status = *[]
267
+
268
+ if IO.respond_to?(:popen4)
269
+ IO.popen4(*rake_args) do |pid, stdin, stdout, stderr|
270
+ output = read_output(stdout, stderr)
271
+ end
272
+ exit_status = $?
273
+ elsif RUBY_VERSION > '1.9'
274
+ require 'open3'
275
+ Open3.popen3(*rake_args) do |stdin, stdout, stderr, thr|
276
+ output = read_output(stdout, stderr)
277
+ exit_status = thr.value
278
+ end
279
+ elsif RUBY_PLATFORM =~ /mingw|mswin/
280
+ begin
281
+ require 'win32/open3'
282
+ Open3.popen3(*rake_args) do |stdin, stdout, stderr|
283
+ output = read_output(stdout, stderr)
269
284
  end
285
+ exit_status = $?
286
+ rescue LoadError
287
+ say "1.8/Windows users must install the 'win32-open3' gem to run tests"
288
+ terminate_interaction 1
270
289
  end
290
+ else
291
+ require 'open4-vendor'
292
+ exit_status = Open4.popen4(*rake_args) do |pid, stdin, stdout, stderr|
293
+ output = read_output(stdout, stderr)
294
+ end
295
+ end
271
296
 
272
- rake_args = [rake_path, 'test', '--trace']
297
+ return output, exit_status
298
+ end
273
299
 
274
- rake_args_concatenator = proc do |ra|
275
- ra.unshift(File.join(RbConfig::CONFIG["bindir"], 'ruby'))
276
- end
300
+ #
301
+ # obtain the rake arguments for a specific platform and environment.
302
+ #
303
+ def get_rake_args(rake_path, *args)
304
+ if RUBY_PLATFORM =~ /mswin/ and RUBY_VERSION > '1.9'
305
+ #
306
+ # XXX GarbageCollect breaks ruby -S with rake on 1.9.
307
+ #
308
+
309
+ rake_args = [ rake_path ] + args
310
+ else
311
+ rake_args = [ Gem.ruby, '-rubygems', '-S' ] + [ rake_path, '--' ] + args
312
+ end
277
313
 
278
- case RUBY_PLATFORM
279
- when /mingw/
280
- rake_args_concatenator.call(rake_args)
281
- rake_args = rake_args.join(' ')
282
- when /mswin/
283
- # if we don't run rake.bat (system rake for 1.9 as opposed to gems),
284
- # run it with ruby.
285
- if rake_args[0] =~ /rake$/
286
- rake_args_concatenator.call(rake_args)
287
- end
288
- rake_args = rake_args.join(' ')
289
- end
314
+ if RUBY_PLATFORM =~ /mswin|mingw/
315
+ # we don't use shellwords for the rest because they use execve().
316
+ require 'shellwords'
317
+ rake_args.map { |x| Shellwords.shellescape(x) }.join(' ')
318
+ else
319
+ rake_args
320
+ end
321
+ end
290
322
 
291
- # jruby stuffs it under IO, so we'll use that if it's available
292
- # if we're on 1.9, use open3 regardless of platform.
293
- # If we're not:
294
- # * on windows use win32/open3 from win32-open3 gem
295
- # * on unix use open4-vendor
296
- klass =
297
- if IO.respond_to?(:popen4)
298
- IO.popen4(*rake_args) do |pid, stdin, stdout, stderr|
299
- outer_reader_proc.call(stdout, stderr)
300
- end
301
- exit_status = $?
302
- elsif RUBY_VERSION > '1.9'
303
- require 'open3'
304
- exit_status = Open3.popen3(*rake_args) do |stdin, stdout, stderr, thr|
305
- outer_reader_proc.call(stdout, stderr)
306
- thr.value
307
- end
308
- elsif RUBY_PLATFORM =~ /mingw|mswin/
309
- begin
310
- require 'win32/open3'
311
- Open3.popen3(*rake_args) do |stdin, stdout, stderr|
312
- outer_reader_proc.call(stdout, stderr)
313
- end
314
- exit_status = $?
315
- rescue LoadError
316
- say "1.8/Windows users must install the 'win32-open3' gem to run tests"
317
- terminate_interaction 1
318
- end
319
- else
320
- require 'open4-vendor'
321
- exit_status = Open4.popen4(*rake_args) do |pid, stdin, stdout, stderr|
322
- outer_reader_proc.call(stdout, stderr)
323
- end
324
- end
323
+ #
324
+ # Run the tests with the appropriate spec and rake_path, and capture all
325
+ # output.
326
+ #
327
+ def run_tests(spec, rake_path)
328
+ Dir.chdir(spec.full_gem_path) do
329
+ rake_args = get_rake_args(rake_path, 'test')
330
+
331
+ output, exit_status = platform_reader(rake_args)
325
332
 
326
333
  if upload_results?
327
334
  upload_results(gather_results(spec, output, exit_status.exitstatus == 0))
@@ -1,5 +1,7 @@
1
1
  Gem.autoload(:Uninstaller, 'rubygems/uninstaller')
2
- Gem.autoload(:Commands, 'rubygems/commands/test_command')
2
+ Gem::Commands.autoload(:TestCommand, 'rubygems/commands/test_command')
3
+ Gem.autoload(:RakeNotFoundError, 'exceptions')
4
+ Gem.autoload(:TestError, 'exceptions')
3
5
 
4
6
  Gem.post_install do |gem|
5
7
  options = Gem.configuration["test_options"] || { }
@@ -9,7 +11,7 @@ Gem.post_install do |gem|
9
11
  gem.ui.ask_yes_no("Test #{gem.spec.name} (#{gem.spec.version})?", true)
10
12
 
11
13
  begin
12
- Gem::Command::TestCommand.new(gem.spec, true).execute
14
+ Gem::Commands::TestCommand.new(gem.spec, true).execute
13
15
  rescue Gem::RakeNotFoundError, Gem::TestError
14
16
  if (options.has_key?("force_install") and !options["force_install"]) or
15
17
  options["force_uninstall_on_failure"] or
data/test/helper.rb CHANGED
@@ -56,11 +56,42 @@ class Test::Unit::TestCase
56
56
  Gem.configuration.verbose = false
57
57
  end
58
58
 
59
+ def set_gem_temp_paths
60
+ @gem_temp_path = Dir.mktmpdir('rubygems-test')
61
+ @gem_home = Gem.dir
62
+ @gem_paths = Gem.path
63
+
64
+ Gem.clear_paths
65
+ if Gem.path.kind_of?(String)
66
+ Gem.path.replace @gem_temp_path
67
+ else
68
+ Gem.path.replace [@gem_temp_path]
69
+ end
70
+ Gem.send :set_home, @gem_temp_path
71
+
72
+ Gem.refresh
73
+ end
74
+
75
+ def unset_gem_temp_paths
76
+ FileUtils.rm_rf @gem_temp_path if @gem_temp_path
77
+ Gem.clear_paths
78
+
79
+ if Gem.path.kind_of?(String)
80
+ Gem.path.replace @gem_paths.join(File::PATH_SEPARATOR)
81
+ else
82
+ Gem.path.replace @gem_paths
83
+ end
84
+ Gem.send :set_home, @gem_home
85
+ Gem.refresh
86
+ end
87
+
59
88
  def setup
60
89
  set_configuration({ })
90
+ set_gem_temp_paths
61
91
  end
62
92
 
63
93
  def teardown
64
94
  uninstall_stub_gem rescue nil
95
+ unset_gem_temp_paths
65
96
  end
66
97
  end
data/test/test_execute.rb CHANGED
@@ -46,13 +46,7 @@ class TestExecute < Test::Unit::TestCase
46
46
  uninstall_stub_gem
47
47
  end
48
48
 
49
- def test_06_find_rake
50
- # XXX how do I test this fully without nuking rake?
51
- assert_nothing_raised { @test.find_rake }
52
- assert_not_nil @test.find_rake
53
- end
54
-
55
- def test_07_gather_results
49
+ def test_06_gather_results
56
50
  install_stub_gem({})
57
51
 
58
52
  spec = @test.find_gem("test-gem", "0.0.0")
@@ -76,8 +70,4 @@ class TestExecute < Test::Unit::TestCase
76
70
 
77
71
  assert_equal YAML.load(@test.gather_results(spec, output, true)), hash
78
72
  end
79
-
80
- def test_08_print_errors_from_server
81
-
82
- end
83
73
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
8
- - 6
9
- version: 0.2.6
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Erik Hollensbe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-15 00:00:00 -05:00
18
+ date: 2011-01-30 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -57,19 +57,20 @@ executables: []
57
57
  extensions: []
58
58
 
59
59
  extra_rdoc_files:
60
- - README.txt
61
60
  - History.txt
62
61
  - Manifest.txt
62
+ - README.txt
63
63
  files:
64
64
  - .gemtest
65
- - LICENSE
66
- - README.txt
67
65
  - History.txt
66
+ - LICENSE
68
67
  - Manifest.txt
68
+ - README.txt
69
69
  - Rakefile
70
70
  - gems/Rakefile
71
71
  - gems/template.gemspec
72
72
  - gems/test/test_pass.rb
73
+ - lib/exceptions.rb
73
74
  - lib/open4-vendor.rb
74
75
  - lib/rubygems/commands/test_command.rb
75
76
  - lib/rubygems/on_install_test.rb