Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Run tests with warnings #142

Closed
wants to merge 2 commits into from

2 participants

@thinkerbot

Doing so is a good practice. In the case of tilt, it's also a PITA because so many of the template gems generate warnings. It's possible to filter them in 1.8.7 using the module below... but I couldn't get it to work on 1.9.2 (I'm not sure why). At any rate this pull request fixes a few warnings in tilt itself. I split it into one commit that turns on the warnings and one that fixes them in case you want to cherry-pick.

WarnFilter Add to test folder and require in test/contest to enable.

# Filter warnings from vendored gems.  Must be included before the filtered
# code is required (obviously).
#
# WarnFilter can be turned off by specifying ENV['WARN_FILTER'] = 'false'.
module WarnFilter
  FILTER_PATHS = [File.expand_path('../../vendor', __FILE__), 'test.haml', '(__TEMPLATE__)']
  @@count = 0

  # A running tally of warnings that have been filtered.
  def self.count
    @@count
  end

  # Writes the message unless it begins with one of the FILTER_PATHS, in
  # which case the message is interpreted as a warning.  In that case
  # count is incremented and the message is ignored.
  def write(message)
    FILTER_PATHS.any? {|path| message.index(path) == 0 } ? @@count += 1 : super
  end
end

unless ENV['WARN_FILTER'] == 'false'
  $stderr.extend(WarnFilter)
  at_exit do
    if WarnFilter.count > 0
      $stderr.puts "(WarnFilter filtered #{WarnFilter.count} warnings, set WARN_FILTER=false in ENV to see warnings)"
    end
  end
end
@judofyr
Collaborator

I agree that running tests with warnings are nice. I'm going to revisit this later. Keeping it open for now.

@judofyr
Collaborator

I can't find an elegant way to solve this. The template engines spits out too many warnings for this to be usable for us. Closing this now; please re-open if you find a solution that works in 1.9.

@judofyr judofyr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 9, 2012
  1. @thinkerbot

    run tests with warnings

    thinkerbot authored
  2. @thinkerbot

    fix warnings

    thinkerbot authored
This page is out of date. Refresh to see the latest.
View
2  Rakefile
@@ -34,7 +34,7 @@ end
desc 'Run tests (default)'
Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/*_test.rb']
- t.ruby_opts = ['-Itest']
+ t.ruby_opts = ['-Itest', '-w']
t.ruby_opts << '-rubygems' if defined? Gem
end
task :test => :version
View
2  lib/tilt/css.rb
@@ -59,7 +59,7 @@ def prepare
if ::Less.const_defined? :Engine
@engine = ::Less::Engine.new(data)
else
- parser = ::Less::Parser.new(options.merge :filename => eval_file, :line => line)
+ parser = ::Less::Parser.new(options.merge(:filename => eval_file, :line => line))
@engine = parser.parse(data)
end
end
View
2  test/tilt_fallback_test.rb
@@ -67,7 +67,7 @@ def clear_ivar(obj, name)
Tilt.register("md", FailTemplate2)
exc = assert_raise(LoadError) { Tilt["md"] }
- assert_match /FailTemplate2/, exc.message
+ assert_match(/FailTemplate2/, exc.message)
end
test ".prefer should also register the template" do
View
3  test/tilt_redcarpettemplate_test.rb
@@ -55,8 +55,7 @@ class RedcarpetTemplateTest < Test::Unit::TestCase
test "smartypants when :smart is set" do
template = Tilt::RedcarpetTemplate.new(:smartypants => true) { |t|
"OKAY -- 'Smarty Pants'" }
- assert_match /<p>OKAY &ndash; &#39;Smarty Pants&#39;<\/p>/,
- template.render
+ assert_match(/<p>OKAY &ndash; &#39;Smarty Pants&#39;<\/p>/, template.render)
end
end
rescue LoadError => boom
View
4 test/tilt_wikiclothtemplate_test.rb
@@ -19,12 +19,12 @@ class WikiClothTemplateTest < Test::Unit::TestCase
test "compiles and evaluates the template on #render" do
template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" }
- assert_match /<h1>.*Hello World!.*<\/h1>/, template.render
+ assert_match(/<h1>.*Hello World!.*<\/h1>/, template.render)
end
test "can be rendered more than once" do
template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" }
- 3.times { assert_match /<h1>.*Hello World!.*<\/h1>/, template.render }
+ 3.times { assert_match(/<h1>.*Hello World!.*<\/h1>/, template.render) }
end
end
rescue LoadError => boom
Something went wrong with that request. Please try again.