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

Fix DotFormatter failures count #530

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions spec/ameba/formatter/dot_formatter_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module Ameba::Formatter
output = IO::Memory.new
subject = DotFormatter.new output

before_each do
output.clear
end

describe "#started" do
it "writes started message" do
subject.started [Source.new ""]
Expand Down Expand Up @@ -51,7 +55,6 @@ module Ameba::Formatter
end

it "writes affected code by default" do
output.clear
s = Source.new(%(
a = 22
puts a
Expand All @@ -65,7 +68,6 @@ module Ameba::Formatter
end

it "writes severity" do
output.clear
s = Source.new(%(
a = 22
puts a
Expand All @@ -78,7 +80,6 @@ module Ameba::Formatter
end

it "doesn't write affected code if it is disabled" do
output.clear
s = Source.new(%(
a = 22
puts a
Expand All @@ -95,11 +96,14 @@ module Ameba::Formatter
end

it "does not write disabled issues" do
s = Source.new ""
s.add_issue(DummyRule.new, location: {1, 1},
message: "DummyRuleError", status: :disabled)
s = Source.new("").tap do |source|
source.add_issue(DummyRule.new, {1, 1}, "DummyRuleError", status: :disabled)
source.add_issue(NamedRule.new, {1, 2}, "NamedRuleError")
end
subject.finished [s]
output.to_s.should contain "1 inspected, 0 failures"
log = output.to_s
log.should_not contain "DummyRuleError"
log.should contain "1 inspected, 1 failure"
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/ameba/formatter/dot_formatter.cr
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ module Ameba::Formatter

private def final_message(sources, failed_sources)
total = sources.size
failures = failed_sources.sum(&.issues.size)
failures = failed_sources.sum(&.issues.count(&.enabled?))
color = failures == 0 ? :green : :red
s = failures != 1 ? "s" : ""

Expand Down
Loading