2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-11-01 12:42:58 +00:00
|
|
|
|
2018-06-16 11:50:59 +00:00
|
|
|
module Ameba::Rule::Lint
|
2017-11-01 12:42:58 +00:00
|
|
|
subject = DebuggerStatement.new
|
|
|
|
|
|
|
|
describe DebuggerStatement do
|
|
|
|
it "passes if there is no debugger statement" do
|
2021-10-22 17:54:39 +00:00
|
|
|
expect_no_issues subject, %(
|
2017-11-01 12:42:58 +00:00
|
|
|
"this is not a debugger statement"
|
|
|
|
s = "debugger"
|
|
|
|
|
|
|
|
def debugger(program)
|
|
|
|
end
|
|
|
|
debugger ""
|
|
|
|
|
|
|
|
class A
|
|
|
|
def debugger
|
|
|
|
end
|
|
|
|
end
|
|
|
|
A.new.debugger
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if there is a debugger statement" do
|
2021-10-22 17:54:39 +00:00
|
|
|
expect_issue subject, %(
|
2017-11-01 12:42:58 +00:00
|
|
|
a = 2
|
|
|
|
debugger
|
2021-10-22 17:54:39 +00:00
|
|
|
# ^{} error: Possible forgotten debugger statement detected
|
2017-11-01 12:42:58 +00:00
|
|
|
a = a + 1
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, pos and message" do
|
2017-11-07 20:02:51 +00:00
|
|
|
s = Source.new "debugger", "source.cr"
|
2017-11-01 20:05:41 +00:00
|
|
|
subject.catch(s).should_not be_valid
|
2017-11-01 12:42:58 +00:00
|
|
|
|
2018-06-10 21:15:12 +00:00
|
|
|
issue = s.issues.first
|
|
|
|
issue.rule.should_not be_nil
|
|
|
|
issue.location.to_s.should eq "source.cr:1:1"
|
2018-11-24 17:38:13 +00:00
|
|
|
issue.end_location.to_s.should eq "source.cr:1:8"
|
2018-06-10 21:15:12 +00:00
|
|
|
issue.message.should eq "Possible forgotten debugger statement detected"
|
2017-11-01 12:42:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|