Add warning whitelist support for specs
Ported from ammar/regexp_parser#26
This commit is contained in:
parent
d07daec9d8
commit
9dd21bae97
3 changed files with 84 additions and 0 deletions
|
@ -14,6 +14,10 @@ if ENV['COVERAGE'] == 'true'
|
|||
end
|
||||
end
|
||||
|
||||
# Require warning support first in order to catch any warnings emitted during boot
|
||||
require_relative './support/warning'
|
||||
$stderr = MutantSpec::Warning::EXTRACTOR
|
||||
|
||||
require 'tempfile'
|
||||
require 'concord'
|
||||
require 'anima'
|
||||
|
@ -58,4 +62,9 @@ RSpec.configure do |config|
|
|||
config.include(MessageHelper)
|
||||
config.include(ParserHelper)
|
||||
config.include(Mutant::AST::Sexp)
|
||||
|
||||
config.after(:suite) do
|
||||
$stderr = STDERR
|
||||
MutantSpec::Warning.assert_no_warnings
|
||||
end
|
||||
end
|
||||
|
|
64
spec/support/warning.rb
Normal file
64
spec/support/warning.rb
Normal file
|
@ -0,0 +1,64 @@
|
|||
require 'yaml'
|
||||
require 'equalizer'
|
||||
require 'memoizable'
|
||||
require 'ice_nine'
|
||||
|
||||
module MutantSpec
|
||||
class Warning
|
||||
def self.assert_no_warnings
|
||||
return if EXTRACTOR.warnings.empty?
|
||||
|
||||
fail UnexpectedWarnings, EXTRACTOR.warnings.to_a
|
||||
end
|
||||
|
||||
class UnexpectedWarnings < StandardError
|
||||
MSG = 'Unexpected warnings: %s'.freeze
|
||||
|
||||
def initialize(warnings)
|
||||
super(MSG % warnings.join("\n"))
|
||||
end
|
||||
end
|
||||
|
||||
class Extractor < DelegateClass(IO)
|
||||
PATTERN = /\A(?:.+):(?:\d+): warning: (?:.+)\n\z/.freeze
|
||||
|
||||
include Equalizer.new(:whitelist, :seen, :io), Memoizable
|
||||
|
||||
def initialize(io, whitelist)
|
||||
@whitelist = whitelist
|
||||
@seen = Set.new
|
||||
@io = io
|
||||
|
||||
super(io)
|
||||
end
|
||||
|
||||
def write(message)
|
||||
return super if PATTERN !~ message
|
||||
|
||||
add(message.chomp)
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def warnings
|
||||
seen.dup
|
||||
end
|
||||
memoize :warnings
|
||||
|
||||
private
|
||||
|
||||
def add(warning)
|
||||
return if whitelist.any?(&warning.public_method(:end_with?))
|
||||
|
||||
seen << warning
|
||||
end
|
||||
|
||||
attr_reader :whitelist, :seen, :io
|
||||
end
|
||||
|
||||
warnings = Pathname.new(__dir__).join('warnings.yml').freeze
|
||||
whitelist = IceNine.deep_freeze(YAML.load(warnings.read))
|
||||
|
||||
EXTRACTOR = Extractor.new(STDERR, whitelist)
|
||||
end
|
||||
end
|
11
spec/support/warnings.yml
Normal file
11
spec/support/warnings.yml
Normal file
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
- 'lib/parser/lexer.rb:10791: warning: assigned but unused variable - testEof'
|
||||
- 'lib/parser/source/rewriter.rb:392: warning: assigned but unused variable - begin_pos'
|
||||
- 'lib/rspec/core/memoized_helpers.rb:288: warning: method redefined; discarding old output'
|
||||
- 'lib/rspec/core/memoized_helpers.rb:295: warning: method redefined; discarding old output'
|
||||
- 'lib/rspec/core/memoized_helpers.rb:295: warning: previous definition of config was here'
|
||||
- 'lib/rspec/core/memoized_helpers.rb:295: warning: previous definition of mutation_a_test_result was here'
|
||||
- 'lib/rspec/core/memoized_helpers.rb:295: warning: previous definition of output was here'
|
||||
- 'spec/support/shared_context.rb:35: warning: previous definition of output was here'
|
||||
- 'spec/support/shared_context.rb:4: warning: method redefined; discarding old config'
|
||||
- 'spec/support/shared_context.rb:4: warning: method redefined; discarding old mutation_a_test_result'
|
Loading…
Reference in a new issue