Skip to content

Commit

Permalink
Use a sentinel value as the default for verbose_flag so nil and false…
Browse files Browse the repository at this point in the history
… mean silent like 0.8.7
  • Loading branch information
drbrain committed Jun 24, 2011
1 parent d9dd16b commit d383d95
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* The rake test loader now removes arguments it has processed. Issue #51
* Rake::TaskArguments now responds to #values_at
* Rake tests are now directory-independent
* RakeFileUtils.verbose_flag = nil silences output the same as 0.8.7

== Version 0.9.2

Expand Down
7 changes: 5 additions & 2 deletions lib/rake/file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def sh(*cmd, &block)
options[:noop] ||= Rake::FileUtilsExt.nowrite_flag
Rake.rake_check_options options, :noop, :verbose
Rake.rake_output_message cmd.join(" ") if options[:verbose]

unless options[:noop]
res = rake_system(*cmd)
status = $?
Expand All @@ -56,8 +57,10 @@ def create_shell_runner(cmd)
private :create_shell_runner

def set_verbose_option(options)
if options[:verbose].nil?
options[:verbose] = Rake::FileUtilsExt.verbose_flag.nil? || Rake::FileUtilsExt.verbose_flag
unless options.key? :verbose
options[:verbose] =
Rake::FileUtilsExt.verbose_flag == Rake::FileUtilsExt::DEFAULT ||
Rake::FileUtilsExt.verbose_flag
end
end
private :set_verbose_option
Expand Down
5 changes: 4 additions & 1 deletion lib/rake/file_utils_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ module FileUtilsExt
class << self
attr_accessor :verbose_flag, :nowrite_flag
end
FileUtilsExt.verbose_flag = nil

DEFAULT = Object.new

FileUtilsExt.verbose_flag = DEFAULT
FileUtilsExt.nowrite_flag = false

$fileutils_verbose = true
Expand Down
19 changes: 17 additions & 2 deletions test/test_rake_file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class TestRakeFileUtils < Rake::TestCase

def teardown
FileUtils::LN_SUPPORTED[0] = true
RakeFileUtils.verbose_flag = Rake::FileUtilsExt::DEFAULT

super
end
Expand Down Expand Up @@ -101,7 +102,11 @@ def test_nowrite

def test_file_utils_methods_are_available_at_top_level
create_file("a")
rm_rf "a"

capture_io do
rm_rf "a"
end

refute File.exist?("a")
end

Expand Down Expand Up @@ -208,7 +213,7 @@ def test_sh_verbose
assert_equal "shellcommand.rb\n", err
end

def test_sh_no_verbose
def test_sh_verbose_false
shellcommand

_, err = capture_io do
Expand All @@ -220,6 +225,16 @@ def test_sh_no_verbose
assert_equal '', err
end

def test_sh_verbose_flag_nil
shellcommand

RakeFileUtils.verbose_flag = nil

assert_silent do
sh %{shellcommand.rb}, :noop=>true
end
end

def test_ruby_with_a_single_string_argument
check_expansion

Expand Down

0 comments on commit d383d95

Please sign in to comment.