Skip to content
This repository

Run tests with warnings #142

Closed
wants to merge 2 commits into from

2 participants

Simon Chiang Magnus Holm
Simon Chiang

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
Magnus Holm
Collaborator

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

Magnus Holm
Collaborator
judofyr commented May 02, 2013

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.

Magnus Holm judofyr closed this May 02, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Mar 09, 2012
Simon Chiang run tests with warnings 26fb3b8
Simon Chiang fix warnings 83a5fa4
This page is out of date. Refresh to see the latest.
2  Rakefile
@@ -34,7 +34,7 @@ end
34 34
 desc 'Run tests (default)'
35 35
 Rake::TestTask.new(:test) do |t|
36 36
   t.test_files = FileList['test/*_test.rb']
37  
-  t.ruby_opts = ['-Itest']
  37
+  t.ruby_opts = ['-Itest', '-w']
38 38
   t.ruby_opts << '-rubygems' if defined? Gem
39 39
 end
40 40
 task :test => :version
2  lib/tilt/css.rb
@@ -59,7 +59,7 @@ def prepare
59 59
       if ::Less.const_defined? :Engine
60 60
         @engine = ::Less::Engine.new(data)
61 61
       else
62  
-        parser  = ::Less::Parser.new(options.merge :filename => eval_file, :line => line)
  62
+        parser  = ::Less::Parser.new(options.merge(:filename => eval_file, :line => line))
63 63
         @engine = parser.parse(data)
64 64
       end
65 65
     end
2  test/tilt_fallback_test.rb
@@ -67,7 +67,7 @@ def clear_ivar(obj, name)
67 67
     Tilt.register("md", FailTemplate2)
68 68
 
69 69
     exc = assert_raise(LoadError) { Tilt["md"] }
70  
-    assert_match /FailTemplate2/, exc.message
  70
+    assert_match(/FailTemplate2/, exc.message)
71 71
   end
72 72
 
73 73
   test ".prefer should also register the template" do
3  test/tilt_redcarpettemplate_test.rb
@@ -55,8 +55,7 @@ class RedcarpetTemplateTest < Test::Unit::TestCase
55 55
     test "smartypants when :smart is set" do
56 56
       template = Tilt::RedcarpetTemplate.new(:smartypants => true) { |t|
57 57
         "OKAY -- 'Smarty Pants'" }
58  
-      assert_match /<p>OKAY &ndash; &#39;Smarty Pants&#39;<\/p>/,
59  
-        template.render
  58
+      assert_match(/<p>OKAY &ndash; &#39;Smarty Pants&#39;<\/p>/, template.render)
60 59
     end
61 60
   end
62 61
 rescue LoadError => boom
4  test/tilt_wikiclothtemplate_test.rb
@@ -19,12 +19,12 @@ class WikiClothTemplateTest < Test::Unit::TestCase
19 19
 
20 20
     test "compiles and evaluates the template on #render" do
21 21
       template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" }
22  
-      assert_match /<h1>.*Hello World!.*<\/h1>/, template.render
  22
+      assert_match(/<h1>.*Hello World!.*<\/h1>/, template.render)
23 23
     end
24 24
 
25 25
     test "can be rendered more than once" do
26 26
       template = Tilt::WikiClothTemplate.new { |t| "= Hello World! =" }
27  
-      3.times { assert_match /<h1>.*Hello World!.*<\/h1>/, template.render }
  27
+      3.times { assert_match(/<h1>.*Hello World!.*<\/h1>/, template.render) }
28 28
     end
29 29
   end
30 30
 rescue LoadError => boom
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.