Skip to content

Commit 92623b1

Browse files
Anmol202005rdiachenko
authored andcommitted
Issue #41: Validate output files by re-running checkstyle
1 parent 9812d1c commit 92623b1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/test/java/org/checkstyle/autofix/recipe/AbstractRecipeTestSupport.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ protected void verify(String testCaseName) throws Exception {
5959
final String inputPath = testCaseName.toLowerCase() + "/" + inputFileName;
6060
final String outputPath = testCaseName.toLowerCase() + "/" + outputFileName;
6161

62+
verifyOutputFile(outputPath);
63+
6264
final Configuration config = getCheckConfigurations(inputPath);
6365
final List<CheckstyleViolation> violations = runCheckstyle(inputPath, config);
6466

@@ -93,6 +95,28 @@ private List<CheckstyleViolation> runCheckstyle(String inputPath,
9395
}
9496
}
9597

98+
private void verifyOutputFile(String outputPath) throws Exception {
99+
100+
final Configuration config = getCheckConfigurations(outputPath);
101+
final List<CheckstyleViolation> violations = runCheckstyle(outputPath, config);
102+
if (!violations.isEmpty()) {
103+
final StringBuilder violationMessage =
104+
new StringBuilder("Checkstyle violations found in the output file:\n");
105+
106+
violationMessage.append("outputFile: ").append(getPath(outputPath)).append("\n");
107+
108+
for (CheckstyleViolation violation : violations) {
109+
violationMessage
110+
.append("line: ").append(violation.getLine())
111+
.append(", col: ").append(violation.getColumn())
112+
.append(", message: ").append(violation.getMessage())
113+
.append("\n");
114+
}
115+
116+
throw new IllegalStateException(violationMessage.toString());
117+
}
118+
}
119+
96120
private Configuration getCheckConfigurations(String inputPath) throws Exception {
97121
final String configFilePath = getPath(inputPath);
98122
final TestInputConfiguration testInputConfiguration =

0 commit comments

Comments
 (0)