Search in sources :

Example 36 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class FilterReplaceTest method testCoreReplaceAll.

/**
 * Equivalent to core.todo_replace
 */
@Test
public void testCoreReplaceAll() throws Exception {
    write("file.txt", "" + "Some text // TODO(foo, bar, baz)\n" + "more text\n");
    Transformation t = eval(Core.TODO_FILTER_REPLACE_EXAMPLE);
    transform(t);
    assertThatPath(checkoutDir).containsFile("file.txt", "Some text // TODO(fooz, bar, bazz)\n" + "more text\n").containsNoMoreFiles();
    transform(t.reverse());
    assertThatPath(checkoutDir).containsFile("file.txt", "Some text // TODO(foo, bar, baz)\n" + "more text\n").containsNoMoreFiles();
}
Also used : Transformation(com.google.copybara.Transformation) Test(org.junit.Test)

Example 37 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class FilterReplaceTest method testPath.

@Test
public void testPath() throws Exception {
    write("file1.txt", "foo\n");
    write("file2.txt", "foo\n");
    Transformation transformation = filterReplace("" + "regex = '.*'," + "mapping = {'foo': 'bar'}," + "paths = glob(['file1.txt']),");
    transform(transformation);
    assertThatPath(checkoutDir).containsFile("file1.txt", "bar\n").containsFile("file2.txt", "foo\n").containsNoMoreFiles();
    transform(transformation.reverse());
    assertThatPath(checkoutDir).containsFile("file1.txt", "foo\n").containsFile("file2.txt", "foo\n").containsNoMoreFiles();
}
Also used : Transformation(com.google.copybara.Transformation) Test(org.junit.Test)

Example 38 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class ReplaceTest method testAppendFile.

@Test
public void testAppendFile() throws Exception {
    Transformation transformation = eval("core.transform([\n" + "    core.replace(\n" + "       before = '${end}',\n" + "       after  = 'some append',\n" + "       multiline = True,\n" + "       regex_groups = { 'end' : r'\\z'},\n" + "    )\n" + "],\n" + "reversal = [\n" + "    core.replace(\n" + "       before = 'some append${end}',\n" + "       after = '',\n" + "       multiline = True,\n" + "       regex_groups = { 'end' : r'\\z'},\n" + "    )" + "])");
    Path file1 = checkoutDir.resolve("file1.txt");
    writeFile(file1, "foo\nbar\nbaz\n");
    transform(transformation);
    assertThatPath(checkoutDir).containsFile("file1.txt", "foo\nbar\nbaz\nsome append");
    transform(transformation.reverse());
    assertThatPath(checkoutDir).containsFile("file1.txt", "foo\nbar\nbaz\n");
}
Also used : FileSubjects.assertThatPath(com.google.copybara.testing.FileSubjects.assertThatPath) Path(java.nio.file.Path) Transformation(com.google.copybara.Transformation) Test(org.junit.Test)

Example 39 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class MetadataModuleTest method testMapAuthor_nonReversible.

@Test
public void testMapAuthor_nonReversible() throws Exception {
    Transformation m = skylark.eval("m", "m = " + "metadata.map_author({\n" + "    'a' : 'b <b@example.com>',\n" + "}," + "reversible = True)");
    assertThrows(NonReversibleValidationException.class, () -> m.reverse());
}
Also used : Transformation(com.google.copybara.Transformation) Test(org.junit.Test)

Example 40 with Transformation

use of com.google.copybara.Transformation in project copybara by google.

the class MetadataModuleTest method testMapAuthor_noop_reversal.

@Test
public void testMapAuthor_noop_reversal() throws Exception {
    Transformation m = skylark.eval("m", "m = " + "metadata.map_author({\n" + "    'a' : 'b <b@example.com>',\n" + "}," + "noop_reverse = True)");
    TransformWork work = TransformWorks.of(workdir, "test", testingConsole);
    work.setAuthor(new Author("a", "foo@foo"));
    m.transform(work);
    assertThat(work.getAuthor().getEmail()).isEqualTo("b@example.com");
    m.reverse().transform(work);
    assertThat(work.getAuthor().getEmail()).isEqualTo("b@example.com");
}
Also used : Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) Author(com.google.copybara.authoring.Author) Test(org.junit.Test)

Aggregations

Transformation (com.google.copybara.Transformation)42 Test (org.junit.Test)38 TransformWork (com.google.copybara.TransformWork)23 TransformationStatus (com.google.copybara.TransformationStatus)12 Author (com.google.copybara.authoring.Author)3 DummyRevision (com.google.copybara.testing.DummyRevision)3 Changes (com.google.copybara.Changes)2 Sequence (com.google.copybara.transform.Sequence)2 Transformations.toTransformation (com.google.copybara.transform.Transformations.toTransformation)2 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)1 ValidationException (com.google.copybara.exception.ValidationException)1 FileSubjects.assertThatPath (com.google.copybara.testing.FileSubjects.assertThatPath)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1