-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathRULE_8_1_A_provide_file_info_comment.py
160 lines (133 loc) · 3.33 KB
/
RULE_8_1_A_provide_file_info_comment.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
"""
Provide file comment.
File comment including 'copyright' should be provided in the head of file.
This rule detect following style file comment.
== Violation ==
= start of file =
#define "AA" <== Violation. file comment should be the first element of file.
///
/// blar blar
/// Copyright reserved.
///
= start of file =
/** <== Violation. No copyright string.
* blar blar
* blar blar
*/
== Good ==
= start of file =
///
/// blar blar
/// Copyright reserved. <== Correct
/// file
/// author
/// date
/// version
/// brief
///
= start of file =
/**
* blar blar
* Copyright reserved. <== Correct
* file
* author
* date
* version
* brief
* blar blar
*/
"""
from nsiqcppstyle_reporter import *
from nsiqcppstyle_rulehelper import *
from nsiqcppstyle_rulemanager import *
from nsiqunittest.nsiqcppstyle_unittestbase import *
def error(lexer):
nsiqcppstyle_reporter.Error(
DummyToken(lexer.filename, "", 1, 0),
__name__,
"""Please provide file info comment in front of
file. It includes license/copyright information along
with filename, author, date of modification, version and
a brief description""",
)
def RunRule(lexer, filename, dirname):
token = lexer.GetNextToken()
while True:
if token is None or token.type not in ("COMMENT", "CPPCOMMENT"):
error(lexer)
return
if token.value.lower().find("copyright") != -1 or token.value.lower().find("license") != -1:
return
token = lexer.GetNextTokenSkipWhiteSpace()
ruleManager.AddFileStartRule(RunRule)
##########################################################################
# Unit Test
##########################################################################
class testRule(nct):
def setUpRule(self):
ruleManager.AddFileStartRule(RunRule)
def test1(self):
self.Analyze(
"thisfile.c",
"""// license
// copyright
""",
)
self.ExpectSuccess(__name__)
def test2(self):
self.Analyze(
"thisfile.c",
"""/**
#if 0
#endif
license
coryright */ """,
)
self.ExpectSuccess(__name__)
def test3(self):
self.Analyze(
"thisfile.c",
"""
// license
// copyrigh1
""",
)
self.ExpectError(__name__)
def test4(self):
self.Analyze(
"thisfile.c",
"""#define "WEWE"
// license
// copyrigh1
#include </ewe/kk> """,
)
self.ExpectError(__name__)
def test5(self):
self.Analyze(
"thisfile.c",
"""
#define "WEWE"
// license
// copyright
#include </ewe/kk> """,
)
self.ExpectError(__name__)
def test6(self):
self.Analyze(
"thisfile.c",
"""// license
// copyright
#define "WEWE"
#include </ewe/kk> """,
)
self.ExpectSuccess(__name__)
def test7(self):
self.Analyze(
"thisfile.c",
"""/*
* license
* copyright
*/
""",
)
self.ExpectSuccess(__name__)