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"));
}
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();
}
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();
}
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();
}
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();
}
Aggregations