Search in sources :

Example 1 with N4jscTestOptions

use of org.eclipse.n4js.cli.N4jscTestOptions in project n4js by eclipse.

the class N4jscBasicTest method testBuildDependentFilesIfFileReadded.

/**
 * Test a second run of the compiler after a file was added to fix compile problems
 */
@Test
public void testBuildDependentFilesIfFileReadded() throws Exception {
    N4jscTestOptions compileOptions = COMPILE(DONT_CLEAN, workspace);
    CliCompileResult firstRun = n4jsc(compileOptions, SUCCESS);
    assertEquals(firstRun.toString(), 20, firstRun.getTranspiledFilesCount());
    Path fileCn4js = proot.toPath().resolve("P1/src/c/C.n4js");
    byte[] bytesC = Files.readAllBytes(fileCn4js);
    Files.delete(fileCn4js);
    n4jsc(compileOptions, VALIDATION_ERRORS);
    // Y.n4js depends on C.n4js
    File fileCjs = proot.toPath().resolve("P1/src-gen/c/C.js").toFile();
    assertFalse(fileCjs.exists());
    File fileYjs = proot.toPath().resolve("P1/src-gen/y/Y.js").toFile();
    assertFalse(fileYjs.exists());
    Files.write(fileCn4js, bytesC);
    CliCompileResult thirdRun = n4jsc(compileOptions, SUCCESS);
    assertTrue(fileCjs.exists());
    assertTrue(fileYjs.exists());
    assertOutputEqual(firstRun, thirdRun);
}
Also used : Path(java.nio.file.Path) 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 2 with N4jscTestOptions

use of org.eclipse.n4js.cli.N4jscTestOptions 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 3 with N4jscTestOptions

use of org.eclipse.n4js.cli.N4jscTestOptions 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 4 with N4jscTestOptions

use of org.eclipse.n4js.cli.N4jscTestOptions 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 5 with N4jscTestOptions

use of org.eclipse.n4js.cli.N4jscTestOptions 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

N4jscTestOptions (org.eclipse.n4js.cli.N4jscTestOptions)36 Test (org.junit.Test)35 AbstractCliCompileTest (org.eclipse.n4js.cli.helper.AbstractCliCompileTest)33 CliCompileResult (org.eclipse.n4js.cli.helper.CliCompileResult)22 File (java.io.File)15 ProcessResult (org.eclipse.n4js.cli.helper.ProcessResult)4 Path (java.nio.file.Path)2 AbstractCliJarTest (org.eclipse.n4js.cli.helper.AbstractCliJarTest)2 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