2017-11-06 08:38:17 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
|
|
|
module Ameba::Formatter
|
|
|
|
describe DotFormatter do
|
|
|
|
output = IO::Memory.new
|
|
|
|
subject = DotFormatter.new output
|
|
|
|
|
|
|
|
describe "#started" do
|
|
|
|
it "writes started message" do
|
|
|
|
subject.started [Source.new ""]
|
2021-01-26 06:38:19 +00:00
|
|
|
output.to_s.should eq "Inspecting 1 file\n\n"
|
2017-11-06 08:38:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#source_finished" do
|
|
|
|
it "writes valid source" do
|
|
|
|
subject.source_finished Source.new ""
|
|
|
|
output.to_s.should contain "."
|
|
|
|
end
|
|
|
|
|
|
|
|
it "writes invalid source" do
|
|
|
|
s = Source.new ""
|
2018-06-10 21:15:12 +00:00
|
|
|
s.add_issue DummyRule.new, Crystal::Nop.new, "message"
|
2017-11-06 08:38:17 +00:00
|
|
|
subject.source_finished s
|
|
|
|
output.to_s.should contain "F"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#finished" do
|
|
|
|
it "writes a final message" do
|
|
|
|
subject.finished [Source.new ""]
|
2021-01-26 06:38:19 +00:00
|
|
|
output.to_s.should contain "1 inspected, 0 failures"
|
2017-11-06 08:38:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "writes the elapsed time" do
|
|
|
|
subject.finished [Source.new ""]
|
|
|
|
output.to_s.should contain "Finished in"
|
|
|
|
end
|
2018-01-29 22:25:36 +00:00
|
|
|
|
2018-06-10 21:15:12 +00:00
|
|
|
context "when issues found" do
|
|
|
|
it "writes each issue" do
|
2018-05-28 08:48:07 +00:00
|
|
|
s = Source.new("").tap do |source|
|
2018-06-10 21:15:12 +00:00
|
|
|
source.add_issue(DummyRule.new, {1, 1}, "DummyRuleError")
|
|
|
|
source.add_issue(NamedRule.new, {1, 2}, "NamedRuleError")
|
2018-01-29 22:25:36 +00:00
|
|
|
end
|
|
|
|
subject.finished [s]
|
|
|
|
log = output.to_s
|
2021-01-26 06:38:19 +00:00
|
|
|
log.should contain "1 inspected, 2 failures"
|
2018-01-29 22:25:36 +00:00
|
|
|
log.should contain "DummyRuleError"
|
|
|
|
log.should contain "NamedRuleError"
|
|
|
|
end
|
|
|
|
|
2018-12-12 19:45:00 +00:00
|
|
|
it "writes affected code by default" do
|
|
|
|
output.clear
|
|
|
|
s = Source.new(%(
|
|
|
|
a = 22
|
|
|
|
puts a
|
|
|
|
)).tap do |source|
|
|
|
|
source.add_issue(DummyRule.new, {1, 5}, "DummyRuleError")
|
|
|
|
end
|
|
|
|
subject.finished [s]
|
|
|
|
log = output.to_s
|
2021-01-26 06:38:19 +00:00
|
|
|
log.should contain "> \e[97ma = 22"
|
2018-12-12 19:45:00 +00:00
|
|
|
log.should contain " \e[33m^\e[0m"
|
|
|
|
end
|
|
|
|
|
2019-04-14 13:45:31 +00:00
|
|
|
it "writes severity" do
|
|
|
|
output.clear
|
|
|
|
s = Source.new(%(
|
|
|
|
a = 22
|
|
|
|
puts a
|
|
|
|
)).tap do |source|
|
|
|
|
source.add_issue(DummyRule.new, {1, 5}, "DummyRuleError")
|
|
|
|
end
|
|
|
|
subject.finished [s]
|
|
|
|
log = output.to_s
|
2019-05-11 18:17:18 +00:00
|
|
|
log.should contain "[C]"
|
2019-04-14 13:45:31 +00:00
|
|
|
end
|
|
|
|
|
2018-12-12 19:45:00 +00:00
|
|
|
it "doesn't write affected code if it is disabled" do
|
|
|
|
output.clear
|
|
|
|
s = Source.new(%(
|
|
|
|
a = 22
|
|
|
|
puts a
|
|
|
|
)).tap do |source|
|
|
|
|
source.add_issue(DummyRule.new, {1, 5}, "DummyRuleError")
|
|
|
|
end
|
|
|
|
|
|
|
|
formatter = DotFormatter.new output
|
|
|
|
formatter.config[:without_affected_code] = true
|
|
|
|
formatter.finished [s]
|
|
|
|
log = output.to_s
|
|
|
|
log.should_not contain "> a = 22"
|
|
|
|
log.should_not contain " \e[33m^\e[0m"
|
|
|
|
end
|
|
|
|
|
2018-06-10 21:15:12 +00:00
|
|
|
it "does not write disabled issues" do
|
2018-01-29 22:25:36 +00:00
|
|
|
s = Source.new ""
|
2018-06-10 21:15:12 +00:00
|
|
|
s.add_issue(DummyRule.new, location: {1, 1},
|
|
|
|
message: "DummyRuleError", status: :disabled)
|
2018-01-29 22:25:36 +00:00
|
|
|
subject.finished [s]
|
2021-01-26 06:38:19 +00:00
|
|
|
output.to_s.should contain "1 inspected, 0 failures"
|
2018-01-29 22:25:36 +00:00
|
|
|
end
|
|
|
|
end
|
2017-11-06 08:38:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|