in testsuite/jflex-testsuite-maven-plugin/src/main/java/jflex/maven/plugin/testsuite/TestCase.java [161:264]
void createScanner(File jflexUberJar, boolean verbose)
throws TestFailException, MojoFailureException {
File lexFile = new File(testPath, testName + ".flex");
if (verbose) {
System.out.println(String.format("Open lex specification [%s]", lexFile));
}
if (!lexFile.exists()) {
throw new MojoFailureException(
"Cannot open lex definition", new FileNotFoundException(lexFile.getPath()));
}
jflexFiles.add(lexFile.getPath());
// invoke JFlex
TestResult jflexResult = ExecUtils.execJFlex(jflexCmdln, jflexFiles);
// System.out.println(jflexResult);
if (jflexResult.getSuccess()) {
// Scanner generation successful
if (TestsuiteUtils.verbose) {
System.out.println("Scanner generation successful");
}
if (expectJFlexFail) {
System.out.println("JFlex failure expected!");
throw new TestFailException();
}
// check JFlex output conformance
File expected = new File(testPath, testName + "-flex.output");
if (expected.exists()) {
DiffStream check = new DiffStream();
String diff;
try {
diff =
check.diff(
jflexDiff, new StringReader(jflexResult.getOutput()), new FileReader(expected));
} catch (FileNotFoundException e) {
System.out.println("Error opening file " + expected);
throw new TestFailException();
}
if (diff != null) {
System.out.println("Test failed, unexpected jflex output: " + diff);
System.out.println("JFlex output: " + jflexResult.getOutput());
throw new TestFailException();
}
} else {
System.out.println("Warning: no file for expected output [" + expected + "]");
}
// Compile Scanner
final List<String> toCompile = getFilesToCompile();
if (TestsuiteUtils.verbose) {
System.out.println("File(s) to compile: " + toCompile);
}
try {
TestResult javacResult =
ExecUtils.execJavac(toCompile, testPath, jflexUberJar.getAbsolutePath(), javacEncoding);
// System.out.println(javacResult);
if (TestsuiteUtils.verbose) {
System.out.println(
"Compilation successful: "
+ javacResult.getSuccess()
+ " [expected: "
+ !expectJavacFail
+ "]");
}
if (javacResult.getSuccess() == expectJavacFail) {
throw new TestFailException(
"Compilation failed in " + testPath + " for " + toCompile,
new Exception(javacResult.getOutput()));
}
} catch (FileNotFoundException e) {
throw new TestFailException("javac: file not found: ", e);
}
} else {
if (!expectJFlexFail) {
System.out.println("Scanner generation failed!");
System.out.println("JFlex output was:\n" + jflexResult.getOutput());
throw new TestFailException();
} else {
// check JFlex output conformance
File expected = new File(testPath, testName + "-flex.output");
if (expected.exists()) {
DiffStream check = new DiffStream();
String diff;
try {
diff =
check.diff(
jflexDiff, new StringReader(jflexResult.getOutput()), new FileReader(expected));
} catch (FileNotFoundException e) {
System.out.println("Error opening file " + expected);
throw new TestFailException();
}
if (diff != null) {
System.out.println("Test failed, unexpected jflex output: " + diff);
System.out.println("JFlex output: " + jflexResult.getOutput());
throw new TestFailException();
}
}
}
}
}