屏蔽rake testtask的warning
查找rake中warn相关字眼
$rake-12.0.0 git:(master) grep warn -rn *
doc/command_line_usage.rdoc:153:[--no-deprecation-warnings (-X)]
doc/command_line_usage.rdoc:154: Do not display the deprecation warnings.
doc/rake.1:117:.It Fl X , Fl -no-deprecation-warnings
doc/rake.1:118:Disable the deprecation warnings.
History.rdoc:7:* Removed to deprecated warnings for `last\_comment`.
History.rdoc:99:* Use ruby warnings by default. Pull request #97 by Harold Giménez
History.rdoc:335: RakeApp). The constant missing hook to warn about using
History.rdoc:340: warnings) in Object have been removed. However, the DSL methods are
History.rdoc:583: RakeApp). The constant missing hook to warn about using
History.rdoc:588: warnings) in Object have been removed. However, the DSL methods are
History.rdoc:956:* Global DSL warnings now honor --no-deprecate
History.rdoc:990:warning messages.
History.rdoc:1024:* Rake now warns when the deprecated :needs syntax used (and suggests
History.rdoc:1025: the proper syntax in the warning).
History.rdoc:1055:* Rake no longer emits warnings for Config. Patch by Santiago Pastorino.
History.rdoc:1080:* Accepted change by warnickr to not expand test patterns in shell
History.rdoc:1238:* Removed reference to manage_gem to fix the warning produced by the
History.rdoc:1912: rake will print a rather annoying warning whenever a
History.rdoc:2040:* Added warning option for the Test Task (requested by Eric Hodel).
History.rdoc:2068:* Several fixes for new warnings generated.
lib/rake/application.rb:587: ["--no-deprecation-warnings", "-X",
lib/rake/application.rb:588: "Disable the deprecation warnings.",
lib/rake/ext/core.rb:3: # the method already exists, then a warning is printed and the extension is
lib/rake/testtask.rb:51: # Request that the tests be run with the warning flag set.
lib/rake/testtask.rb:52: # E.g. warning=true implies "ruby -w" used to run the tests.
lib/rake/testtask.rb:53: attr_accessor :warning
lib/rake/testtask.rb:91: @warning = true
lib/rake/testtask.rb:148: opts.unshift("-w") if @warning
Binary file lib/rake/.testtask.rb.swp matches
发现就在testtask中,且@warning默认为true,但有accessor可改变它
module Rake
class TestTask < TaskLib
#..
attr_accessor :warning
#..
def initialize(name=:test)
@name = name
@libs = ["lib"]
@pattern = nil
@options = nil
@test_files = nil
@verbose = false
@warning = true
@loader = :rake
@ruby_opts = []
@description = "Run tests" + (@name == :test ? "" : " for #{@name}")
@deps = []
if @name.is_a?(Hash)
@deps = @name.values.first
@name = @name.keys.first
end
yield self if block_given?
@pattern = "test/test*.rb" if @pattern.nil? && @test_files.nil?
define
end
于是可以这样
Rake::TestTask.new(:test) do |t|
t.warning = false
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/*_test.rb']
end
或者加入检查ARGV是否带有-W0,然后再设置t.warning为true或false。这是ruby bin可用的选项,不过rake cli不认此项,需自己在rakefile中另行判断
t.warning = false if ARGV.index('-W0')
然后cli需带上double dash,否则会被rake当成传给它自己的选项,然后报错说不支持此项
rake test -- -W0
不过,屏蔽warning是不好的做法……