Skip to content

Commit dedf47f

Browse files
committed
Refactor temporary test directory creation
Now the includeorder, includeguard, and config tests use a temporary directory with their own .styleguide files instead of using the wpiformat .styleguide file. This allowed massively simplifying wpiformat's .styleguide file.
1 parent 6694a03 commit dedf47f

File tree

8 files changed

+287
-229
lines changed

8 files changed

+287
-229
lines changed

.styleguide

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
1-
cppHeaderFileInclude {
2-
\.h$
3-
\.hpp$
4-
\.inc$
5-
}
6-
7-
cppSrcFileInclude {
8-
\.cpp$
9-
}
10-
11-
# Extra "/" used by unit tests
121
generatedFileExclude {
13-
/cpplint\.py$
2+
cpplint\.py$
143
}
154

165
modifiableFileExclude {
176
\.png$
187
}
19-
20-
licenseUpdateExclude {
21-
Excluded\.h$
22-
}
23-
24-
# Ordered this way to ensure tests find longest match
25-
includeGuardRoots {
26-
wpiformat/
27-
wpiformat/Test/
28-
}
29-
30-
# Used by unit tests
31-
includeProject {
32-
^ctre/
33-
}

.styleguide-license

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
/*{padding}Company Name{padding}*/
2-
/* Copyright (c) {year} Company Name. All Rights Reserved.{padding}*/
1+
// Copyright (c) {year} FIRST

wpiformat/wpiformat/test/test_cidentlist.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22

33
from .test_tasktest import *
4+
from .test_tempdir import *
45
from wpiformat.cidentlist import CIdentList
56

67

@@ -494,4 +495,18 @@ def test_cidentlist():
494495
True,
495496
)
496497

497-
test.run(OutputType.FILE)
498+
with OpenTemporaryDirectory():
499+
with open(".styleguide", "w") as file:
500+
file.write(
501+
r"""cppHeaderFileInclude {
502+
\.h$
503+
\.hpp$
504+
\.inc$
505+
}
506+
507+
includeProject {
508+
^ctre/
509+
}
510+
"""
511+
)
512+
test.run(OutputType.FILE)
Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,45 @@
1-
import os
2-
1+
from .tempdir import *
32
from wpiformat.config import Config
43

54

65
def test_config():
7-
config_file = Config(os.path.abspath(os.getcwd()), ".styleguide")
8-
assert config_file.is_modifiable_file(
9-
"." + os.sep + "wpiformat" + os.sep + "javaguidelink.png"
10-
)
11-
assert config_file.is_generated_file(
12-
"." + os.sep + "wpiformat" + os.sep + "wpiformat" + os.sep + "cpplint.py"
13-
)
6+
with OpenTemporaryDirectory():
7+
with open(".styleguide", "w") as file:
8+
file.write(
9+
r"""cppHeaderFileInclude {
10+
\.h$
11+
\.inc$
12+
}
13+
14+
cppSrcFileInclude {
15+
\.cpp$
16+
}
17+
18+
# Extra "/" used by unit tests
19+
generatedFileExclude {
20+
/cpplint\.py$
21+
}
22+
23+
modifiableFileExclude {
24+
\.png$
25+
}
26+
"""
27+
)
28+
29+
config_file = Config(os.path.abspath(os.getcwd()), ".styleguide")
30+
assert config_file.is_modifiable_file(
31+
"." + os.sep + "wpiformat" + os.sep + "javaguidelink.png"
32+
)
33+
assert config_file.is_generated_file(
34+
"." + os.sep + "wpiformat" + os.sep + "wpiformat" + os.sep + "cpplint.py"
35+
)
1436

15-
assert not config_file.is_generated_file(
16-
"." + os.sep + "wpiformat" + os.sep + "diff_cpplint.py"
17-
)
18-
assert not config_file.is_generated_file(
19-
"." + os.sep + "wpiformat" + os.sep + "update_cpplint.py"
20-
)
21-
assert not config_file.is_modifiable_file(
22-
"." + os.sep + "wpiformat" + os.sep + "license.txt"
23-
)
37+
assert not config_file.is_generated_file(
38+
"." + os.sep + "wpiformat" + os.sep + "diff_cpplint.py"
39+
)
40+
assert not config_file.is_generated_file(
41+
"." + os.sep + "wpiformat" + os.sep + "update_cpplint.py"
42+
)
43+
assert not config_file.is_modifiable_file(
44+
"." + os.sep + "wpiformat" + os.sep + "license.txt"
45+
)

0 commit comments

Comments
 (0)