Search in sources :

Example 21 with CliCompileResult

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

the class N4jscInitTest method yarnHelloWorld.

/**
 * test yarn hello world
 */
@Test
public void yarnHelloWorld() throws Exception {
    N4jscTestOptions options = INIT().setWorkingDirectory(cwd.toPath()).workspaces().answers(",,,,,,yes");
    n4jsc(options, SUCCESS);
    yarnInstall(cwd.toPath());
    CliCompileResult result = n4jsc(IMPLICIT_COMPILE(cwd).setWorkingDirectory(cwd.toPath()), SUCCESS);
    assertEquals(1, result.getTranspiledFilesCount());
    ProcessResult resultNodejs = nodejsRun(cwd.toPath(), Path.of("packages/my-project"));
    assertEquals("Hello World", resultNodejs.getStdOut());
}
Also used : CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) N4jscTestOptions(org.eclipse.n4js.cli.N4jscTestOptions) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 22 with CliCompileResult

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

the class N4jscInitTest method failDueToExistingPackagejson.

/**
 * fail due to existing package.json file
 */
@Test
public void failDueToExistingPackagejson() throws Exception {
    File packjson = new File(cwd.getAbsoluteFile(), PACKAGE_JSON);
    packjson.createNewFile();
    N4jscTestOptions options = INIT().setWorkingDirectory(cwd.toPath()).yes();
    CliCompileResult result = n4jsc(options, INIT_ERROR_WORKING_DIR);
    assertEquals("ERROR-410 (Error: Unsupported working directory):  Current working directory must not contain a package.json file. Note:\n" + "  In case you like to add the n4js property to an existing project, use option --n4js.\n" + "  In case you like to add a project to an existing workspace project, use options -w -c.", result.getStdOut());
}
Also used : CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) N4jscTestOptions(org.eclipse.n4js.cli.N4jscTestOptions) File(java.io.File) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 23 with CliCompileResult

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

the class N4jscInitTest method yarnWrongLocation1ScopeCreate.

/**
 * test yarn at wrong location
 */
@Test
public void yarnWrongLocation1ScopeCreate() throws Exception {
    // create environment
    N4jscTestOptions options = INIT().setWorkingDirectory(cwd.toPath()).yes().workspaces();
    n4jsc(options, SUCCESS);
    assertEquals("TestInit\n" + "- package.json\n" + "+ packages\n" + "  + my-project\n" + "    - package.json\n" + "    + src\n" + "    + src-gen\n" + "", FileUtils.serializeFileTree(cwd));
    // test
    File newProject = new File(cwd, "packages");
    options = INIT().yes().setWorkingDirectory(newProject.toPath()).scope().create();
    CliCompileResult result = n4jsc(options, INIT_ERROR_WORKING_DIR);
    assertEquals("ERROR-410 (Error: Unsupported working directory):  " + "Creating a new project inside an existing yarn project requires option '--workspaces' to be set.", result.getStdOut());
}
Also used : CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) N4jscTestOptions(org.eclipse.n4js.cli.N4jscTestOptions) File(java.io.File) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 24 with CliCompileResult

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

the class N4jscInitTest method mainModule1Compile.

/**
 * test for a custom main module
 */
@Test
public void mainModule1Compile() throws Exception {
    String answers = ",,index.js";
    N4jscTestOptions options = INIT().setWorkingDirectory(cwd.toPath()).answers(answers);
    n4jsc(options, SUCCESS);
    String packagejsonContents = Files.readString(cwd.toPath().resolve(PACKAGE_JSON));
    assertEquals("{\n" + "  \"name\": \"TestInit\",\n" + "  \"version\": \"0.0.1\",\n" + "  \"type\": \"module\",\n" + "  \"main\": \"src-gen/index.js\",\n" + "  \"scripts\": {\n" + "    \"n4jsc\": \"n4jsc\",\n" + "    \"build\": \"n4jsc compile . --clean || true\"\n" + "  },\n" + "  \"dependencies\": {\n" + "    \"n4js-runtime\": \"\",\n" + "    \"n4js-runtime-es2015\": \"\"\n" + "  },\n" + "  \"devDependencies\": {\n" + "    \"n4js-cli\": \"\"\n" + "  },\n" + "  \"n4js\": {\n" + "    \"projectType\": \"library\",\n" + "    \"mainModule\": \"index\",\n" + "    \"output\": \"src-gen\",\n" + "    \"sources\": {\n" + "      \"source\": [\n" + "        \"src\"\n" + "      ]\n" + "    },\n" + "    \"requiredRuntimeLibraries\": [\n" + "      \"n4js-runtime-es2015\"\n" + "    ]\n" + "  }\n" + "}", packagejsonContents);
    assertEquals("TestInit\n" + "- package.json\n" + "+ src\n" + "  - index.n4js\n" + "+ src-gen\n" + "", FileUtils.serializeFileTree(cwd));
    npmInstall(cwd.toPath());
    CliCompileResult result = n4jsc(IMPLICIT_COMPILE(cwd).setWorkingDirectory(cwd.toPath()), SUCCESS);
    assertEquals(1, result.getTranspiledFilesCount());
}
Also used : CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) N4jscTestOptions(org.eclipse.n4js.cli.N4jscTestOptions) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 25 with CliCompileResult

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

the class FrontendCompileTest method checkNoTestsWrongGoal.

/**
 */
@Test
public void checkNoTestsWrongGoal() {
    String[] args = { "lsp", ".", "--noTests" };
    CliCompileResult result = n4jsc(args, 10);
    assertEquals(result.toString(), "ERROR-10 (Invalid command line string):  No argument is allowed: .", result.getStdOut());
}
Also used : CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) Test(org.junit.Test)

Aggregations

CliCompileResult (org.eclipse.n4js.cli.helper.CliCompileResult)92 Test (org.junit.Test)90 AbstractCliCompileTest (org.eclipse.n4js.cli.helper.AbstractCliCompileTest)41 N4jscTestOptions (org.eclipse.n4js.cli.N4jscTestOptions)22 File (java.io.File)20 Path (java.nio.file.Path)12 ProcessResult (org.eclipse.n4js.cli.helper.ProcessResult)12 N4jscOptions (org.eclipse.n4js.cli.N4jscOptions)8 AbstractCliJarTest (org.eclipse.n4js.cli.helper.AbstractCliJarTest)6 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 CliTools (org.eclipse.n4js.cli.helper.CliTools)1 CliException (org.eclipse.n4js.cli.helper.CliTools.CliException)1 Ignore (org.junit.Ignore)1