Run tests with warnings #142

wants to merge 2 commits into

2 participants


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

  # 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

unless ENV['WARN_FILTER'] == 'false'
  at_exit do
    if WarnFilter.count > 0
      $stderr.puts "(WarnFilter filtered #{WarnFilter.count} warnings, set WARN_FILTER=false in ENV to see warnings)"
Simon Chiang added some commits Mar 9, 2012

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


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 May 2, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment