Skip to content
This repository
Browse code

Remove requirement for session gem from rake tests

  • Loading branch information...
commit 3680bf61101fbedaa5ec3a1d6b961ad538ee5797 1 parent 412a19c
Eric Hodel authored July 22, 2011
33  Rakefile
@@ -12,7 +12,7 @@ require 'rubygems'
12 12
 system_rake = File.join RbConfig::CONFIG['rubylibdir'], 'rake.rb'
13 13
 
14 14
 # Use our rake, not the installed rake from system
15  
-if $".include? system_rake then
  15
+if $".include? system_rake or $".grep(/rake\/name_space\.rb$/).empty? then
16 16
   exec Gem.ruby, '-Ilib', 'bin/rake', *ARGV
17 17
 end
18 18
 
@@ -155,41 +155,22 @@ if ! defined?(Gem)
155 155
   puts "Package Target requires RubyGems"
156 156
 else
157 157
   SPEC = Gem::Specification.new do |s|
158  
-
159  
-    #### Basic information.
160  
-
161 158
     s.name = 'rake'
162 159
     s.version = $package_version
163 160
     s.summary = "Ruby based make-like utility."
164  
-    s.description = <<-EOF
165  
-      Rake is a Make-like program implemented in Ruby. Tasks
166  
-      and dependencies are specified in standard Ruby syntax.
  161
+    s.description = <<-EOF.delete "\n"
  162
+Rake is a Make-like program implemented in Ruby. Tasks and dependencies are
  163
+specified in standard Ruby syntax.
167 164
     EOF
168 165
 
169  
-    #### Dependencies and requirements.
170  
-
171 166
     s.required_ruby_version = '>= 1.8.6'
172 167
     s.required_rubygems_version = '>= 1.3.2'
173 168
     s.add_development_dependency 'minitest', '~> 2.1'
174  
-    s.add_development_dependency 'session', '~> 2.4'
175  
-
176  
-    #### Which files are to be included in this gem?  Everything!  (Except CVS directories.)
177 169
 
178 170
     s.files = PKG_FILES.to_a
179 171
 
180  
-    #### C code extensions.
181  
-
182  
-    #s.extensions << "ext/rmagic/extconf.rb"
183  
-
184  
-    #### Load-time details: library and application (you will need one or both).
185  
-
186  
-    s.require_path = 'lib'                         # Use these for libraries.
187  
-
188  
-    s.bindir = "bin"                               # Use these for applications.
189 172
     s.executables = ["rake"]
190 173
 
191  
-    #### Documentation and testing.
192  
-
193 174
     s.extra_rdoc_files = FileList[
194 175
       'README.rdoc',
195 176
       'MIT-LICENSE',
@@ -200,16 +181,10 @@ else
200 181
 
201 182
     s.rdoc_options = BASE_RDOC_OPTIONS
202 183
 
203  
-    #### Author and project details.
204  
-
205 184
     s.author = "Jim Weirich"
206 185
     s.email = "jim@weirichhouse.org"
207 186
     s.homepage = "http://rake.rubyforge.org"
208 187
     s.rubyforge_project = "rake"
209  
-#     if ENV['CERT_DIR']
210  
-#       s.signing_key = File.join(ENV['CERT_DIR'], 'gem-private_key.pem')
211  
-#       s.cert_chain  = [File.join(ENV['CERT_DIR'], 'gem-public_cert.pem')]
212  
-#     end
213 188
   end
214 189
 
215 190
   Gem::PackageTask.new(SPEC) do |pkg|
15  lib/rake/application.rb
@@ -85,14 +85,12 @@ def load_rakefile
85 85
 
86 86
     # Run the top level tasks of a Rake application.
87 87
     def top_level
88  
-      standard_exception_handling do
89  
-        if options.show_tasks
90  
-          display_tasks_and_comments
91  
-        elsif options.show_prereqs
92  
-          display_prerequisites
93  
-        else
94  
-          top_level_tasks.each { |task_name| invoke_task(task_name) }
95  
-        end
  88
+      if options.show_tasks
  89
+        display_tasks_and_comments
  90
+      elsif options.show_prereqs
  91
+        display_prerequisites
  92
+      else
  93
+        top_level_tasks.each { |task_name| invoke_task(task_name) }
96 94
       end
97 95
     end
98 96
 
@@ -348,6 +346,7 @@ def standard_rake_options
348 346
         ],
