Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

* fixed all warnings. tests are running in verbose mode now. #685

Merged
merged 3 commits into from May 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -37,6 +37,5 @@ matrix:
- rvm: rbx-2
- script: ./ci/run_rubocop_specs
before_install:
- gem install bundler -v '< 2'
- bundle --version
- gem --version
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -11,7 +11,7 @@ task :default => [:test]
Rake::TestTask.new do |t|
t.libs = %w(test/ lib/)
t.test_files = FileList["test/**/test_*.rb"]
t.warning = false
t.warning = true
end

task :test_cov do
Expand Down
2 changes: 1 addition & 1 deletion lib/parser/diagnostic.rb
Expand Up @@ -67,7 +67,7 @@ def initialize(level, reason, arguments, location, highlights=[])
# @return [String] the rendered message.
#
def message
MESSAGES[@reason] % @arguments
Messages.format(@reason, @arguments)
end

##
Expand Down
7 changes: 7 additions & 0 deletions lib/parser/lexer.rl
Expand Up @@ -283,6 +283,13 @@ class Parser::Lexer
%% write exec;
# %

# Ragel creates a local variable called `testEof` but it doesn't use
# it any assignment. This dead code is here to swallow the warning.
# It has no runtime cost because Ruby doesn't produce any instructions from it.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Until ruby starts warning about if false as a redundant construct ;)

if false
testEof
end

@p = p

if @token_queue.any?
Expand Down
15 changes: 15 additions & 0 deletions lib/parser/messages.rb
Expand Up @@ -93,4 +93,19 @@ module Parser
:crossing_insertions => 'the rewriting action on:',
:crossing_insertions_conflict => 'is crossing that on:',
}.freeze

# @api private
module Messages
# Formats the message, returns a raw template if there's nothing to interpolate
#
# Code like `"" % {}` gives a warning, and so this method tries interpolating
# only if `arguments` hash is not empty.
#
# @api private
def self.format(reason, arguments)
template = MESSAGES[reason]
return template if Hash === arguments && arguments.empty?
template % arguments
iliabylich marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
2 changes: 1 addition & 1 deletion lib/parser/source/tree_rewriter.rb
Expand Up @@ -221,7 +221,7 @@ def insert_after(range, content)
#
# @return [String]
#
def process
def process
source = @source_buffer.source

chunks = []
Expand Down
2 changes: 1 addition & 1 deletion parser.gemspec
Expand Up @@ -45,7 +45,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'ast', '~> 2.4.0'

spec.add_development_dependency 'bundler', '>= 1.15', '< 3.0.0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rake', '~> 13.0.1'
spec.add_development_dependency 'racc', '= 1.4.15'
spec.add_development_dependency 'cliver', '~> 0.3.2'

Expand Down
8 changes: 3 additions & 5 deletions test/helper.rb
@@ -1,8 +1,6 @@
# frozen_string_literal: true

require 'tempfile'
require 'minitest/test'

require 'simplecov'

if ENV.include?('COVERAGE') && SimpleCov.usable?
Expand All @@ -28,9 +26,9 @@
at_exit { RaccCoverage.stop }

SimpleCov.start do
self.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
]
self.formatter = SimpleCov::Formatter::MultiFormatter.new(
SimpleCov::Formatter::HTMLFormatter
)

add_group 'Grammars' do |source_file|
source_file.filename =~ %r{\.y$}
Expand Down
10 changes: 4 additions & 6 deletions test/parse_helper.rb
Expand Up @@ -106,8 +106,7 @@ def try_parsing(ast, code, parser, source_maps, version)
assert_equal ast, parsed_ast,
"(#{version}) AST equality"

parse_source_map_descriptions(source_maps) \
do |begin_pos, end_pos, map_field, ast_path, line|
parse_source_map_descriptions(source_maps) do |begin_pos, end_pos, map_field, ast_path, line|

astlet = traverse_ast(parsed_ast, ast_path)

Expand Down Expand Up @@ -160,15 +159,14 @@ def assert_diagnoses(diagnostic, code, source_maps='', versions=ALL_VERSIONS)

level, reason, arguments = diagnostic
arguments ||= {}
message = Parser::MESSAGES[reason] % arguments
message = Parser::Messages.format(reason, arguments)

assert_equal level, emitted_diagnostic.level
assert_equal reason, emitted_diagnostic.reason
assert_equal arguments, emitted_diagnostic.arguments
assert_equal message, emitted_diagnostic.message

parse_source_map_descriptions(source_maps) \
do |begin_pos, end_pos, map_field, ast_path, line|
parse_source_map_descriptions(source_maps) do |begin_pos, end_pos, map_field, ast_path, line|

