Search in sources :

Example 1 with DtsParseResult

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);
    }
}
Also used : Path(java.nio.file.Path) DtsParseResult(org.eclipse.n4js.dts.DtsParseResult) FileURI(org.eclipse.n4js.workspace.locations.FileURI) Files(java.nio.file.Files) Stopwatch(com.google.common.base.Stopwatch) GitUtils.hardReset(org.eclipse.n4js.tests.helper.git.GitUtils.hardReset) IOException(java.io.IOException) Test(org.junit.Test) FileInputStream(java.io.FileInputStream) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) DtsParser(org.eclipse.n4js.dts.DtsParser) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) N4JSResource(org.eclipse.n4js.resource.N4JSResource) StandardSystemProperty(com.google.common.base.StandardSystemProperty) FileVisitOption(java.nio.file.FileVisitOption) BufferedReader(java.io.BufferedReader) Assert(org.junit.Assert) Path(java.nio.file.Path) Collections(java.util.Collections) InputStreamReader(java.io.InputStreamReader) DtsParseResult(org.eclipse.n4js.dts.DtsParseResult) Stopwatch(com.google.common.base.Stopwatch) FileInputStream(java.io.FileInputStream) DtsParser(org.eclipse.n4js.dts.DtsParser) FileURI(org.eclipse.n4js.workspace.locations.FileURI) BufferedReader(java.io.BufferedReader) N4JSResource(org.eclipse.n4js.resource.N4JSResource)

Aggregations

StandardSystemProperty (com.google.common.base.StandardSystemProperty)1 Stopwatch (com.google.common.base.Stopwatch)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 FileVisitOption (java.nio.file.FileVisitOption)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Collections (java.util.Collections)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 DtsParseResult (org.eclipse.n4js.dts.DtsParseResult)1 DtsParser (org.eclipse.n4js.dts.DtsParser)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 GitUtils.hardReset (org.eclipse.n4js.tests.helper.git.GitUtils.hardReset)1 FileURI (org.eclipse.n4js.workspace.locations.FileURI)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1