Search in sources :

Example 11 with TransformationStatus

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

the class SkylarkTransformationTest method testStarlarkTransform_noReturnValue_isTreatedAsSuccess.

@Test
public void testStarlarkTransform_noReturnValue_isTreatedAsSuccess() throws Exception {
    Transformation t = skylark.eval("t", "" + "def foo(ctx):\n" + "  # Do nothing \n" + "  pass\n" + "\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)

Example 12 with TransformationStatus

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

the class SkylarkTransformationTest method testStarlarkTransform_returnsSuccess.

@Test
public void testStarlarkTransform_returnsSuccess() throws Exception {
    Transformation t = skylark.eval("t", "" + "def foo(ctx):\n" + "  return ctx.success()\n" + "\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)

Example 13 with TransformationStatus

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

the class SkylarkTransformationTest method testStarlarkTransform_returnsNoop.

@Test
public void testStarlarkTransform_returnsNoop() throws Exception {
    Transformation t = skylark.eval("t", "" + "def foo(ctx):\n" + "  return ctx.noop('Reason for noop.')\n" + "\n" + "t = core.dynamic_transform(foo)");
    TransformationStatus status = t.transform(transformWork);
    assertThat(status.isNoop()).isTrue();
    assertThat(status.getMessage()).isEqualTo("Reason for noop.");
}
Also used : TransformationStatus(com.google.copybara.TransformationStatus) Transformation(com.google.copybara.Transformation) Test(org.junit.Test)

Example 14 with TransformationStatus

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

the class ReplaceTest method testNoBacktracking.

@Test
public void testNoBacktracking() throws Exception {
    Replace transformation = eval("core.replace(\n" + "  before = 'foo/${a}${a}',\n" + "  after = '${a}',\n" + "  regex_groups = {\n" + "       'a' : '[a-z]+',\n" + "  },\n" + "  repeated_groups = True,\n" + ")");
    writeFile(checkoutDir.resolve("before_and_after"), "foo/barbar\n");
    // Because we don't use backtracking this repeated group is expected to fail.
    TransformationStatus status = transform(transformation);
    assertThat(status.isNoop()).isTrue();
}
Also used : TransformationStatus(com.google.copybara.TransformationStatus) Test(org.junit.Test)

Example 15 with TransformationStatus

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

the class ReplaceTest method replaceErrorEscapesNewLine.

@Test
public void replaceErrorEscapesNewLine() throws Exception {
    Replace replace = eval("core.replace(\n" + "  before = \"hello\\n\\r\\tbye!\",\n" + "  after = 'lulz',\n" + ")");
    TransformationStatus status = transform(replace);
    assertThat(status.isNoop()).isTrue();
    assertThat(status.getMessage()).contains("hello\\n\\r\\tbye!");
}
Also used : TransformationStatus(com.google.copybara.TransformationStatus) Test(org.junit.Test)

Aggregations

TransformationStatus (com.google.copybara.TransformationStatus)27 Test (org.junit.Test)23 Transformation (com.google.copybara.Transformation)12 TransformWork (com.google.copybara.TransformWork)9 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)2 ValidationException (com.google.copybara.exception.ValidationException)2 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)1 RepoException (com.google.copybara.exception.RepoException)1 Transformations.toTransformation (com.google.copybara.transform.Transformations.toTransformation)1 Console (com.google.copybara.util.console.Console)1 Pattern (com.google.re2j.Pattern)1 PathMatcher (java.nio.file.PathMatcher)1 EvalException (net.starlark.java.eval.EvalException)1 Mutability (net.starlark.java.eval.Mutability)1 StarlarkThread (net.starlark.java.eval.StarlarkThread)1