use of org.eclipse.n4js.dts.DtsParseResult in project n4js by eclipse.
the class DtsParsesDefinitelyTypedTest method assertParseCounts.
static void assertParseCounts(Path repoRoot, int minPass, int maxFail, int maxError) throws IOException {
Path typesFolder = repoRoot.resolve("types");
List<Path> files = Files.walk(typesFolder, FileVisitOption.FOLLOW_LINKS).filter(file -> {
if (!file.toString().endsWith(".d.ts")) {
return false;
}
String relPath = typesFolder.relativize(file).toString();
for (String exclude : EXCLUDES) {
if (exclude != null && !exclude.isBlank() && relPath.startsWith(exclude)) {
return false;
}
}
return true;
}).collect(Collectors.toList());
Collections.sort(files, (p1, p2) -> p1.toString().compareTo(p2.toString()));
int filesCount = files.size();
int pass = 0;
int fail = 0;
int error = 0;
System.out.println("Processing " + filesCount + " files ...");
Stopwatch sw = Stopwatch.createStarted();
for (Path file : files) {
try (BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream(file.toFile())))) {
N4JSResource resource = new N4JSResource();
resource.setURI(new FileURI(file).toURI());
DtsParseResult parseResult = new DtsParser().parse(buf, resource);
if (parseResult.hasSyntaxErrors()) {
fail++;
} else {
pass++;
}
} catch (Throwable e) {
e.printStackTrace();
if (e instanceof Error) {
throw e;
}
error++;
}
}
System.out.println("Done processing " + filesCount + " files in " + sw.elapsed(TimeUnit.SECONDS) + "s");
System.out.println(" passed: " + pass + " (" + percent(pass, filesCount) + ")");
System.out.println(" failed: " + fail + " (" + percent(fail, filesCount) + ")");
System.out.println(" errors: " + error + " (" + percent(error, filesCount) + ")");
if (error > maxError) {
Assert.fail("More errors detected than expected: " + error);
}
if (fail > maxFail) {
Assert.fail("More failures detected than expected: " + fail);
}
if (pass < minPass) {
Assert.fail("Less passes detected than expected: " + pass);
}
}
Aggregations