Search in sources :

Example 31 with TransformWork

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

the class SequenceTest method testSequence_noopIfAllNoop_allChildNoops.

@Test
public void testSequence_noopIfAllNoop_allChildNoops() throws Exception {
    TransformWork work = uncachedTreeStateTransformWork();
    MockTransform t1 = new MockTransform("t1").setNoop(true);
    MockTransform t2 = new MockTransform("t2").setNoop(true);
    MockTransform t3 = new MockTransform("t3").setNoop(true);
    Transformation t = sequence(Sequence.NoopBehavior.NOOP_IF_ALL_NOOP, t1, t2, t3);
    TransformationStatus status = t.transform(work);
    assertThat(t1.wasRun).isTrue();
    assertThat(t2.wasRun).isTrue();
    assertThat(t3.wasRun).isTrue();
    assertThat(status.isNoop()).isTrue();
}
Also used : TransformationStatus(com.google.copybara.TransformationStatus) Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Example 32 with TransformWork

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

the class SequenceTest method testSequence_nestedSequences_missOnSecondCache.

@Test
public void testSequence_nestedSequences_missOnSecondCache() throws Exception {
    TransformWork work = cachedTreeStateTransformWork();
    MockTransform t1 = new MockTransform("t1").setUseTreeState(false);
    MockTransform t2 = new MockTransform("t2").setUseTreeState(true).setExpectCacheHit(false);
    MockTransform t3 = new MockTransform("t3").setUseTreeState(true).setExpectCacheHit(true);
    MockTransform t4 = new MockTransform("t4").setUseTreeState(true).setExpectCacheHit(true);
    Transformation t = sequence(sequence(t1, t2), sequence(t3, t4));
    t.transform(work);
    assertThat(t1.wasRun).isTrue();
    assertThat(t2.wasRun).isTrue();
    assertThat(t3.wasRun).isTrue();
    assertThat(t4.wasRun).isTrue();
}
Also used : Transformation(com.google.copybara.Transformation) TransformWork(com.google.copybara.TransformWork) Test(org.junit.Test)

Example 33 with TransformWork

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

the class TodoReplaceTest method run.

private TransformWork run(Transformation replace) throws Exception {
    TransformWork work = TransformWorks.of(checkoutDir, "testmsg", console);
    replace.transform(work);
    return work;
}
Also used : TransformWork(com.google.copybara.TransformWork)

Example 34 with TransformWork

use of com.google.copybara.TransformWork 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)

Example 35 with TransformWork

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

the class MetadataModuleTest method testLastMessageWithMerge.

@Test
public void testLastMessageWithMerge() throws Exception {
    Changes changes = new Changes(ImmutableList.of(new Change<>(new DummyRevision("3"), ORIGINAL_AUTHOR, "merge", fakeDate(), ImmutableListMultimap.of(), /*changeFiles=*/
    null, /*merge=*/
    true, ImmutableList.of(new DummyRevision("10"), new DummyRevision("20"))), new Change<>(new DummyRevision("2"), ORIGINAL_AUTHOR, "change2", fakeDate(), ImmutableListMultimap.of()), new Change<>(new DummyRevision("1"), ORIGINAL_AUTHOR, "change1", fakeDate(), ImmutableListMultimap.of())), ImmutableList.of());
    TransformWork work = TransformWorks.of(workdir, "the message", testingConsole).withChanges(changes);
    // The default is to use merges, since git.origin does --first-parent by default
    skylark.<UseLastChange>eval("s", "s = metadata.use_last_change()").transform(work);
    assertThat(work.getMessage()).isEqualTo("merge");
    work = TransformWorks.of(workdir, "the message", testingConsole).withChanges(changes);
    skylark.<UseLastChange>eval("s", "s = metadata.use_last_change(use_merge = False)").transform(work);
    assertThat(work.getMessage()).isEqualTo("change2");
}
Also used : Changes(com.google.copybara.Changes) TransformWork(com.google.copybara.TransformWork) DummyRevision(com.google.copybara.testing.DummyRevision) TransformWorks.toChange(com.google.copybara.testing.TransformWorks.toChange) ProcessedChange(com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange) Change(com.google.copybara.Change) Test(org.junit.Test)

Aggregations

TransformWork (com.google.copybara.TransformWork)41 Test (org.junit.Test)33 Transformation (com.google.copybara.Transformation)23 TransformationStatus (com.google.copybara.TransformationStatus)9 DummyRevision (com.google.copybara.testing.DummyRevision)6 Changes (com.google.copybara.Changes)5 Author (com.google.copybara.authoring.Author)5 ValidationException (com.google.copybara.exception.ValidationException)4 Change (com.google.copybara.Change)3 ProcessedChange (com.google.copybara.testing.RecordsProcessCallDestination.ProcessedChange)3 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)2 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)2 RepoException (com.google.copybara.exception.RepoException)2 TransformWorks.toChange (com.google.copybara.testing.TransformWorks.toChange)2 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1