Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-dev-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-dev-tools
Commits
9b12dea2
Commit
9b12dea2
authored
10 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
update test for completeness check
parent
a231bff6
No related branches found
No related tags found
No related merge requests found
Pipeline
#4759
failed
6 years ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_source/check_style_c.py
+8
-8
8 additions, 8 deletions
check_source/check_style_c.py
tests/check_source/check_style_c_test.py
+159
-29
159 additions, 29 deletions
tests/check_source/check_style_c_test.py
with
167 additions
and
37 deletions
check_source/check_style_c.py
+
8
−
8
View file @
9b12dea2
...
...
@@ -193,6 +193,11 @@ def extract_to_linestart(index):
def
extract_statement_if
(
index_kw
):
# assert(tokens[index_kw].text == "if")
# ignore preprocessor
i_linestart
=
tk_advance_line_start
(
index_kw
)
if
tokens
[
i_linestart
].
text
.
startswith
(
"
#
"
):
return
None
# seek back
i
=
index_kw
...
...
@@ -203,11 +208,6 @@ def extract_statement_if(index_kw):
# print(tokens[i_next])
# ignore preprocessor
i_linestart
=
tk_advance_line_start
(
index_kw
)
if
tokens
[
i_linestart
].
text
.
startswith
(
"
#
"
):
return
None
if
tokens
[
i_next
].
type
!=
Token
.
Punctuation
or
tokens
[
i_next
].
text
!=
"
(
"
:
warning
(
"
E105
"
,
"
no
'
(
'
after
'
%s
'"
%
tokens
[
index_kw
].
text
,
i_start
,
i_next
)
return
None
...
...
@@ -734,14 +734,14 @@ def blender_check_operator(index_start, index_end, op_text, is_cpp):
elif
op_text
==
"
::~
"
:
pass
else
:
warning
(
"
E
138
"
,
"
unhandled operator 3
'
%s
'"
%
op_text
,
index_start
,
index_end
)
warning
(
"
E
000.1
"
,
"
unhandled operator 3
'
%s
'"
%
op_text
,
index_start
,
index_end
)
elif
len
(
op_text
)
==
4
:
if
op_text
==
"
*>::
"
:
pass
else
:
warning
(
"
E
139
"
,
"
unhandled operator 4
'
%s
'"
%
op_text
,
index_start
,
index_end
)
warning
(
"
E
000.2
"
,
"
unhandled operator 4
'
%s
'"
%
op_text
,
index_start
,
index_end
)
else
:
warning
(
"
E
140
"
,
"
unhandled operator (len > 4)
'
%s
'"
%
op_text
,
index_start
,
index_end
)
warning
(
"
E
000.3
"
,
"
unhandled operator (len > 4)
'
%s
'"
%
op_text
,
index_start
,
index_end
)
if
len
(
op_text
)
>
1
:
if
op_text
[
0
]
==
"
*
"
and
op_text
[
-
1
]
==
"
*
"
:
...
...
This diff is collapsed.
Click to expand it.
tests/check_source/check_style_c_test.py
+
159
−
29
View file @
9b12dea2
#!/usr/bin/env python3
# python3 -m unittest check_style_c_test.SourceCodeTest.test_whitespace_kw_indent
# ----
import
os
...
...
@@ -22,6 +23,9 @@ parser = check_style_c.create_parser()
args
=
parser
.
parse_args
([
"
.
"
])
# ----
# store errors we found
errors
=
set
()
FUNC_BEGIN
=
"""
void func(void)
{
...
...
@@ -33,12 +37,18 @@ FUNC_END = """
def
test_code
(
code
):
warnings
.
clear
()
check_style_c
.
scan_source
(
"
test.c
"
,
code
,
args
)
err_
ls
=
[
w
.
split
(
"
:
"
,
3
)[
2
].
strip
()
for
w
in
warnings
]
err_
found
=
[
w
.
split
(
"
:
"
,
3
)[
2
].
strip
()
for
w
in
warnings
]
# print(warnings)
return
err_
ls
return
err_
found
class
SourceCodeTest
(
unittest
.
TestCase
):
def
assertWarning
(
self
,
err_found
,
*
errors_test
):
err_set
=
set
(
err_found
)
errors
.
update
(
err_set
)
self
.
assertEqual
(
err_set
,
set
(
errors_test
))
def
test_brace_function
(
self
):
# --------------------------------------------------------------------
# brace on not on newline (function)
...
...
@@ -46,19 +56,36 @@ class SourceCodeTest(unittest.TestCase):
void func(void) {
\t
/* pass */
}
"""
err_ls
=
test_code
(
code
)
self
.
assertEqual
(
1
,
len
(
err_ls
))
self
.
assertEqual
(
"
E101
"
,
err_ls
[
0
])
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E101
"
)
code
=
"""
void func(void)
{
\t
/* pass */
}
"""
err_
ls
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_
ls
))
err_
found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_
found
))
def
test_brace_kw
(
self
):
def
test_brace_kw_whitespace
(
self
):
# --------------------------------------------------------------------
# brace has whitespace after it
code
=
FUNC_BEGIN
+
"""
\t
if (1){
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E107
"
,
"
E150
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (1) {
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_found
))
def
test_brace_kw_newline
(
self
):
# --------------------------------------------------------------------
# brace on on newline (if, for... )
...
...
@@ -67,16 +94,15 @@ void func(void)
\t
{
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_ls
=
test_code
(
code
)
self
.
assertEqual
(
1
,
len
(
err_ls
))
self
.
assertEqual
(
"
E108
"
,
err_ls
[
0
])
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E108
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (1) {
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_
ls
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_
ls
))
err_
found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_
found
))
def
test_brace_do_while
(
self
):
# --------------------------------------------------------------------
...
...
@@ -87,16 +113,15 @@ void func(void)
\t
{
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_ls
=
test_code
(
code
)
self
.
assertEqual
(
1
,
len
(
err_ls
))
self
.
assertEqual
(
"
E108
"
,
err_ls
[
0
])
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E108
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (1) {
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_
ls
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_
ls
))
err_
found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_
found
))
def
test_brace_kw_multiline
(
self
):
# --------------------------------------------------------------------
...
...
@@ -107,10 +132,8 @@ void func(void)
\t
b) {
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_ls
=
test_code
(
code
)
self
.
assertEqual
(
2
,
len
(
err_ls
))
self
.
assertEqual
(
"
E103
"
,
err_ls
[
0
])
self
.
assertEqual
(
"
E104
"
,
err_ls
[
1
])
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E103
"
,
"
E104
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (a &&
...
...
@@ -119,8 +142,8 @@ void func(void)
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_
ls
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_
ls
))
err_
found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_
found
))
def
test_brace_indent
(
self
):
# --------------------------------------------------------------------
...
...
@@ -129,16 +152,123 @@ void func(void)
\t
if (1) {
\t\t
/* pass */
\t\t
}
"""
+
FUNC_END
err_ls
=
test_code
(
code
)
self
.
assertEqual
(
1
,
len
(
err_ls
))
self
.
assertEqual
(
"
E104
"
,
err_ls
[
0
])
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E104
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (1) {
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_found
))
def
test_whitespace_kw_no_parens
(
self
):
# --------------------------------------------------------------------
# if MACRO {}
code
=
FUNC_BEGIN
+
"""
\t
if MACRO {
\t\t
/* pass */
\t\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E104
"
,
"
E105
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (1) {
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_found
))
def
test_whitespace_kw_missing
(
self
):
# --------------------------------------------------------------------
code
=
FUNC_BEGIN
+
"""
\t
if(1) {
\t\t
/* pass */
\t\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E104
"
,
"
E106
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (1) {
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_ls
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_ls
))
err_found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_found
))
def
test_brace_kw_newline_missing
(
self
):
# --------------------------------------------------------------------
code
=
FUNC_BEGIN
+
"""
\t
if (1 &&
\t
1) fn();
\t
else {}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E103
"
,
"
E109
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (1 &&
\t
1)
\t
{
\t\t
fn();
\t
}
\t
else {}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_found
))
def
test_whitespace_kw_indent
(
self
):
# --------------------------------------------------------------------
code
=
FUNC_BEGIN
+
"""
\t
if (a &&
\t\t\t
b &&
\t
c)
\t
{
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertWarning
(
err_found
,
"
E110
"
)
code
=
FUNC_BEGIN
+
"""
\t
if (a &&
\t
b &&
\t
c)
\t
{
\t\t
/* pass */
\t
}
"""
+
FUNC_END
err_found
=
test_code
(
code
)
self
.
assertEqual
(
0
,
len
(
err_found
))
class
SourceCodeTestComplete
(
unittest
.
TestCase
):
"""
Check we ran all tests.
"""
def
test_complete
(
self
):
# --------------------------------------------------------------------
# Check we test all errors
errors_uniq
=
set
()
with
open
(
check_style_c
.
__file__
,
'
r
'
,
encoding
=
'
utf-8
'
)
as
fh
:
import
re
# E100
err_re_main
=
re
.
compile
(
r
'
.*\(
"
(E\d+)
"'
)
# E100.0
err_re_subv
=
re
.
compile
(
r
'
.*\(
"
(E\d+)\.\d+
"'
)
# --> E100
err_re_subv_group
=
re
.
compile
(
r
'
.*\(
"
(E\d+\.\d+)
"'
)
# --> E100.0
for
l
in
fh
:
g
=
err_re_subv
.
match
(
l
)
if
g
is
None
:
g
=
err_re_main
.
match
(
l
)
is_sub
=
False
else
:
is_sub
=
True
if
g
:
err
=
g
.
group
(
1
)
self
.
assertIn
(
err
,
errors
)
# ----
# now check we didn't use multiple times
if
is_sub
:
err
=
err_re_subv_group
.
match
(
l
).
group
(
1
)
self
.
assertNotIn
(
err
,
errors_uniq
)
errors_uniq
.
add
(
err
)
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment