Search in sources :

Example 11 with CliCompileResult

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

the class N4jscBasicTest method testCompileP1_And_Run_A_WithNodeRunner.

/**
 * Basic compile and run test.
 */
@Test
public void testCompileP1_And_Run_A_WithNodeRunner() throws Exception {
    CliCompileResult cliResult = n4jsc(COMPILE(workspace), SUCCESS);
    assertEquals(cliResult.toString(), 20, cliResult.getTranspiledFilesCount());
    Path fileA = proot.toPath().resolve("P1/src-gen/A.js");
    ProcessResult nodejsResult = nodejsRun(workspace.toPath(), fileA);
    assertEquals(nodejsResult.toString(), "A", nodejsResult.getStdOut());
}
Also used : Path(java.nio.file.Path) CliCompileResult(org.eclipse.n4js.cli.helper.CliCompileResult) ProcessResult(org.eclipse.n4js.cli.helper.ProcessResult) Test(org.junit.Test) AbstractCliCompileTest(org.eclipse.n4js.cli.helper.AbstractCliCompileTest)

Example 12 with CliCompileResult

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

the class N4jscBasicTest method testFileRegeneratedIfMapRemoved.

/**
 * Test a second run of the compiler after a generated js file was removed
 */
@Test
public void testFileRegeneratedIfMapRemoved() throws Exception {
    N4jscTestOptions compileOptions = COMPILE(DONT_CLEAN, workspace);
    CliCompileResult firstRun = n4jsc(compileOptions, SUCCESS);
    assertEquals(firstRun.toString(), 20, firstRun.getTranspiledFilesCount());
    File fileAmap = proot.toPath().resolve("P1/src-gen/A.map").toFile();
    assertTrue(fileAmap.getAbsolutePath(), fileAmap.isFile());
    assertTrue(fileAmap.getAbsolutePath(), fileAmap.exists());
    assertTrue(fileAmap.getAbsolutePath(), fileAmap.delete());
    assertFalse(fileAmap.getAbsolutePath(), fileAmap.exists());
    CliCompileResult secondRun = n4jsc(compileOptions, SUCCESS);
    assertEquals(secondRun.toString(), 1, secondRun.getTranspiledFilesCount());
    assertEquals(secondRun.toString(), 0, secondRun.getDeletedFilesCount());
    assertTrue(fileAmap.exists());
    File fileAjs = proot.toPath().resolve("P1/src-gen/A.js").toFile();
    assertTrue(fileAjs.exists());
    assertOutputEqual(firstRun, secondRun);
}
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 13 with CliCompileResult

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

the class N4jscBasicTest method testBuildDependentFilesIfFileRemoved.

/**
 * Test a second run of the compiler after a file with downstream files was removed
 */
@Test
public void testBuildDependentFilesIfFileRemoved() throws Exception {
    N4jscTestOptions compileOptions = COMPILE(DONT_CLEAN, workspace);
    CliCompileResult firstRun = n4jsc(compileOptions, SUCCESS);
    assertEquals(firstRun.toString(), 20, firstRun.getTranspiledFilesCount());
    File fileCn4js = proot.toPath().resolve("P1/src/c/C.n4js").toFile();
    assertTrue(fileCn4js.getAbsolutePath(), fileCn4js.isFile());
    assertTrue(fileCn4js.getAbsolutePath(), fileCn4js.exists());
    assertTrue(fileCn4js.getAbsolutePath(), fileCn4js.delete());
    assertFalse(fileCn4js.getAbsolutePath(), fileCn4js.exists());
    CliCompileResult secondRun = n4jsc(compileOptions, VALIDATION_ERRORS);
    // Z and Z3 are affected indirectly
    assertEquals(secondRun.toString(), 2, secondRun.getTranspiledFilesCount());
    // C and Y are affected (js and map)
    assertEquals(secondRun.toString(), 4, secondRun.getDeletedFilesCount());
    // Y.n4js depends on C.n4js
    File fileYjs = proot.toPath().resolve("P1/src-gen/y/Y.js").toFile();
    assertFalse(fileYjs.exists());
}
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 14 with CliCompileResult

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

the class N4jscBasicTest method testRunTwice.

/**
 * Test a second run of the compiler on the same sources
 */
@Test
public void testRunTwice() throws Exception {
    N4jscTestOptions compileOptions = COMPILE(DONT_CLEAN, workspace);
    CliCompileResult firstRun = n4jsc(compileOptions, SUCCESS);
    assertEquals(firstRun.toString(), 20, firstRun.getTranspiledFilesCount());
    Path fileA = proot.toPath().resolve("P1/.n4js.projectstate");
    assertTrue(fileA.toFile().getAbsolutePath(), fileA.toFile().exists());
    CliCompileResult secondRun = n4jsc(compileOptions, SUCCESS);
    assertEquals(secondRun.toString(), 0, secondRun.getTranspiledFilesCount());
    assertOutputEqual(firstRun, secondRun);
}
Also used : Path(java.nio.file.Path) 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 15 with CliCompileResult

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

the class N4jscBasicTest method testFileRemovedIfN4JSRemoved.

/**
 * Test a second run of the compiler after a source file was removed
 */
@Test
public void testFileRemovedIfN4JSRemoved() throws Exception {
    N4jscTestOptions compileOptions = COMPILE(DONT_CLEAN, workspace);
    CliCompileResult firstRun = n4jsc(compileOptions, SUCCESS);
    assertEquals(firstRun.toString(), 20, firstRun.getTranspiledFilesCount());
    File fileAn4js = proot.toPath().resolve("P1/src/A.n4js").toFile();
    assertTrue(fileAn4js.getAbsolutePath(), fileAn4js.isFile());
    assertTrue(fileAn4js.getAbsolutePath(), fileAn4js.exists());
    assertTrue(fileAn4js.getAbsolutePath(), fileAn4js.delete());
    assertFalse(fileAn4js.getAbsolutePath(), fileAn4js.exists());
    File fileAjs = proot.toPath().resolve("P1/src-gen/A.js").toFile();
    assertTrue(fileAjs.exists());
    File fileAmap = proot.toPath().resolve("P1/src-gen/A.map").toFile();
    assertTrue(fileAmap.exists());
    CliCompileResult secondRun = n4jsc(compileOptions, SUCCESS);
    assertEquals(secondRun.toString(), 0, secondRun.getTranspiledFilesCount());
    assertEquals(secondRun.toString(), 2, secondRun.getDeletedFilesCount());
    assertFalse(fileAjs.exists());
    assertFalse(fileAmap.exists());
}
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)

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