rubygems-test 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1 +1,11 @@
1
+ === 0.2.2 / 1/10/2011
2
+
3
+ * Windows + 1.8 support. Requires the 'win32-open3' gem.
4
+
5
+ * --force option - run tests even if the gem author hasn't opted in. Do not
6
+ upload these results ever.
7
+
8
+ * --dep-user-install option - install any development dependencies to
9
+ Gem.user_dir
10
+
1
11
  === 0.1.9 / Sometime before hoe
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.1'
15
+ self.version = '0.2.2'
16
16
 
17
17
  self.rubyforge_name = nil
18
18
 
@@ -26,7 +26,7 @@ class Gem::Commands::TestCommand < Gem::Command
26
26
  end
27
27
 
28
28
  def usage
29
- "#{program_name} GEM -v VERSION"
29
+ "#{program_name} GEM [-v VERSION] [--force] [--dep-user-install]"
30
30
  end
31
31
 
32
32
  def initialize(spec=nil, on_install=false)
@@ -41,6 +41,20 @@ class Gem::Commands::TestCommand < Gem::Command
41
41
 
42
42
  super 'test', description, options
43
43
  add_version_option
44
+
45
+ add_option(
46
+ '--force',
47
+ 'ignore opt-in testing and just run the tests'
48
+ ) do |v,o|
49
+ o[:force] = true
50
+ end
51
+
52
+ add_option(
53
+ '--dep-user-install',
54
+ 'force installing the dependencies into the user path'
55
+ ) do |v,o|
56
+ o[:dep_user_install] = true
57
+ end
44
58
  end
45
59
 
46
60
  #
@@ -95,7 +109,13 @@ class Gem::Commands::TestCommand < Gem::Command
95
109
  # Install development dependencies for the gem we're about to test.
96
110
  #
97
111
  def install_dependencies(spec)
98
- di = Gem::DependencyInstaller.new
112
+ di = nil
113
+
114
+ if options[:dep_user_install]
115
+ di = Gem::DependencyInstaller.new(:install_dir => Gem.user_dir)
116
+ else
117
+ di = Gem::DependencyInstaller.new
118
+ end
99
119
 
100
120
  spec.development_dependencies.each do |dep|
101
121
  unless Gem.source_index.search(dep).last
@@ -132,8 +152,14 @@ class Gem::Commands::TestCommand < Gem::Command
132
152
  case response
133
153
  when Net::HTTPSuccess
134
154
  body = YAML::load(response.body)
135
- url = body[:data][0] if body[:data]
136
- say "Test results posted successfully! \n\t#{url}"
155
+ if body[:success]
156
+ url = body[:data][0] if body[:data]
157
+ say "Test results posted successfully! \n\t#{url}"
158
+ else
159
+ body[:errors].each do |error|
160
+ say error
161
+ end if body[:errors]
162
+ end
137
163
  when Net::HTTPRedirection
138
164
  location = response.fetch('Location')
139
165
  if !location or URI.parse(location) == url
@@ -184,78 +210,95 @@ class Gem::Commands::TestCommand < Gem::Command
184
210
  exit_status = nil
185
211
 
186
212
  Dir.chdir(spec.full_gem_path) do
187
-
188
- if spec.files.include?(".gemtest")
189
- reader_proc = proc do |orig_handles|
190
- current_handles = orig_handles.dup
191
-
192
- handles, _, _ = IO.select(current_handles, nil, nil, 0.1)
193
- buf = ""
194
-
195
- if handles
196
- handles.compact.each do |io|
197
- begin
198
- buf += io.readline
199
- rescue EOFError
200
- buf += io.read rescue ""
201
- current_handles.reject! { |x| x == io }
202
- end
203
- end
204
- end
205
-
206
- [buf, current_handles]
213
+ reader_proc = proc do |orig_handles|
214
+ current_handles = orig_handles.dup
215
+
216
+ handles, _, _ = IO.select(current_handles, nil, nil, 0.1)
217
+ buf = ""
218
+
219
+ if handles
220
+ handles.compact.each do |io|
221
+ begin
222
+ buf += io.readline
223
+ rescue EOFError
224
+ buf += io.read rescue ""
225
+ current_handles.reject! { |x| x == io }
226
+ end
227
+ end
207
228
  end
208
229
 
209
- outer_reader_proc = proc do |stdout, stderr|
210
- loop do
211
- handles = [stderr, stdout]
212
- buf, handles = reader_proc.call(handles)
213
- output += buf
214
- print buf
215
- break if handles.empty?
216
- end
230
+ [buf, current_handles]
231
+ end
232
+
233
+ outer_reader_proc = proc do |stdout, stderr|
234
+ loop do
235
+ handles = [stderr, stdout]
236
+ buf, handles = reader_proc.call(handles)
237
+ output += buf
238
+ print buf
239
+ break if handles.empty?
217
240
  end
241
+ end
218
242
 
219
- rake_args = [rake_path, 'test', '--trace']
243
+ rake_args = [rake_path, 'test', '--trace']
220
244
 
