Skip to content

Commit fbabcda

Browse files
committed
Issue #41: Validate output files by re-running checkstyle
1 parent a2d69a9 commit fbabcda

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
@@ -62,6 +62,8 @@ protected void verify(String testCaseName) throws Exception {
6262
final String inputPath = testCaseName.toLowerCase() + "/" + inputFileName;
6363
final String outputPath = testCaseName.toLowerCase() + "/" + outputFileName;
6464

65+
verifyOutputFile(outputPath);
66+
6567
final Configuration config = getCheckConfigurations(inputPath);
6668
final List<CheckstyleViolation> violations = runCheckstyle(inputPath, config);
6769

@@ -95,6 +97,28 @@ private List<CheckstyleViolation> runCheckstyle(String inputPath,
9597
}
9698
}
9799

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

0 commit comments

Comments
 (0)