Search in sources :

Example 1 with CliTools

use of org.eclipse.n4js.cli.helper.CliTools 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 2 with CliTools

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

the class NodeVersionTest method testNodeVersion.

/**
 */
@Test
public void testNodeVersion() {
    Path cwd = new File("").toPath().toAbsolutePath();
    ProcessResult result = new CliTools().nodejsRun(cwd, Path.of("-v"));
    Assert.assertEquals("bad exit code", 0, result.getExitCode());
    String versionStr = result.getStdOut().trim();
    if (!N4JSGlobals.isCompatibleNodeVersion(versionStr)) {
        Assert.fail("tests are running with node version " + versionStr + " but this version is not compatible to version v" + N4JSGlobals.NODE_VERSION + " defined in " + N4JSGlobals.class.getSimpleName());
    }
}
Also used : Path(java.nio.file.Path) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) CliTools(org.eclipse.n4js.cli.helper.CliTools) File(java.io.File) Test(org.junit.Test)

Example 3 with CliTools

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

the class ConvertedIdeTest method runMangelhaft.

/**
 * Executes mangelhaft for the given output file. The {@code outputFilePath} should be a relative path from the
 * project's root folder.
 */
protected String runMangelhaft(String projectName, Optional<String> outputFilePath, boolean quiet) {
    File workingDir = getProjectRootForImportedProject(projectName);
    List<String> args = new ArrayList<>();
    if (quiet) {
        args.add("-q");
    }
    if (outputFilePath.isPresent()) {
        args.add("-f");
        args.add("/" + outputFilePath.get() + "/");
    }
    ProcessResult result = new CliTools().nodejsRun(workingDir.toPath(), Path.of("../../node_modules/n4js-mangelhaft-cli/src-gen/org/eclipse/n4js/mangelhaft/runner/node/NodeTestMain.js"), args.toArray(String[]::new));
    String output = result.getStdOut();
    output = output.replaceAll("\\e\\[\\d+m", "");
    return output;
}
Also used : ArrayList(java.util.ArrayList) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) CliTools(org.eclipse.n4js.cli.helper.CliTools) File(java.io.File)

Example 4 with CliTools

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

the class XpectN4JSES5TranspilerHelper method doExecute.

private String doExecute(Path workingDir, Path fileToRun, boolean decorateStdStreams, String... options) {
    ProcessResult processResult = new CliTools().nodejsRun(workingDir, fileToRun, options);
    StringBuffer output = new StringBuffer();
    output.append(processResult.getStdOut().trim());
    String errOut = processResult.getErrOut().trim();
    if (!errOut.isEmpty()) {
        if (decorateStdStreams) {
            output.append("=== stderr ===");
        }
        output.append(errOut);
    }
    return output.toString();
}
Also used : ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) CliTools(org.eclipse.n4js.cli.helper.CliTools)

Example 5 with CliTools

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

the class BuildN4jsLibs method bundleN4jsRuntime.

private static void bundleN4jsRuntime(Path n4jsLibsRootPath) {
    CliTools cliTools = new CliTools();
    cliTools.setInheritIO(true);
    cliTools.yarnRun(n4jsLibsRootPath, "workspace", "n4js-runtime", "run", "bundle");
}
Also used : CliTools(org.eclipse.n4js.cli.helper.CliTools)

Aggregations

CliTools (org.eclipse.n4js.cli.helper.CliTools)9 ProcessResult (org.eclipse.n4js.cli.helper.ProcessResult)5 File (java.io.File)3 Path (java.nio.file.Path)3 CliException (org.eclipse.n4js.cli.helper.CliTools.CliException)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 N4jscTestOptions (org.eclipse.n4js.cli.N4jscTestOptions)1 CliCompileResult (org.eclipse.n4js.cli.helper.CliCompileResult)1 Project (org.eclipse.n4js.tests.codegen.Project)1 FileURI (org.eclipse.n4js.workspace.locations.FileURI)1 Xpect (org.eclipse.xpect.runner.Xpect)1