-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathRULE_7_2_B_do_not_use_goto_statement.py
72 lines (58 loc) · 1.45 KB
/
RULE_7_2_B_do_not_use_goto_statement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
Do not use goto statements.
if it's shown... this rule reports a violation.
== Violation ==
void FunctionA()
{
while(True)
{
goto AAA; <== Violation. A goto statement is used.
}
AAA:
}
== Good ==
void FunctionA()
{
while(True)
{
break; <== OK.
}
}
"""
from nsiqcppstyle_reporter import *
from nsiqcppstyle_rulehelper import *
from nsiqcppstyle_rulemanager import *
from nsiqunittest.nsiqcppstyle_unittestbase import *
def RunRule(lexer, contextStack):
t = lexer.GetCurToken()
if t.type == "GOTO":
nsiqcppstyle_reporter.Error(t, __name__, "Do not use goto keyword")
ruleManager.AddFunctionScopeRule(RunRule)
ruleManager.AddPreprocessRule(RunRule)
##########################################################################
# Unit Test
##########################################################################
class testRule(nct):
def setUpRule(self):
ruleManager.AddFunctionScopeRule(RunRule)
ruleManager.AddPreprocessRule(RunRule)
def test1(self):
self.Analyze(
"thisfile.c",
"""
void Hello() {
goto TT:
}
""",
)
self.ExpectError(__name__)
def test2(self):
self.Analyze(
"thisfile.c",
"""
goto TT:
void Hello() {
}
""",
)
self.ExpectSuccess(__name__)