Search in sources :

Example 31 with Transformation

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

the class SequenceTest method testSequence_noopIfAnyNoop_someChildNoops.

@Test
public void testSequence_noopIfAnyNoop_someChildNoops() throws Exception {
    TransformWork work = uncachedTreeStateTransformWork();
    MockTransform t1 = new MockTransform("t1");
    MockTransform t2 = new MockTransform("t2").setNoop(true);
    MockTransform t3 = new MockTransform("t3");
    Transformation t = sequence(Sequence.NoopBehavior.NOOP_IF_ANY_NOOP, t1, t2, t3);
    TransformationStatus status = t.transform(work);
    assertThat(t1.wasRun).isTrue();
    assertThat(t2.wasRun).isTrue();
    assertThat(t3.wasRun).isFalse();
    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 Transformation

use of com.google.copybara.Transformation 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 33 with Transformation

use of com.google.copybara.Transformation 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 34 with Transformation

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

the class SkylarkTransformationTest method testStarlarkTransform_convertToString.

@Test
public void testStarlarkTransform_convertToString() throws Exception {
    Transformation t = skylark.eval("t", "" + "def _foo_impl(ctx):\n" + "  pass\n" + "\n" + "t = core.dynamic_transform(_foo_impl, {'a': 1})");
    assertThat(t.describe()).isEqualTo("_foo_impl");
    assertThat(t.toString()).isEqualTo("Foo{a=1}");
}
Also used : Transformation(com.google.copybara.Transformation) Test(org.junit.Test)

Example 35 with Transformation

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

the class SkylarkTransformationTest method testStarlarkTransform_returnValueCanBeCasedOn.

@Test
public void testStarlarkTransform_returnValueCanBeCasedOn() throws Exception {
    Transformation t = skylark.eval("t", "" + "def foo(ctx):\n" + "  return ctx.success()\n" + "\n" + "s = core.dynamic_transform(foo)" + "\n" + "def bar(ctx):\n" + "  status = ctx.run(s)\n" + "  if not status.is_success:\n" + "    core.fail_with_noop()\n" + "  if status.is_noop:\n" + "    core.fail_with_noop()\n" + "  return status" + "\n" + "t = core.dynamic_transform(foo)");
    TransformationStatus status = t.transform(transformWork);
    assertThat(status.isSuccess()).isTrue();
}
Also used : TransformationStatus(com.google.copybara.TransformationStatus) Transformation(com.google.copybara.Transformation) 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