case map_field
when 'location'
Expand Down Expand Up @@ -216,7 +214,7 @@ def assert_diagnoses_many(diagnostics, code, versions=ALL_VERSIONS)
diagnostics.zip(@diagnostics) do |expected_diagnostic, actual_diagnostic|
level, reason, arguments = expected_diagnostic
arguments ||= {}
message = Parser::MESSAGES[reason] % arguments
message = Parser::Messages.format(reason, arguments)

assert_equal level, actual_diagnostic.level
assert_equal reason, actual_diagnostic.reason
Expand Down
2 changes: 1 addition & 1 deletion test/test_diagnostic.rb
Expand Up @@ -16,7 +16,7 @@ def test_verifies_levels
Parser::Diagnostic.new(:foobar, :escape_eof, {}, @range1)
end

assert_match /level/, error.message
assert_match(/level/, error.message)
end

def test_freezes
Expand Down
13 changes: 5 additions & 8 deletions test/test_diagnostic_engine.rb
Expand Up @@ -4,17 +4,14 @@

class TestDiagnosticEngine < Minitest::Test
def setup
@buffer = Parser::Source::Buffer.new('(source)')
@buffer.source = 'foobar'

@engine = Parser::Diagnostic::Engine.new

@queue = []
@engine.consumer = lambda { |diag| @queue << diag }
end

def test_process_warnings
warn = Parser::Diagnostic.new(:warning, :invalid_escape, @buffer, 1..2)
warn = Parser::Diagnostic.new(:warning, :invalid_escape, {}, 1..2)
@engine.process(warn)

assert_equal [warn], @queue
Expand All @@ -23,7 +20,7 @@ def test_process_warnings
def test_ignore_warnings
@engine.ignore_warnings = true

warn = Parser::Diagnostic.new(:warning, :invalid_escape, @buffer, 1..2)
warn = Parser::Diagnostic.new(:warning, :invalid_escape, {}, 1..2)
@engine.process(warn)

assert_equal [], @queue
Expand All @@ -32,7 +29,7 @@ def test_ignore_warnings
def test_all_errors_are_fatal
@engine.all_errors_are_fatal = true

error = Parser::Diagnostic.new(:error, :invalid_escape, @buffer, 1..2)
error = Parser::Diagnostic.new(:error, :invalid_escape, {}, 1..2)

err = assert_raises Parser::SyntaxError do
@engine.process(error)
Expand All @@ -44,14 +41,14 @@ def test_all_errors_are_fatal
end

def test_all_errors_are_collected
error = Parser::Diagnostic.new(:error, :invalid_escape, @buffer, 1..2)
error = Parser::Diagnostic.new(:error, :invalid_escape, {}, 1..2)
@engine.process(error)

assert_equal [error], @queue
end

def test_fatal_error
fatal = Parser::Diagnostic.new(:fatal, :invalid_escape, @buffer, 1..2)
fatal = Parser::Diagnostic.new(:fatal, :invalid_escape, {}, 1..2)

assert_raises Parser::SyntaxError do
@engine.process(fatal)
Expand Down
2 changes: 1 addition & 1 deletion test/test_lexer.rb
Expand Up @@ -3606,7 +3606,7 @@ def assert_scanned_numbered_parameter(input)

def refute_scanned_numbered_parameter(input, message = nil)
err = assert_raises Parser::SyntaxError do
lex_token, (lex_value, lex_range) = lex_numbered_parameter(input)
_lex_token, (_lex_value, _lex_range) = lex_numbered_parameter(input)
end

if message
Expand Down
2 changes: 1 addition & 1 deletion test/test_parser.rb
Expand Up @@ -9238,7 +9238,7 @@ def assert_pattern_matching_defines_local_variables(match_code, lvar_names, vers
before = parser.static_env.instance_variable_get(:@variables).to_a

begin
parsed_ast = parser.parse(source_file)
_parsed_ast = parser.parse(source_file)
rescue Parser::SyntaxError => exc
backtrace = exc.backtrace
Exception.instance_method(:initialize).bind(exc).
Expand Down
2 changes: 1 addition & 1 deletion test/test_runner_parse.rb
Expand Up @@ -7,7 +7,7 @@ class TestRunnerParse < Minitest::Test
PATH_TO_RUBY_PARSE = File.expand_path('../bin/ruby-parse', __dir__).freeze

def assert_prints(argv, expected_output)
stdout, stderr, status = Open3.capture3(PATH_TO_RUBY_PARSE, *argv)
stdout, _stderr, status = Open3.capture3(PATH_TO_RUBY_PARSE, *argv)

assert_equal 0, status.to_i
assert_includes(stdout, expected_output)
Expand Down
2 changes: 1 addition & 1 deletion test/test_runner_rewrite.rb
Expand Up @@ -21,7 +21,7 @@ def assert_rewriter_output(path, args, input: 'input.rb', output: 'output.rb', e
expected_file = @fixtures_dir + output

FileUtils.cp(@fixtures_dir + input, sample_file_expanded)
stdout, stderr, exit_code = Dir.chdir @test_dir do
stdout, stderr, _exit_code = Dir.chdir @test_dir do
Open3.capture3 %Q{
#{Shellwords.escape(@ruby_rewrite.to_s)} #{args} \
#{Shellwords.escape(sample_file_expanded.to_s)}
Expand Down
2 changes: 1 addition & 1 deletion test/test_source_buffer.rb
Expand Up @@ -45,7 +45,7 @@ def test_source_setter_encoding_error
].join("\n")
end

assert_match /invalid byte sequence in UTF\-8/, error.message
assert_match(/invalid byte sequence in UTF\-8/, error.message)
end

def test_read
Expand Down
30 changes: 15 additions & 15 deletions test/test_source_comment_associator.rb
Expand Up @@ -95,7 +95,7 @@ def bar
end
END

klass_node = ast
_klass_node = ast
method_node = ast.children[2]
body = method_node.children[2]
f1_1_node = body.children[0]
Expand Down Expand Up @@ -175,7 +175,7 @@ def bar
end
END

klass_node = ast
_klass_node = ast
method_node = ast.children[2]
body = method_node.children[2]
f1_1_node = body.children[0]
Expand All @@ -201,12 +201,12 @@ class Foo
end

def test_associate_empty_tree
ast, associations = associate("")
_ast, associations = associate("")
assert_equal 0, associations.size
end

def test_associate_shebang_only
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
#!ruby
class Foo
end
Expand All @@ -216,7 +216,7 @@ class Foo
end

def test_associate_frozen_string_literal
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# frozen_string_literal: true
class Foo
end
Expand All @@ -226,7 +226,7 @@ class Foo
end

def test_associate_frozen_string_literal_dash_star_dash
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# -*- frozen_string_literal: true -*-
class Foo
end
Expand All @@ -236,7 +236,7 @@ class Foo
end

def test_associate_frozen_string_literal_no_space_after_colon
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# frozen_string_literal:true
class Foo
end
Expand All @@ -246,7 +246,7 @@ class Foo
end

def test_associate_warn_indent
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# warn_indent: true
class Foo
end
Expand All @@ -256,7 +256,7 @@ class Foo
end

def test_associate_warn_indent_dash_star_dash
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# -*- warn_indent: true -*-
class Foo
end
Expand All @@ -266,7 +266,7 @@ class Foo
end

def test_associate_warn_past_scope
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# warn_past_scope: true
class Foo
end
Expand All @@ -276,7 +276,7 @@ class Foo
end

def test_associate_warn_past_scope_dash_star_dash
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# -*- warn_past_scope: true -*-
class Foo
end
Expand All @@ -286,7 +286,7 @@ class Foo
end

def test_associate_multiple
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# frozen_string_literal: true; warn_indent: true
class Foo
end
Expand All @@ -296,7 +296,7 @@ class Foo
end

def test_associate_multiple_dash_star_dash
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
# -*- frozen_string_literal: true; warn_indent: true -*-
class Foo
end
Expand All @@ -306,7 +306,7 @@ class Foo
end

def test_associate_no_comments
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
class Foo
end
END
Expand All @@ -315,7 +315,7 @@ class Foo
end

def test_associate_comments_after_root_node
ast, associations = associate(<<-END)
_ast, associations = associate(<<-END)
class Foo
end
# not associated
Expand Down
14 changes: 7 additions & 7 deletions test/test_source_range.rb
Expand Up @@ -95,15 +95,15 @@ def test_containment

def test_order
assert_equal 0, @sr1_3 <=> @sr1_3
assert_equal -1, @sr1_3 <=> @sr5_8
assert_equal -1, @sr2_2 <=> @sr2_6
assert_equal +1, @sr2_6 <=> @sr2_2
assert_equal(-1, @sr1_3 <=> @sr5_8)
assert_equal(-1, @sr2_2 <=> @sr2_6)
assert_equal(+1, @sr2_6 <=> @sr2_2)

assert_equal -1, @sr1_3 <=> @sr2_6
assert_equal(-1, @sr1_3 <=> @sr2_6)

assert_equal +1, @sr2_2 <=> @sr1_3
assert_equal -1, @sr1_3 <=> @sr2_2
assert_equal -1, @sr5_7 <=> @sr5_8
assert_equal(+1, @sr2_2 <=> @sr1_3)
assert_equal(-1, @sr1_3 <=> @sr2_2)
assert_equal(-1, @sr5_7 <=> @sr5_8)

assert_nil @sr1_3 <=> Parser::Source::Range.new(@buf.dup, 1, 3)
assert_nil @sr1_3 <=> 4
Expand Down