349 347
         ['--rakelibdir', '--rakelib', '-R RAKELIBDIR',
350 348
           "Auto-import any .rake files in RAKELIBDIR. (default is 'rakelib')",
  349
+          # HACK Use File::PATH_SEPARATOR
351 350
           lambda { |value| options.rakelib = value.split(':') }
352 351
         ],
353 352
         ['--require', '-r MODULE', "Require MODULE before executing rakefile.",
12  test/helper.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require 'rubygems'
2  
-require 'minitest/unit'
3 2
 require 'minitest/autorun'
4 3
 require 'rake'
5 4
 require 'tmpdir'
@@ -428,17 +427,6 @@ def rakefile_rbext
428 427
     end
429 428
   end
430 429
 
431  
-  def rakefile_statusreturn
432  
-    rakefile <<-STATUSRETURN
433  
-task :exit5 do
434  
-  exit(5)
435  
-end
436  
-
437  
-task :normal do
438  
-end
439  
-    STATUSRETURN
440  
-  end
441  
-
442 430
   def rakefile_unittest
443 431
     rakefile '# Empty Rakefile for Unit Test'
444 432
 
61  test/test_rake_application.rb
@@ -405,6 +405,67 @@ def test_deprecation_message
405 405
     assert_match(/at c$/i, err)
406 406
   end
407 407
 
  408
+  def test_standard_exception_handling_invalid_option
  409
+    out, err = capture_io do
  410
+      e = assert_raises SystemExit do
  411
+        @app.standard_exception_handling do
  412
+          raise OptionParser::InvalidOption, 'blah'
  413
+        end
  414
+      end
  415
+
  416
+      assert_equal 1, e.status
  417
+    end
  418
+
  419
+    assert_empty out
  420
+    assert_equal "invalid option: blah\n", err
  421
+  end
  422
+
  423
+  def test_standard_exception_handling_other
  424
+    out, err = capture_io do
  425
+      e = assert_raises SystemExit do
  426
+        @app.standard_exception_handling do
  427
+          raise 'blah'
  428
+        end
  429
+      end
  430
+
  431
+      assert_equal 1, e.status
  432
+    end
  433
+
  434
+    assert_empty out
  435
+    assert_match "rake aborted!\n", err
  436
+    assert_match "blah\n", err
  437
+  end
  438
+
  439
+  def test_standard_exception_handling_system_exit
  440
+    out, err = capture_io do
  441
+      e = assert_raises SystemExit do
  442
+        @app.standard_exception_handling do
  443
+          exit 0
  444
+        end
  445
+      end
  446
+
  447
+      assert_equal 0, e.status
  448
+    end
  449
+
  450
+    assert_empty out
  451
+    assert_empty err
  452
+  end
  453
+
  454
+  def test_standard_exception_handling_system_exit_nonzero
  455
+    out, err = capture_io do
  456
+      e = assert_raises SystemExit do
  457
+        @app.standard_exception_handling do
  458
+          exit 5
  459
+        end
  460
+      end
  461
+
  462
+      assert_equal 5, e.status
  463
+    end
  464
+
  465
+    assert_empty out
  466
+    assert_empty err
  467
+  end
  468
+
408 469
   def util_loader
409 470
     loader = Object.new
410 471
 
97  test/test_rake_functional.rb
... ...
@@ -1,38 +1,6 @@
1  
-begin
2  
-  old_verbose = $VERBOSE
3  
-  $VERBOSE = nil
4  
-  require 'session'
5  
-rescue LoadError
6  
-  if File::ALT_SEPARATOR
7  
-    puts "Unable to run functional tests on MS Windows. Skipping."
8  
-  else
9  
-    puts "Unable to run functional tests -- please run \"gem install session\""
10  
-  end
11  
-ensure
12  
-  $VERBOSE = old_verbose
13  
-end
14  
-
15  
-if defined?(Session)
16  
-  if File::ALT_SEPARATOR
17  
-    puts "Unable to run functional tests on MS Windows. Skipping."
18  
-  end
19  
-end
20  
-
21 1
 require File.expand_path('../helper', __FILE__)
22 2
 require 'fileutils'
23  
-
24  
-# Version 2.1.9 of session has a bug where the @debug instance
25  
-# variable is not initialized, causing warning messages.  This snippet
26  
-# of code fixes that problem.
27  
-module Session
28  
-  class AbstractSession
29  
-    alias old_initialize initialize
30  
-    def initialize(*args)
31  
-      @debug = nil
32  
-      old_initialize(*args)
33  
-    end
34  
-  end
35  
-end if defined? Session
  3
+require 'open3'
36 4
 
37 5
 class TestRakeFunctional < Rake::TestCase
38 6
 
@@ -59,16 +27,15 @@ def test_rake_default
59 27
     rake
60 28
 
61 29
     assert_match(/^DEFAULT$/, @out)
62  
-    assert_status
63 30
   end
64 31
 
65 32
   def test_rake_error_on_bad_task
66 33
     rakefile_default
67 34
 
68  
-    rake "xyz"
  35
+    rake '-t', 'xyz'
69 36
 
  37
+    puts @err
70 38
     assert_match(/rake aborted/, @err)
71  
-    assert_status(1)
72 39
   end
73 40
 
74 41
   def test_env_available_at_top_scope
@@ -77,16 +44,14 @@ def test_env_available_at_top_scope
77 44
     rake "TESTTOPSCOPE=1"
78 45
 
79 46
     assert_match(/^TOPSCOPE$/, @out)
80  
-    assert_status
81 47
   end
82 48
 
83 49
   def test_env_available_at_task_scope
84 50
     rakefile_default
85 51
 
86  
-    rake "TESTTASKSCOPE=1 task_scope"
  52
+    rake 'TESTTASKSCOPE=1', 'task_scope'
87 53
 
88 54
     assert_match(/^TASKSCOPE$/, @out)
89  
-    assert_status
90 55
   end
91 56
 
92 57
   def test_multi_desc
@@ -283,8 +248,6 @@ def test_dry_run_bug
283 248
     rake "--dry-run"
284 249
 
285 250
     refute_match(/No such file/, @out)
286  
-
287  
-    assert_status
288 251
   end
289 252
 
290 253
   # Test for the trace/dry_run bug found by Brian Chandler
@@ -298,7 +261,6 @@ def test_trace_bug
298 261
     rake "--trace"
299 262
 
300 263
     refute_match(/No such file/, @out)
301  
-    assert_status
302 264
   end
303 265
 
304 266
   def test_imports
@@ -309,7 +271,6 @@ def test_imports
309 271
     assert File.exist?(File.join(@tempdir, 'dynamic_deps')),
310 272
            "'dynamic_deps' file should exist"
311 273
     assert_match(/^FIRST$\s+^DYNAMIC$\s+^STATIC$\s+^OTHER$/, @out)
312  
-    assert_status
313 274
   end
314 275
 
315 276
   def test_rules_chaining_to_file_task
@@ -319,7 +280,6 @@ def test_rules_chaining_to_file_task
319 280
 
320 281
     assert File.exist?(File.join(@tempdir, 'play.app')),
321 282
            "'play.app' file should exist"
322  
-    assert_status
323 283
   end
324 284
 
325 285
   def test_file_creation_task
@@ -335,7 +295,7 @@ def test_file_creation_task
335 295
   def test_dash_f_with_no_arg_foils_rakefile_lookup
336 296
     rakefile_rakelib
337 297
 
338  
-    rake "-I rakelib -rtest1 -f"
  298
+    rake '-I', 'rakelib', '-rtest1', '-f'
339 299
 
340 300
     assert_match(/^TEST1$/, @out)
341 301
   end
@@ -343,8 +303,9 @@ def test_dash_f_with_no_arg_foils_rakefile_lookup
343 303
   def test_dot_rake_files_can_be_loaded_with_dash_r
344 304
     rakefile_rakelib
345 305
 
346  
-    rake "-I rakelib -rtest2 -f"
  306
+    rake '-I', 'rakelib', '-rtest2', '-f'
347 307
 
  308
+    assert_empty @err
348 309
     assert_match(/^TEST2$/, @out)
349 310
   end
350 311
 
@@ -412,22 +373,6 @@ def test_file_task_dependencies_scoped_by_namespaces
412 373
     assert_match(/^PREPARE\nSCOPEDEP$/m, @out)
413 374
   end
414 375
 
415  
-  def test_rake_returns_status_error_values
416  
-    rakefile_statusreturn
417  
-
418  
-    rake "exit5"
419  
-
420  
-    assert_status 5
421  
-  end
422  
-
423  
-  def test_rake_returns_no_status_error_on_normal_exit
424  
-    rakefile_statusreturn
425  
-
426  
-    rake "normal"
427  
-
428  
-    assert_status 0
429  
-  end
430  
-
431 376
   def test_comment_before_task_acts_like_desc
432 377
     rakefile_comments
433 378
 
@@ -469,42 +414,38 @@ def test_correct_number_of_tasks_reported
469 414
   end
470 415
 
471 416
   def test_file_list_is_requirable_separately
472  
-    ruby "-rrake/file_list", "-e 'puts Rake::FileList[\"a\"].size'"
  417
+    ruby '-rrake/file_list', '-e', 'puts Rake::FileList["a"].size'
473 418
     assert_equal "1\n", @out
474  
-    assert_equal 0, @status
475 419
   end
476 420
 
477 421
   private
478 422
 
479 423
   # Run a shell Ruby command with command line options (using the
480  
-  # default test options). Output is captured in @out, @err and
481  
-  # @status.
  424
+  # default test options). Output is captured in @out and @err
482 425
   def ruby(*option_list)
483 426
     run_ruby(@ruby_options + option_list)
484 427
   end
485 428
 
486 429
   # Run a command line rake with the give rake options.  Default
487 430
   # command line ruby options are included.  Output is captured in
488  
-  # @out, @err and @status.
  431
+  # @out and @err
489 432
   def rake(*rake_options)
490 433
     run_ruby @ruby_options + [@rake_path] + rake_options
491 434
   end
492 435
 
493 436
   # Low level ruby command runner ...
494 437
   def run_ruby(option_list)
495  
-    shell = Session::Shell.new
496  
-    command = "#{Gem.ruby} #{option_list.join ' '}"
497  
-    puts "COMMAND: [#{command}]" if @verbose
498  
-    @out, @err = shell.execute command
499  
-    @status = shell.exit_status
500  
-    puts "STATUS:  [#{@status}]" if @verbose
  438
+    puts "COMMAND: [#{Gem.ruby} #{option_list.join ' '}]" if @verbose
  439
+
  440
+    inn, out, err, wait = Open3.popen3(Gem.ruby, *option_list)
  441
+    inn.close
  442
+
  443
+    @out = out.read
  444
+    @err = err.read
  445
+
501 446
     puts "OUTPUT:  [#{@out}]" if @verbose
502 447
     puts "ERROR:   [#{@err}]" if @verbose
503 448
     puts "PWD:     [#{Dir.pwd}]" if @verbose
504  
-    shell.close
505 449
   end
506 450
 
507  
-  def assert_status(expected_status=0)
508  
-    assert_equal expected_status, @status
509  
-  end
510  
-end if defined?(Session)
  451
+end
8  test/test_rake_task_manager.rb
@@ -19,6 +19,14 @@ def test_define_task
19 19
     assert_equal @tm, t.application
20 20
   end
21 21
 
  22
+  def test_index
  23
+    e = assert_raises RuntimeError do
  24
+      @tm['bad']
  25
+    end
  26
+
  27
+    assert_equal "Don't know how to build task 'bad'", e.message
  28
+  end
  29
+
22 30
   def test_name_lookup
23 31
     t = @tm.define_task(Rake::Task, :t)
24 32
     assert_equal t, @tm[:t]

0 notes on commit 3680bf6

Please sign in to comment.
Something went wrong with that request. Please try again.