Search in sources :

Example 21 with HumanReadableException

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

the class AndroidPlatformTargetTest method testThrowsExceptionWhenAddOnsDirectoryIsMissing.

@Test
public void testThrowsExceptionWhenAddOnsDirectoryIsMissing() throws IOException {
    File androidSdkDir = tempDir.newFolder();
    String platformId = "Google Inc.:Google APIs:17";
    AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver(Optional.of(androidSdkDir.toPath()), /* buildToolsDir */
    Optional.empty(), /* androidNdkDir */
    Optional.empty(), /* ndkVersion */
    Optional.empty());
    try {
        AndroidPlatformTarget.getTargetForId(platformId, androidDirectoryResolver, /* aaptOverride */
        Optional.empty());
        fail("Should have thrown HumanReadableException");
    } catch (HumanReadableException e) {
        assertEquals(String.format("Google APIs not found in %s.\n" + "Please run '%s/tools/android sdk' and select both 'SDK Platform' and " + "'Google APIs' under Android (API 17)", new File(androidSdkDir, "add-ons/addon-google_apis-google-17/libs").getAbsolutePath(), androidSdkDir.getPath()), e.getMessage());
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) File(java.io.File) Test(org.junit.Test)

Example 22 with HumanReadableException

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

the class MultiarchFileTest method descriptionWithMultipleDifferentSdksShouldFail.

@Test
public void descriptionWithMultipleDifferentSdksShouldFail() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    HumanReadableException exception = null;
    try {
        nodeBuilderFactory.getNodeBuilder(BuildTargetFactory.newInstance("//foo:xctest#iphoneos-i386,macosx-x86_64")).build(resolver);
    } catch (HumanReadableException e) {
        exception = e;
    }
    assertThat(exception, notNullValue());
    assertThat("Should throw exception about different architectures", exception.getHumanReadableErrorMessage(), endsWith("Fat binaries can only be generated from binaries compiled for the same SDK."));
}
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 23 with HumanReadableException

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

the class BuckConfigTest method testDuplicateAliasDefinitionThrows.

@Test
public void testDuplicateAliasDefinitionThrows() throws IOException, NoSuchBuildTargetException {
    Reader reader = new StringReader(Joiner.on('\n').join("[alias]", "foo = //java/com/example:foo", "foo = //java/com/example:foo"));
    try {
        BuckConfigTestUtils.createWithDefaultFilesystem(temporaryFolder, reader);
        fail("Should have thrown HumanReadableException.");
    } catch (HumanReadableException e) {
        assertEquals("Throw an exception if there are duplicate definitions for an alias, " + "even if the values are the same.", "Duplicate definition for foo in the [alias] section of your .buckconfig or " + ".buckconfig.local.", 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 24 with HumanReadableException

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

the class BuckConfigTest method testConstructorThrowsForMalformedBuildTarget.

@Test
public void testConstructorThrowsForMalformedBuildTarget() throws IOException {
    Reader reader = new StringReader(Joiner.on('\n').join("[alias]", "fb4a   = :fb4a"));
    ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
    EasyMock.replay(projectFilesystem);
    try {
        BuckConfigTestUtils.createWithDefaultFilesystem(temporaryFolder, reader);
        fail("Should have thrown HumanReadableException.");
    } catch (HumanReadableException e) {
        assertEquals("Path in :fb4a must start with //", e.getHumanReadableErrorMessage());
    }
    EasyMock.verify(projectFilesystem);
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 25 with HumanReadableException

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

the class BuckConfigTest method testUnresolvedAliasThrows.

@Test
public void testUnresolvedAliasThrows() throws IOException, NoSuchBuildTargetException {
    Reader reader = new StringReader(Joiner.on('\n').join("[alias]", "foo = //java/com/example:foo", "bar = food"));
    try {
        BuckConfigTestUtils.createWithDefaultFilesystem(temporaryFolder, reader);
        fail("Should have thrown HumanReadableException.");
    } catch (HumanReadableException e) {
        assertEquals("No alias for: food.", 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)

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