rake 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rake might be problematic. Click here for more details.

data/CHANGES CHANGED
@@ -1,5 +1,20 @@
1
1
  = Rake Changelog
2
2
 
3
+ == Version 0.4.10
4
+
5
+ * Added block support to the "sh" command, allowing users to take
6
+ special actions on the result of the system call. E.g.
7
+
8
+ sh "shell_command" do |ok, res|
9
+ puts "Program returned #{res.exitstatus}" if ! ok
10
+ end
11
+
12
+ == Version 0.4.9
13
+
14
+ * Switched to Jamis Buck's RDoc template.
15
+ * Removed autorequire from Rake's gem spec. This prevents the Rake
16
+ libraries from loading while using rails.
17
+
3
18
  == Version 0.4.8
4
19
 
5
20
  * Added support for .rb versions of Rakefile.
@@ -29,7 +29,7 @@
29
29
  # referenced as a library via a require statement, but it can be
30
30
  # distributed independently as an application.
31
31
 
32
- RAKEVERSION = '0.4.9'
32
+ RAKEVERSION = '0.4.10'
33
33
 
34
34
  require 'rbconfig'
35
35
  require 'ftools'
@@ -364,11 +364,24 @@ module FileUtils
364
364
  # Example:
365
365
  # sh %{ls -ltr}
366
366
  #
367
- def sh(cmd, options={})
367
+ # # check exit status after command runs
368
+ # sh %{grep pattern file} do |ok, res|
369
+ # if ! ok
370
+ # puts "pattern not found (status = #{res.exitstatus})"
371
+ # end
372
+ # end
373
+ #
374
+ def sh(cmd, options={}, &block)
375
+ unless block_given?
376
+ block = lambda { |ok, status|
377
+ ok or fail "Command failed with status (#{status.exitstatus}): [#{cmd}]"
378
+ }
379
+ end
368
380
  fu_check_options options, :noop, :verbose
369
381
  fu_output_message cmd if options[:verbose]
370
382
  unless options[:noop]
371
- system(cmd) or fail "Command Failed: [#{cmd}]"
383
+ res = system(cmd)
384
+ block.call(res, $?)
372
385
  end
373
386
  end
374
387
 
@@ -431,10 +444,11 @@ module RakeFileUtils
431
444
  FileUtils::OPT_TABLE.each do |name, opts|
432
445
  next unless opts.include?('verbose')
433
446
  module_eval(<<-EOS, __FILE__, __LINE__ + 1)
434
- def #{name}( *args )
447
+ def #{name}( *args, &block )
435
448
  super(*fu_merge_option(args,
436
449
  :verbose => $fileutils_verbose,
437
- :noop => $fileutils_nowrite))
450
+ :noop => $fileutils_nowrite),
451
+ &block)
438
452
  end
439
453
  EOS
440
454
  end
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ exit((ARGV[0] || "0").to_i)
@@ -52,4 +52,32 @@ class TestFileUtils < Test::Unit::TestCase
52
52
  assert_equal false, nowrite
53
53
  end
54
54
 
55
+ def test_sh
56
+ verbose(false) { sh %{test/shellcommand.rb} }
57
+ assert true, "should not fail"
58
+ end
59
+
60
+ def test_sh_failure
61
+ assert_raises(RuntimeError) {
62
+ verbose(false) { sh %{test/shellcommand.rb 1} }
63
+ }
64
+ end
65
+
66
+ def test_sh_special_handling
67
+ count = 0
68
+ verbose(false) {
69
+ sh(%{test/shellcommand.rb}) do |ok, res|
70
+ assert(ok)
71
+ assert_equal 0, res.exitstatus
72
+ count += 1
73
+ end
74
+ sh(%{test/shellcommand.rb 1}) do |ok, res|
75
+ assert(!ok)
76
+ assert_equal 1, res.exitstatus
77
+ count += 1
78
+ end
79
+ }
80
+ assert_equal 2, count, "Block count should be 2"
81
+ end
82
+
55
83
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.1
3
3
  specification_version: 1
4
4
  name: rake
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.9
7
- date: 2004-10-30
6
+ version: 0.4.10
7
+ date: 2004-11-05
8
8
  summary: Ruby based make-like utility.
9
9
  require_paths:
10
10
  - lib
@@ -53,6 +53,7 @@ files:
53
53
  - test/testtasks.rb
54
54
  - test/testftp.rb
55
55
  - test/testfileutils.rb
56
+ - test/shellcommand.rb
56
57
  - test/testpackagetask.rb
57
58
  - test/functional.rb
58
59
  - test/testtesttask.rb