2
2
3
3
from test .tasktest import *
4
4
from wpiformat .includeguard import IncludeGuard
5
+ from wpiformat .task import Task
5
6
6
7
7
8
def test_includeguard ():
8
9
test = TaskTest (IncludeGuard ())
9
10
11
+ repo_root = os .path .basename (Task .get_repo_root ()).upper ()
12
+
10
13
# Fix incorrect include guard
11
14
test .add_input ("./Test.h" ,
12
15
"#ifndef WRONG_H" + os .linesep + \
13
16
"#define WRONG_C" + os .linesep + \
14
17
os .linesep + \
15
18
"#endif" + os .linesep )
16
19
test .add_output (
17
- "#ifndef STYLEGUIDE_TEST_H_ " + os .linesep + \
18
- "#define STYLEGUIDE_TEST_H_ " + os .linesep + \
20
+ "#ifndef " + repo_root + "_TEST_H_ " + os .linesep + \
21
+ "#define " + repo_root + "_TEST_H_ " + os .linesep + \
19
22
os .linesep + \
20
- "#endif // STYLEGUIDE_TEST_H_ " + os .linesep , True , True )
23
+ "#endif // " + repo_root + "_TEST_H_ " + os .linesep , True , True )
21
24
22
25
# Ensure nested preprocessor statements are handled properly for incorrect
23
26
# include guard
@@ -30,20 +33,20 @@ def test_includeguard():
30
33
"#endif" + os .linesep + \
31
34
"#endif" + os .linesep )
32
35
test .add_output (
33
- "#ifndef STYLEGUIDE_TEST_H_ " + os .linesep + \
34
- "#define STYLEGUIDE_TEST_H_ " + os .linesep + \
36
+ "#ifndef " + repo_root + "_TEST_H_ " + os .linesep + \
37
+ "#define " + repo_root + "_TEST_H_ " + os .linesep + \
35
38
os .linesep + \
36
39
"#if SOMETHING" + os .linesep + \
37
40
"// do something" + os .linesep + \
38
41
"#endif" + os .linesep + \
39
- "#endif // STYLEGUIDE_TEST_H_ " + os .linesep , True , True )
42
+ "#endif // " + repo_root + "_TEST_H_ " + os .linesep , True , True )
40
43
41
44
# Don't touch correct include guard
42
45
test .add_input ("./Test.h" ,
43
- "#ifndef STYLEGUIDE_TEST_H_ " + os .linesep + \
44
- "#define STYLEGUIDE_TEST_H_ " + os .linesep + \
46
+ "#ifndef " + repo_root + "_TEST_H_ " + os .linesep + \
47
+ "#define " + repo_root + "_TEST_H_ " + os .linesep + \
45
48
os .linesep + \
46
- "#endif // STYLEGUIDE_TEST_H_ " + os .linesep )
49
+ "#endif // " + repo_root + "_TEST_H_ " + os .linesep )
47
50
test .add_latest_input_as_output (True )
48
51
49
52
# Fail on missing include guard
@@ -56,27 +59,27 @@ def test_includeguard():
56
59
57
60
# Ensure include guard roots are processed correctly
58
61
test .add_input ("./Test.h" ,
59
- "#ifndef STYLEGUIDE_WPIFORMAT_TEST_H_ " + os .linesep + \
60
- "#define STYLEGUIDE_WPIFORMAT_TEST_H_ " + os .linesep + \
62
+ "#ifndef " + repo_root + "_WPIFORMAT_TEST_H_ " + os .linesep + \
63
+ "#define " + repo_root + "_WPIFORMAT_TEST_H_ " + os .linesep + \
61
64
os .linesep + \
62
- "#endif // STYLEGUIDE_WPIFORMAT_TEST_H_ " + os .linesep )
65
+ "#endif // " + repo_root + "_WPIFORMAT_TEST_H_ " + os .linesep )
63
66
test .add_output (
64
- "#ifndef STYLEGUIDE_TEST_H_ " + os .linesep + \
65
- "#define STYLEGUIDE_TEST_H_ " + os .linesep + \
67
+ "#ifndef " + repo_root + "_TEST_H_ " + os .linesep + \
68
+ "#define " + repo_root + "_TEST_H_ " + os .linesep + \
66
69
os .linesep + \
67
- "#endif // STYLEGUIDE_TEST_H_ " + os .linesep , True , True )
70
+ "#endif // " + repo_root + "_TEST_H_ " + os .linesep , True , True )
68
71
69
72
# Ensure leading underscores are removed (this occurs if the user doesn't
70
73
# include a trailing "/" in the include guard root)
71
74
test .add_input ("./Test/Test.h" ,
72
- "#ifndef STYLEGUIDE_WPIFORMAT_TEST_TEST_H_ " + os .linesep + \
73
- "#define STYLEGUIDE_WPIFORMAT_TEST_TEST_H_ " + os .linesep + \
75
+ "#ifndef " + repo_root + "_WPIFORMAT_TEST_TEST_H_ " + os .linesep + \
76
+ "#define " + repo_root + "_WPIFORMAT_TEST_TEST_H_ " + os .linesep + \
74
77
os .linesep + \
75
- "#endif // STYLEGUIDE_WPIFORMAT_TEST_TEST_H_ " + os .linesep )
78
+ "#endif // " + repo_root + "_WPIFORMAT_TEST_TEST_H_ " + os .linesep )
76
79
test .add_output (
77
- "#ifndef STYLEGUIDE_TEST_H_ " + os .linesep + \
78
- "#define STYLEGUIDE_TEST_H_ " + os .linesep + \
80
+ "#ifndef " + repo_root + "_TEST_H_ " + os .linesep + \
81
+ "#define " + repo_root + "_TEST_H_ " + os .linesep + \
79
82
os .linesep + \
80
- "#endif // STYLEGUIDE_TEST_H_ " + os .linesep , True , True )
83
+ "#endif // " + repo_root + "_TEST_H_ " + os .linesep , True , True )
81
84
82
85
test .run (OutputType .FILE )
0 commit comments