Search in sources :

Example 91 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class JavaBuckConfigTest method whenJavacJarDoesNotExistThenHumanReadableExceptionIsThrown.

@Test
public void whenJavacJarDoesNotExistThenHumanReadableExceptionIsThrown() throws IOException {
    String invalidPath = temporaryFolder.getRoot().toAbsolutePath() + "DoesNotExist";
    Reader reader = new StringReader(Joiner.on('\n').join("[tools]", "    javac_jar = " + invalidPath.replace("\\", "\\\\")));
    JavaBuckConfig config = createWithDefaultFilesystem(reader);
    try {
        config.getJavacJarPath();
        fail("Should throw exception as javac file does not exist.");
    } catch (HumanReadableException e) {
        assertEquals("Overridden tools:javac_jar path not found: " + invalidPath, e.getHumanReadableErrorMessage());
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 92 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class ParserIntegrationTest method testBoundaryChecksAreEnforced.

@Test
public void testBoundaryChecksAreEnforced() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "package_boundaries", temporaryFolder);
    workspace.setUp();
    try {
        workspace.runBuckCommand("build", "//java:foo");
        fail("Expected exception");
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), containsString("package boundary"));
    }
    workspace.addBuckConfigLocalOption("project", "check_package_boundary", "false");
    workspace.runBuckCommand("build", "//java:foo").assertSuccess();
    workspace.addBuckConfigLocalOption("project", "check_package_boundary", "true");
    workspace.addBuckConfigLocalOption("project", "package_boundary_exceptions", "java");
    workspace.runBuckCommand("build", "//java:foo").assertSuccess();
    try {
        workspace.runBuckCommand("build", "//java2:foo").assertSuccess();
        fail("Expected exception");
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), containsString("package boundary"));
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) HumanReadableException(com.facebook.buck.util.HumanReadableException) Test(org.junit.Test)

Example 93 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class PythonPackageableComponentsTest method testDuplicateSourcesInComponentsThrowsException.

@Test
public void testDuplicateSourcesInComponentsThrowsException() {
    BuildTarget me = BuildTargetFactory.newInstance("//:me");
    BuildTarget them = BuildTargetFactory.newInstance("//:them");
    Path dest = Paths.get("test");
    PythonPackageComponents compA = PythonPackageComponents.of(ImmutableMap.of(dest, new FakeSourcePath("sourceA")), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty());
    PythonPackageComponents compB = PythonPackageComponents.of(ImmutableMap.of(dest, new FakeSourcePath("sourceB")), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty());
    PythonPackageComponents.Builder builder = new PythonPackageComponents.Builder(me);
    builder.addComponent(compA, them);
    try {
        builder.addComponent(compB, them);
        fail("expected to throw");
    } catch (HumanReadableException e) {
        assertTrue(e.getMessage().contains("duplicate entries"));
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) Test(org.junit.Test)

Example 94 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class GenruleTest method testConstructingGenruleWithBadWorkerMacroThrows.

@Test
public void testConstructingGenruleWithBadWorkerMacroThrows() throws Exception {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    GenruleBuilder genruleBuilder = createGenruleBuilderThatUsesWorkerMacro(ruleResolver);
    try {
        genruleBuilder.setBash("no worker macro here").build(ruleResolver);
    } catch (HumanReadableException e) {
        assertEquals(String.format("You cannot use a worker macro in one of the cmd, bash, or " + "cmd_exe properties and not in the others for genrule //:genrule_with_worker."), e.getHumanReadableErrorMessage());
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 95 with HumanReadableException

use of com.facebook.buck.util.HumanReadableException in project buck by facebook.

the class WorkerProcessProtocolZeroTest method testReceiveHandshakeWithMalformedJSON.

@Test
public void testReceiveHandshakeWithMalformedJSON() throws IOException {
    String malformedJson = "=^..^= meow";
    WorkerProcessProtocol protocol = new WorkerProcessProtocolZero(fakeProcessExecutor, fakeLaunchedProcess, dummyJsonWriter, new JsonReader(new StringReader(malformedJson)), newTempFile());
    try {
        protocol.receiveHandshake(123);
    } catch (HumanReadableException e) {
        assertThat(e.getMessage(), Matchers.containsString("Error receiving handshake response"));
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) Test(org.junit.Test)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15