Search in sources :

Example 1 with GeneratorResult

use of org.lflang.generator.GeneratorResult in project lingua-franca by lf-lang.

the class TestBase method generateCode.

/**
 * Invoke the code generator for the given test.
 * @param test The test to generate code for.
 */
private GeneratorResult generateCode(LFTest test) {
    GeneratorResult result = GeneratorResult.NOTHING;
    if (test.fileConfig.resource != null) {
        generator.doGenerate(test.fileConfig.resource, fileAccess, test.context);
        result = test.context.getResult();
        if (generator.errorsOccurred()) {
            test.result = Result.CODE_GEN_FAIL;
            throw new AssertionError("Code generation unsuccessful.");
        }
    }
    return result;
}
Also used : GeneratorResult(org.lflang.generator.GeneratorResult)

Example 2 with GeneratorResult

use of org.lflang.generator.GeneratorResult in project lingua-franca by lf-lang.

the class TestBase method validateAndRun.

/**
 * Validate and run the given tests, using the specified configuratator and level.
 *
 * While performing tests, this method prints a header that reaches completion
 * once all tests have been run.
 *
 * @param tests A set of tests to run.
 * @param configurator A procedure for configuring the tests.
 * @param level The level of testing.
 * @throws IOException If initial file configuration fails
 */
private void validateAndRun(Set<LFTest> tests, Configurator configurator, TestLevel level) throws IOException {
    final var x = 78f / tests.size();
    var marks = 0;
    var done = 0;
    for (var test : tests) {
        try {
            redirectOutputs(test);
            var context = configure(test, configurator, level);
            validate(test, context);
            GeneratorResult result = GeneratorResult.NOTHING;
            if (level.compareTo(TestLevel.CODE_GEN) >= 0) {
                result = generateCode(test);
            }
            if (level == TestLevel.EXECUTION) {
                execute(test, result);
            } else if (test.result == Result.UNKNOWN) {
                test.result = Result.TEST_PASS;
            }
        } catch (AssertionError e) {
        // Do not report assertion errors. They are pretty printed
        // during reporting.
        } catch (Exception e) {
            test.issues.append(e.getMessage());
        } finally {
            restoreOutputs();
        }
        done++;
        while (Math.floor(done * x) >= marks && marks < 78) {
            System.out.print("=");
            marks++;
        }
    }
    while (marks < 78) {
        System.out.print("=");
        marks++;
    }
    System.out.print(System.lineSeparator());
}
Also used : GeneratorResult(org.lflang.generator.GeneratorResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) RuntimeIOException(org.eclipse.xtext.util.RuntimeIOException) IOException(java.io.IOException)

Example 3 with GeneratorResult

use of org.lflang.generator.GeneratorResult in project lingua-franca by lf-lang.

the class LFLanguageServerExtension method buildWithProgress.

/**
 * Describes a build process that has a progress.
 */
private GeneratorResult buildWithProgress(LanguageClient client, String uri, boolean mustComplete) {
    URI parsedUri;
    try {
        parsedUri = URI.createFileURI(new java.net.URI(uri).getPath());
    } catch (java.net.URISyntaxException e) {
        // This error will appear as a silent failure to most users, but that is acceptable because this error
        // should be impossible. The URI is not the result of user input -- the language client provides it --
        // so it should be valid.
        System.err.println(e);
        return GeneratorResult.NOTHING;
    }
    Progress progress = new Progress(client, "Build \"" + parsedUri.lastSegment() + "\"", mustComplete);
    progress.begin();
    GeneratorResult result = null;
    try {
        result = builder.run(parsedUri, mustComplete, progress::report, progress.getCancelIndicator());
    } finally {
        progress.end(result == null ? "An internal error occurred." : result.getUserMessage());
    }
    return result;
}
Also used : GeneratorResult(org.lflang.generator.GeneratorResult) URI(org.eclipse.emf.common.util.URI)

Example 4 with GeneratorResult

use of org.lflang.generator.GeneratorResult in project lingua-franca by lf-lang.

the class LspTests method buildAndRunTest.

/**
 * Test the "Build and Run" functionality of the language server.
 */
private void buildAndRunTest(Target target) {
    MockLanguageClient client = new MockLanguageClient();
    LanguageServerErrorReporter.setClient(client);
    for (LFTest test : selectTests(target)) {
        MockReportProgress reportProgress = new MockReportProgress();
        GeneratorResult result = runTest(test.srcFile, true);
        if (NOT_SUPPORTED.or(MISSING_DEPENDENCY).test(client.getReceivedDiagnostics())) {
            System.err.println("WARNING: Skipping \"Build and Run\" test due to lack of support or a missing " + "requirement.");
        } else {
            Assertions.assertFalse(reportProgress.failed());
            Assertions.assertEquals(Status.COMPILED, result.getStatus());
            Assertions.assertNotNull(result.getCommand());
            Assertions.assertEquals(result.getCommand().run(), 0);
        }
    }
}
Also used : GeneratorResult(org.lflang.generator.GeneratorResult) LFTest(org.lflang.tests.LFTest)

Example 5 with GeneratorResult

use of org.lflang.generator.GeneratorResult in project lingua-franca by lf-lang.

the class LspTests method runTest.

/**
 * Run the given test.
 * @param test An integration test.
 * @param mustComplete Whether the build must be complete.
 * @return The result of running the test.
 */
private GeneratorResult runTest(Path test, boolean mustComplete) {
    MockReportProgress reportProgress = new MockReportProgress();
    GeneratorResult result = builder.run(URI.createFileURI(test.toString()), mustComplete, reportProgress, () -> false);
    Assertions.assertFalse(reportProgress.failed());
    return result;
}
Also used : GeneratorResult(org.lflang.generator.GeneratorResult)

Aggregations

GeneratorResult (org.lflang.generator.GeneratorResult)5 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (org.eclipse.emf.common.util.URI)1 RuntimeIOException (org.eclipse.xtext.util.RuntimeIOException)1 LFTest (org.lflang.tests.LFTest)1