Search in sources :

Example 11 with ExplicitReversal

use of com.google.copybara.transform.ExplicitReversal in project copybara by google.

the class CoreTransformTest method testOneLayerTransformWithNoop_usingNoopBehavior_noopIfAllNoop.

@Test
public void testOneLayerTransformWithNoop_usingNoopBehavior_noopIfAllNoop() throws Exception {
    ExplicitReversal t = skylark.eval("x", "x=" + "core.transform([\n" + "    core.replace(\n" + "        before = 'not found',\n" + "        after = 'not important',\n" + "    ),\n" + "    core.replace(\n" + "        before = 'foo',\n" + "        after = 'bar',\n" + "    ),\n" + "], noop_behavior = 'NOOP_IF_ALL_NOOP')");
    Files.write(checkoutDir.resolve("file.txt"), "foo".getBytes(UTF_8));
    t.transform(TransformWorks.of(checkoutDir, "msg", console));
    console.assertThat().onceInLog(MessageType.WARNING, ".*NOOP.*");
    assertThatPath(checkoutDir).containsFile("file.txt", "bar").containsNoMoreFiles();
}
Also used : ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Example 12 with ExplicitReversal

use of com.google.copybara.transform.ExplicitReversal in project copybara by google.

the class CoreTransformTest method testOneLayerTransformWithNoNoop.

@Test
public void testOneLayerTransformWithNoNoop() throws ValidationException, IOException {
    ExplicitReversal t = skylark.eval("x", "x=" + "core.transform([\n" + "    core.replace(\n" + "        before = 'not found',\n" + "        after = 'not important',\n" + "    ),\n" + "    core.replace(\n" + "        before = 'foo',\n" + "        after = 'bar',\n" + "    ),\n" + "], ignore_noop = False)");
    Files.write(checkoutDir.resolve("file.txt"), "foo".getBytes(UTF_8));
    VoidOperationException e = assertThrows(VoidOperationException.class, () -> t.transform(TransformWorks.of(checkoutDir, "msg", console)));
    assertThat(e).hasMessageThat().containsMatch(".*was a no-op because it didn't " + "change any of the matching files.*");
    assertThatPath(checkoutDir).containsFile("file.txt", "foo").containsNoMoreFiles();
}
Also used : VoidOperationException(com.google.copybara.exception.VoidOperationException) ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Example 13 with ExplicitReversal

use of com.google.copybara.transform.ExplicitReversal in project copybara by google.

the class CoreTransformTest method testOneLayerTransformWithNoop_usingNoopBehavior_ignoreNoop.

@Test
public void testOneLayerTransformWithNoop_usingNoopBehavior_ignoreNoop() throws Exception {
    ExplicitReversal t = skylark.eval("x", "x=" + "core.transform([\n" + "    core.replace(\n" + "        before = 'not found',\n" + "        after = 'not important',\n" + "    ),\n" + "    core.replace(\n" + "        before = 'foo',\n" + "        after = 'bar',\n" + "    ),\n" + "], noop_behavior = 'IGNORE_NOOP')");
    Files.write(checkoutDir.resolve("file.txt"), "foo".getBytes(UTF_8));
    t.transform(TransformWorks.of(checkoutDir, "msg", console));
    console.assertThat().onceInLog(MessageType.WARNING, ".*NOOP.*");
    assertThatPath(checkoutDir).containsFile("file.txt", "bar").containsNoMoreFiles();
}
Also used : ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Example 14 with ExplicitReversal

use of com.google.copybara.transform.ExplicitReversal in project copybara by google.

the class CoreTransformTest method testSecondLayerTransformWithOuterNoop.

@Test
public void testSecondLayerTransformWithOuterNoop() throws Exception {
    String secondLayerTransform = "core.transform([\n" + "    core.replace(\n" + "        before = 'not found',\n" + "        after = 'not important',\n" + "    ),\n" + "]),\n";
    ExplicitReversal t = skylark.eval("x", "x=" + "core.transform([\n" + "    core.replace(\n" + "        before = 'foo',\n" + "        after = 'bar',\n" + "     )," + secondLayerTransform + "    core.replace(\n" + "        before = 'bar',\n" + "        after = 'baz',\n" + "    )\n" + "], ignore_noop=True)");
    Files.write(checkoutDir.resolve("file.txt"), "foo".getBytes(UTF_8));
    t.transform(TransformWorks.of(checkoutDir, "msg", console));
    assertThatPath(checkoutDir).containsFile("file.txt", "baz").containsNoMoreFiles();
    console.assertThat().onceInLog(MessageType.WARNING, ".*NOOP.*");
}
Also used : ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Example 15 with ExplicitReversal

use of com.google.copybara.transform.ExplicitReversal in project copybara by google.

the class CoreTransformTest method testSecondLayerWithInnerNoop.

@Test
public void testSecondLayerWithInnerNoop() throws Exception {
    String secondLayerTransform = "core.transform([\n" + "    core.replace(\n" + "        before = 'not found',\n" + "        after = 'not important',\n" + "    ),\n" + "]," + "ignore_noop=True),";
    ExplicitReversal t = skylark.eval("x", "x=" + "core.transform([\n" + "    core.replace(\n" + "        before = 'foo',\n" + "        after = 'bar',\n" + "    ),\n" + secondLayerTransform + "    core.replace(\n" + "        before = 'bar',\n" + "        after = 'baz',\n" + "    )\n" + "], ignore_noop=False)");
    Files.write(checkoutDir.resolve("file.txt"), "foo".getBytes(UTF_8));
    t.transform(TransformWorks.of(checkoutDir, "msg", console));
    assertThatPath(checkoutDir).containsFile("file.txt", "baz").containsNoMoreFiles();
    console.assertThat().onceInLog(MessageType.WARNING, ".*NOOP.*");
}
Also used : ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Aggregations

ExplicitReversal (com.google.copybara.transform.ExplicitReversal)16 Test (org.junit.Test)14 VoidOperationException (com.google.copybara.exception.VoidOperationException)2 DocDefault (com.google.copybara.doc.annotations.DocDefault)1 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)1 Sequence (com.google.copybara.transform.Sequence)1 SkylarkTransformation (com.google.copybara.transform.SkylarkTransformation)1 Transformations.toTransformation (com.google.copybara.transform.Transformations.toTransformation)1 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)1 StarlarkMethod (net.starlark.java.annot.StarlarkMethod)1