Search in sources :

Example 41 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class WorkflowTest method checkLastRevStatus_change_request.

@Test
public void checkLastRevStatus_change_request() throws Exception {
    ValidationException e = assertThrows(ValidationException.class, () -> checkLastRevStatus(WorkflowMode.CHANGE_REQUEST));
    assertThat(e.getMessage()).isEqualTo("--check-last-rev-state is not compatible with CHANGE_REQUEST");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 42 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class WorkflowTest method testNullOrigin.

@Test
public void testNullOrigin() throws Exception {
    ValidationException e = assertThrows(ValidationException.class, () -> loadConfig("" + "core.workflow(\n" + "    name = 'foo',\n" + "    authoring = " + authoring + "\n," + "    destination = testing.destination(),\n" + ")\n"));
    for (Message message : console().getMessages()) {
        System.err.println(message);
    }
    console().assertThat().onceInLog(MessageType.ERROR, ".*missing 1 required named argument: origin.*");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Message(com.google.copybara.util.console.Message) Test(org.junit.Test)

Example 43 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class BuildozerBatchTest method testBatchFileNotFoundIsNotNoop.

@Test
public void testBatchFileNotFoundIsNotNoop() throws Exception {
    options.workflowOptions.ignoreNoop = true;
    BuildozerCreate create = skylark.eval("c", "c = " + "buildozer.create(" + "    target = 'copy/bar:baz'," + "    rule_type = 'proto_library'" + ")");
    BuildozerModify notFound = skylark.eval("c", "c = " + "     buildozer.modify(\n" + "       target = ['foo/bar:idontexist'],\n" + "       commands = [ buildozer.cmd('set config \"test\"')],\n" + "     )");
    ValidationException thrown = assertThrows(ValidationException.class, () -> transform(create.join(notFound)));
    assertThat(thrown).hasMessageThat().contains("foo/bar:idontexist");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 44 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class BuildozerBatchTest method testBatchMixedExceptionsGetThrown.

@Test
public void testBatchMixedExceptionsGetThrown() throws Exception {
    options.workflowOptions.ignoreNoop = true;
    BuildozerCreate create = skylark.eval("c", "c = " + "buildozer.create(" + "    target = 'copy/bar:baz'," + "    rule_type = 'proto_library'" + ")");
    BuildozerModify targetNotFoundButIgnored = skylark.eval("c", "c = " + "     buildozer.modify(\n" + "       target = ['foo/bar:idontexist'],\n" + "       commands = [ buildozer.cmd('set config \"test\"')],\n" + "     )");
    BuildozerModify fileNotFound = skylark.eval("c", "c = " + "     buildozer.modify(\n" + "       target = ['nosuch:file'],\n" + "       commands = [ buildozer.cmd('set config \"test\"')],\n" + "     )");
    Files.createDirectories(checkoutDir.resolve("foo/bar"));
    Files.write(checkoutDir.resolve("foo/bar/BUILD"), "".getBytes(UTF_8));
    // this is fine
    transform(create.join(targetNotFoundButIgnored));
    // this is not
    ValidationException thrown = assertThrows(ValidationException.class, () -> transform(create.join(targetNotFoundButIgnored).join(fileNotFound)));
    assertThat(thrown).hasMessageThat().contains("nosuch:file");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) Test(org.junit.Test)

Example 45 with ValidationException

use of com.google.copybara.exception.ValidationException in project copybara by google.

the class SkylarkParserTest method testStrictStarlarkParsingCatchesError.

@Test
public void testStrictStarlarkParsingCatchesError() throws IOException, ValidationException {
    // A parse error is always reported, even in LOOSE mode.
    options.general.starlarkMode = StarlarkMode.LOOSE.name();
    parser = new SkylarkTestExecutor(options);
    ValidationException ex = assertThrows(ValidationException.class, () -> parser.loadConfig("foo = '\\j',"));
    assertThat(ex).hasMessageThat().contains("Trailing comma");
    // Strict mode detects string escapes, if/for at top level, and loads not at the top.
    options.general.starlarkMode = StarlarkMode.STRICT.name();
    parser = new SkylarkTestExecutor(options);
    ex = assertThrows(ValidationException.class, () -> parser.loadConfig("foo = '\\j',"));
    assertThat(ex).hasMessageThat().contains("Trailing comma");
    assertThat(ex).hasMessageThat().contains("invalid escape sequence");
}
Also used : ValidationException(com.google.copybara.exception.ValidationException) SkylarkTestExecutor(com.google.copybara.testing.SkylarkTestExecutor) Test(org.junit.Test)

Aggregations

ValidationException (com.google.copybara.exception.ValidationException)178 Test (org.junit.Test)125 Path (java.nio.file.Path)33 RepoException (com.google.copybara.exception.RepoException)29 NonReversibleValidationException (com.google.copybara.exception.NonReversibleValidationException)26 ImmutableList (com.google.common.collect.ImmutableList)21 IOException (java.io.IOException)19 Console (com.google.copybara.util.console.Console)16 EmptyChangeException (com.google.copybara.exception.EmptyChangeException)14 DummyRevision (com.google.copybara.testing.DummyRevision)14 Glob (com.google.copybara.util.Glob)14 ProfilerTask (com.google.copybara.profiler.Profiler.ProfilerTask)13 Nullable (javax.annotation.Nullable)13 Migration (com.google.copybara.config.Migration)11 TestingConsole (com.google.copybara.util.console.testing.TestingConsole)11 Iterables (com.google.common.collect.Iterables)10 Change (com.google.copybara.Change)10 CannotResolveRevisionException (com.google.copybara.exception.CannotResolveRevisionException)10 Collectors (java.util.stream.Collectors)10 WriterContext (com.google.copybara.WriterContext)9