Search in sources :

Example 1 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class AbstractIdeTest method assertOutput.

/**
 * Runs the given file (with its parent folder as working directory) in node.js and asserts the output.
 */
protected void assertOutput(FileURI fileToRun, CharSequence expectedOutput) {
    ProcessResult result = runInNodejs(fileToRun);
    assertNull("exception while running: " + fileToRun, result.getException());
    assertEquals("unexpected exit code from running: " + fileToRun, 0, result.getExitCode());
    assertEquals("unexpected output from running: " + fileToRun, expectedOutput.toString().trim(), result.getStdOut().trim());
    assertEquals("stderr was non-empty after running: " + fileToRun, "", result.getErrOut().trim());
}
Also used : ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult)

Example 2 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class XtIdeTest method ensureTSC.

private void ensureTSC(CliTools cliTools) {
    if (TSC_PROVIDER.isDirectory() && TSC2.isFile()) {
        return;
    }
    if (TSC_PROVIDER.exists()) {
        TSC_PROVIDER.delete();
    }
    TSC_PROVIDER.mkdirs();
    // npm install --prefix . typescript@4.3.2
    ProcessResult result = cliTools.npmRun(TSC_PROVIDER.toPath(), "install", "--prefix", ".", "typescript@4.3.2");
    assertEquals(0, result.getExitCode());
}
Also used : ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult)

Example 3 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class XtIdeTest method generated_dts.

/**
 * Compares the content of the generated .d.ts file with the expectation string.
 *
 * <pre>
 * // XPECT generated_dts ---
 * &lt;EXPECTED CONTENT OF GENERATED D.TS FILE&gt;
 * // ---
 * </pre>
 */
@Xpect
public void generated_dts(XtMethodData data) throws IOException {
    String moduleName = xtData.workspace.moduleNameOfXtFile;
    int idxStart = Math.max(moduleName.lastIndexOf("/") + 1, 0);
    int idxEnd = moduleName.lastIndexOf(".");
    String genDtsFileName = moduleName.substring(idxStart, idxEnd) + ".d.ts";
    try {
        FileURI genDtsFileURI = getFileURIFromModuleName(genDtsFileName);
        String genDtsCode = Files.readString(genDtsFileURI.toPath());
        assertTrue(genDtsCode.startsWith(OUTPUT_FILE_PREAMBLE));
        String genDtsCodeTrimmedPreamble = genDtsCode.substring(OUTPUT_FILE_PREAMBLE.length()).trim();
        assertTrue(genDtsCodeTrimmedPreamble.startsWith(IMPORT_N4JSGLOBALS));
        String genDtsCodeTrimmed = genDtsCodeTrimmedPreamble.substring(IMPORT_N4JSGLOBALS.length()).trim();
        assertEquals(data.getUnescapeExpectationRaw(), genDtsCodeTrimmed);
        CliTools cliTools = new CliTools();
        ensureTSC(cliTools);
        List<Project> allProjectsWithGenerateDts = FluentIterable.from(xtData.workspace.getAllProjects()).filter(Project::isGenerateDts).toList();
        assertFalse("no projects found with .d.ts generation turned on", allProjectsWithGenerateDts.isEmpty());
        for (Project project : allProjectsWithGenerateDts) {
            File workingDir = getProjectRoot(project.getName());
            // copy n4jsglobals.d.ts to output dir to make d.ts globals available
            Path n4jsGlobalsDTS = N4jsLibsAccess.getN4JSGlobalsDTS();
            Files.copy(n4jsGlobalsDTS, workingDir.toPath().resolve("src-gen/n4jsglobals.d.ts"));
            ProcessResult result;
            try {
                result = cliTools.nodejsRun(workingDir.toPath(), TSC2.getAbsoluteFile().toPath());
            } catch (CliException e) {
                throw new AssertionError("error while running tsc in working directory: " + workingDir, e);
            }
            assertFalse("TypeScript Error: " + result.getStdOut(), result.getStdOut().contains(": error "));
        }
    } catch (IllegalStateException e) {
        throw new RuntimeException("Could not find file " + genDtsFileName + "\nDid you set: " + XtSetupParser.GENERATE_DTS + " in SETUP section?", e);
    }
}
Also used : Path(java.nio.file.Path) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) CliTools(org.eclipse.n4js.cli.helper.CliTools) Project(org.eclipse.n4js.tests.codegen.Project) FileURI(org.eclipse.n4js.workspace.locations.FileURI) CliException(org.eclipse.n4js.cli.helper.CliTools.CliException) File(java.io.File) Xpect(org.eclipse.xpect.runner.Xpect)

Example 4 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class AT_IDEBUG_695_CannotSetFinalFieldInCtorForStaticPolyfillsTest method compileCheckFinalFieldCanBeSetInInheritedCtor_ExpectCanBeSet.

/**
 */
@Test
public void compileCheckFinalFieldCanBeSetInInheritedCtor_ExpectCanBeSet() {
    Path projectDir = workspace.toPath().resolve(WS_IDEBUG_695);
    Path fileToRun = projectDir.resolve("src-gen/Main.js");
    N4jscOptions options = COMPILE(workspace);
    CliCompileResult cliResult = n4jsc(options, VALIDATION_ERRORS);
    assertEquals(cliResult.toString(), 2, cliResult.getTranspiledFilesCount());
    ProcessResult nodejsResult = nodejsRun(projectDir, fileToRun);
    assertEquals(nodejsResult.toString(), "A.a == 5: true", nodejsResult.getStdOut());
}
Also used : Path(java.nio.file.Path) CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) N4jscOptions(org.eclipse.n4js.cli.N4jscOptions) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 5 with ProcessResult

use of org.eclipse.n4js.cli.helper.ProcessResult in project n4js by eclipse.

the class IncompleteApiImplementationTest method testInterfaces_static_setter_missing.

/**
 */
@Test
public void testInterfaces_static_setter_missing() {
    String expectedString = "Loaded Implementation one.x.impl::p.A.n4js";
    String fileToRunName = fileToExecute_direct("Exec_AT_IDE-1510_Interfaces_static_setter_missing.js");
    ProcessResult nodejsResult = nodejsRun(workspace.toPath(), Path.of(fileToRunName));
    assertEquals(nodejsResult.toString(), expectedString, nodejsResult.getStdOut());
}
Also used : ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Aggregations

ProcessResult (org.eclipse.n4js.cli.helper.ProcessResult)64 Test (org.junit.Test)59 AbstractCliCompileTest (org.eclipse.n4js.cli.helper.AbstractCliCompileTest)55 Path (java.nio.file.Path)13 CliCompileResult (org.eclipse.n4js.cli.helper.CliCompileResult)12 Ignore (org.junit.Ignore)9 CliTools (org.eclipse.n4js.cli.helper.CliTools)5 N4jscOptions (org.eclipse.n4js.cli.N4jscOptions)4 N4jscTestOptions (org.eclipse.n4js.cli.N4jscTestOptions)4 File (java.io.File)3 AbstractCliJarTest (org.eclipse.n4js.cli.helper.AbstractCliJarTest)2 ArrayList (java.util.ArrayList)1 CliException (org.eclipse.n4js.cli.helper.CliTools.CliException)1 Project (org.eclipse.n4js.tests.codegen.Project)1 FileURI (org.eclipse.n4js.workspace.locations.FileURI)1 Xpect (org.eclipse.xpect.runner.Xpect)1