221
- # jruby stuffs it under IO, so we'll use that if it's available
222
- klass =
223
- if IO.respond_to?(:popen4)
224
- IO.popen4(*rake_args) do |pid, stdin, stdout, stderr|
245
+ # jruby stuffs it under IO, so we'll use that if it's available
246
+ klass =
247
+ if IO.respond_to?(:popen4)
248
+ IO.popen4(*rake_args) do |pid, stdin, stdout, stderr|
249
+ outer_reader_proc.call(stdout, stderr)
250
+ end
251
+ exit_status = $?
252
+ elsif RUBY_VERSION > '1.9'
253
+ require 'open3'
254
+ exit_status = Open3.popen3(*rake_args) do |stdin, stdout, stderr, thr|
255
+ outer_reader_proc.call(stdout, stderr)
256
+ thr.value
257
+ end
258
+ elsif RUBY_PLATFORM =~ /mingw/
259
+ begin
260
+ require 'win32/open3'
261
+ Open3.popen3([File.join(RbConfig::CONFIG["bindir"], 'ruby'), *rake_args].join(' ')) do |stdin, stdout, stderr|
225
262
  outer_reader_proc.call(stdout, stderr)
226
263
  end
227
264
  exit_status = $?
228
- elsif RUBY_VERSION > '1.9'
229
- require 'open3'
230
- exit_status = Open3.popen3(*rake_args) do |stdin, stdout, stderr, thr|
231
- outer_reader_proc.call(stdout, stderr)
232
- thr.value
233
- end
234
- else
235
- require 'open4-vendor'
236
- exit_status = Open4.popen4(*rake_args) do |pid, stdin, stdout, stderr|
237
- outer_reader_proc.call(stdout, stderr)
238
- end
265
+ rescue LoadError
266
+ say "1.8/Windows users must install the 'win32-open3' gem to run tests"
267
+ terminate_interaction 1
268
+ end
269
+ else
270
+ require 'open4-vendor'
271
+ exit_status = Open4.popen4(*rake_args) do |pid, stdin, stdout, stderr|
272
+ outer_reader_proc.call(stdout, stderr)
239
273
  end
240
-
241
-
242
- if config["upload_results"] or
243
- (!config.has_key?("upload_results") and ask_yes_no("Upload these results?", true))
244
-
245
- upload_results(gather_results(spec, output, exit_status.exitstatus == 0))
246
274
  end
247
275
 
248
- if exit_status.exitstatus != 0
249
- alert_error "Tests did not pass. Examine the output and report it to the author!"
276
+ if upload_results?
277
+ upload_results(gather_results(spec, output, exit_status.exitstatus == 0))
278
+ end
250
279
 
251
- raise Gem::TestError, "tests failed"
252
- end
253
- else
254
- alert_warning "This gem has no tests! Please contact the author to gain testing and reporting!"
280
+ if exit_status.exitstatus != 0
281
+ alert_error "Tests did not pass. Examine the output and report it to the author!"
282
+
283
+ raise Gem::TestError, "tests failed"
255
284
  end
256
285
  end
257
286
  end
258
287
 
288
+ #
289
+ # Convenience predicate for upload_results option
290
+ #
291
+ def upload_results?
292
+ !options[:force] and (
293
+ config["upload_results"] or
294
+ (
295
+ !config.has_key?("upload_results") and
296
+ ask_yes_no("Upload these results?", true)
297
+ )
298
+ )
299
+ end
300
+
301
+
259
302
  #
260
303
  # Execute routine. This is where the magic happens.
261
304
  #
@@ -271,7 +314,7 @@ class Gem::Commands::TestCommand < Gem::Command
271
314
  next
272
315
  end
273
316
 
274
- if spec.files.include?('.gemtest')
317
+ if spec.files.include?('.gemtest') or options[:force]
275
318
  # we find rake and the rakefile first to eliminate needlessly installing
276
319
  # dependencies.
277
320
  find_rakefile(spec)
@@ -280,6 +323,20 @@ class Gem::Commands::TestCommand < Gem::Command
280
323
  install_dependencies(spec)
281
324
 
282
325
  run_tests(spec, rake_path)
326
+ else
327
+ say "Gem '#{name}' (version #{version}) needs to opt-in for testing."
328
+ say ""
329
+ say "Locally available testing helps gems maintain high quality by"
330
+ say "ensuring they work correctly on a wider array of platforms than the"
331
+ say "original developer can access."
332
+ say ""
333
+ say "If you are the author: "
334
+ say " * Add the file '.gemtest' to your spec.files"
335
+ say " * Ensure 'rake test' works and doesn't do system damage"
336
+ say " * Add your tests and Rakefile to your gem."
337
+ say ""
338
+ say "For more information, please see the rubygems-test README:"
339
+ say "https://github.com/rubygems/rubygems-test/blob/master/README.txt"
283
340
  end
284
341
  end
285
342
  rescue Gem::TestError
data/test/helper.rb CHANGED
@@ -58,4 +58,8 @@ class Test::Unit::TestCase
58
58
  def setup
59
59
  set_configuration({ })
60
60
  end
61
+
62
+ def teardown
63
+ uninstall_stub_gem rescue nil
64
+ end
61
65
  end
data/test/test_execute.rb CHANGED
@@ -18,7 +18,7 @@ class TestExecute < Test::Unit::TestCase
18
18
  def test_02_gem_command_attributes
19
19
  assert_equal @test.description, "Run the tests for a specific gem"
20
20
  assert_equal @test.arguments, "GEM: name of gem"
21
- assert_equal @test.usage, "#{@test.program_name} GEM -v VERSION"
21
+ assert_equal @test.usage, "#{@test.program_name} GEM [-v VERSION] [--force] [--dep-user-install]"
22
22
  end
23
23
 
24
24
  def test_04_find_gem
@@ -76,4 +76,8 @@ class TestExecute < Test::Unit::TestCase
76
76
 
77
77
  assert_equal YAML.load(@test.gather_results(spec, output, true)), hash
78
78
  end
79
+
80
+ def test_08_print_errors_from_server
81
+
82
+ end
79
83
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
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-08 00:00:00 -05:00
18
+ date: 2011-01-10 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency