-
Notifications
You must be signed in to change notification settings - Fork 550
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
Add -Werror
flag to turn Ruby warnings into errors
#995
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,10 @@ def self.run args = [] | |
Minitest.seed = options[:seed] | ||
srand Minitest.seed | ||
|
||
if options[:error_on_warning] | ||
require "minitest/error_on_warning" | ||
end | ||
|
||
reporter = CompositeReporter.new | ||
reporter << SummaryReporter.new(options[:io], options) | ||
reporter << ProgressReporter.new(options[:io], options) unless options[:quiet] | ||
|
@@ -253,6 +257,19 @@ def self.process_args args = [] # :nodoc: | |
options[:skip] = s.chars.to_a | ||
end | ||
|
||
opts.on "-Werror", String, "Turn Ruby warnings into errors" do |s| | ||
case s | ||
when "error" | ||
options[:error_on_warning] = true | ||
$VERBOSE = true | ||
::Warning[:deprecated] if ::Warning.respond_to?(:[]=) # Ruby 2.7+ | ||
else | ||
if ::Warning.respond_to?(:[]=) # Ruby 2.7+ | ||
::Warning[s.to_sym] = true | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unfamiliar enough with Warning that I don't understand this side of the top branch... I can see that you're setting that category to true, but I don't see it doing anything? Clue me? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warnings that have a category ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Part of my confusion was that minitest/test_task always runs -w by default so Warning[:deprecated] was always true. |
||
end | ||
end | ||
|
||
unless extensions.empty? | ||
opts.separator "" | ||
opts.separator "Known extensions: #{extensions.join(", ")}" | ||
|
@@ -995,6 +1012,15 @@ def result_label # :nodoc: | |
end | ||
end | ||
|
||
## | ||
# Assertion raised on warning when running in -Werror mode. | ||
|
||
class UnexpectedWarning < Assertion | ||
def result_label # :nodoc: | ||
"Warning" | ||
end | ||
end | ||
|
||
## | ||
# Assertion wrapping an unexpected error that was raised during a run. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Minitest | ||
|
||
module ErrorOnWarning | ||
def warn(message, category: nil) | ||
message = "[#{category}] #{message}" if category | ||
raise UnexpectedWarning, message | ||
end | ||
end | ||
|
||
::Warning.singleton_class.prepend(ErrorOnWarning) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.