Search in sources :

Example 6 with ExplicitReversal

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

the class TransformWorkTest method testAddHiddenLabel.

@Test
public void testAddHiddenLabel() throws Exception {
    TransformWork work = create("Foo\n\nSOME=TEST\n");
    ExplicitReversal t = skylark.eval("t", "" + "def user_transform(ctx):\n" + "    " + "ctx.add_label('FOO','BAR', hidden = True)" + "\n" + "    " + "ctx.add_label('FOO','BAR', hidden = True)" + "\n" + "t = core.transform([user_transform])");
    t.transform(work);
    assertThat(work.getMessage()).isEqualTo("Foo\n\nSOME=TEST\n");
    assertThat(work.getAllLabels("FOO").getImmutableList()).isEqualTo(ImmutableList.of("BAR"));
}
Also used : ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Example 7 with ExplicitReversal

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

the class CoreTransformTest method testOneLayerTransformWithAllNoops_usingNoopBehavior_noopIfAllNoop.

@Test
public void testOneLayerTransformWithAllNoops_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 = 'also not found',\n" + "        after = 'also not important',\n" + "    ),\n" + "], noop_behavior = 'NOOP_IF_ALL_NOOP')");
    Files.write(checkoutDir.resolve("file.txt"), "foo".getBytes(UTF_8));
    TransformationStatus status = t.transform(TransformWorks.of(checkoutDir, "msg", console));
    assertThat(status.isNoop()).isTrue();
    console.assertThat().timesInLog(2, MessageType.WARNING, ".*NOOP.*");
    assertThatPath(checkoutDir).containsFile("file.txt", "foo").containsNoMoreFiles();
}
Also used : ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Example 8 with ExplicitReversal

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

the class CoreTransformTest method autoReversibleCheck.

@Test
public void autoReversibleCheck() throws Exception {
    ExplicitReversal t = skylark.eval("x", "x=" + "core.transform([\n" + "    core.replace(\n" + "        before = 'foo',\n" + "        after = 'bar',\n" + "    ),\n" + "    core.replace(\n" + "        before = 'bar',\n" + "        after = 'baz',\n" + "    ),\n" + "])");
    Files.write(checkoutDir.resolve("file.txt"), "foo".getBytes(UTF_8));
    t.transform(TransformWorks.of(checkoutDir, "msg", console));
    assertThatPath(checkoutDir).containsFile("file.txt", "baz").containsNoMoreFiles();
    t.reverse().transform(TransformWorks.of(checkoutDir, "msg", console));
    assertThatPath(checkoutDir).containsFile("file.txt", "foo").containsNoMoreFiles();
}
Also used : ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Example 9 with ExplicitReversal

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

the class CoreTransformTest method testIgnoreNoopWithVerboseFalse.

@Test
public void testIgnoreNoopWithVerboseFalse() throws Exception {
    ExplicitReversal t = skylark.eval("x", "x=" + "core.transform([\n" + "    core.replace(\n" + "        before = 'not found',\n" + "        after = 'not important',\n" + "    ),\n" + "]," + "ignore_noop=True)");
    console = new TestingConsole(false);
    options.setConsole(console);
    Files.write(checkoutDir.resolve("file.txt"), "foo".getBytes(UTF_8));
    t.transform(TransformWorks.of(checkoutDir, "msg", console));
    console.assertThat().matchesNext(MessageType.PROGRESS, ".*Replace not found.*").containsNoMoreMessages();
}
Also used : TestingConsole(com.google.copybara.util.console.testing.TestingConsole) ExplicitReversal(com.google.copybara.transform.ExplicitReversal) Test(org.junit.Test)

Example 10 with ExplicitReversal

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

the class CoreTransformTest method testOneLayerTransformWithNoop.

@Test
public void testOneLayerTransformWithNoop() 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" + "], ignore_noop = True)");
    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)

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