Search in sources :

Example 46 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class AppleBuildRulesTest method testAppleLibraryIsXcodeTargetDescription.

@Test
public void testAppleLibraryIsXcodeTargetDescription() throws Exception {
    Cell rootCell = (new TestCellBuilder()).build();
    BuildTarget libraryTarget = BuildTarget.builder(rootCell.getRoot(), "//foo", "lib").build();
    TargetNode<AppleLibraryDescription.Arg, ?> library = AppleLibraryBuilder.createBuilder(libraryTarget).setSrcs(ImmutableSortedSet.of()).build();
    assertTrue(AppleBuildRules.isXcodeTargetDescription(library.getDescription()));
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 47 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class OwnersReportTest method verifyInputsWithOneOwnerAreCorrectlyReported.

/**
   * Verify that owners are correctly detected:
   *  - one owner, multiple inputs
   */
@Test
public void verifyInputsWithOneOwnerAreCorrectlyReported() throws CmdLineException, IOException, InterruptedException {
    ImmutableSet<String> inputs = ImmutableSet.of("java/somefolder/badfolder/somefile.java", "java/somefolder/perfect.java", "com/test/subtest/random.java");
    ImmutableSet<Path> inputPaths = RichStream.from(inputs).map(filesystem::getPath).toImmutableSet();
    for (Path path : inputPaths) {
        filesystem.mkdirs(path.getParent());
        filesystem.writeContentsToPath("", path);
    }
    BuildTarget target = BuildTargetFactory.newInstance("//base:name");
    TargetNode<?, ?> targetNode = createTargetNode(target, inputPaths);
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    OwnersReport report = OwnersReport.generateOwnersReport(cell, targetNode, inputs);
    assertTrue(report.nonFileInputs.isEmpty());
    assertTrue(report.nonExistentInputs.isEmpty());
    assertTrue(report.inputsWithNoOwners.isEmpty());
    assertEquals(inputs.size(), report.owners.size());
    assertTrue(report.owners.containsKey(targetNode));
    assertEquals(targetNode.getInputs(), report.owners.get(targetNode));
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 48 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class OwnersReportTest method verifyInputsWithoutOwnersAreCorrectlyReported.

@Test
public void verifyInputsWithoutOwnersAreCorrectlyReported() throws CmdLineException, IOException, InterruptedException {
    // Inputs that should be treated as existing files
    ImmutableSet<String> inputs = ImmutableSet.of("java/somefolder/badfolder/somefile.java", "java/somefolder/perfect.java", "com/test/subtest/random.java");
    ImmutableSet<Path> inputPaths = RichStream.from(inputs).map(filesystem::getPath).toImmutableSet();
    // Write dummy files.
    for (Path path : inputPaths) {
        filesystem.mkdirs(path.getParent());
        filesystem.writeContentsToPath("", path);
    }
    BuildTarget target = BuildTargetFactory.newInstance("//base:name");
    TargetNode<?, ?> targetNode = createTargetNode(target, ImmutableSet.of());
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    OwnersReport report = OwnersReport.generateOwnersReport(cell, targetNode, inputs);
    assertTrue(report.owners.isEmpty());
    assertTrue(report.nonFileInputs.isEmpty());
    assertTrue(report.nonExistentInputs.isEmpty());
    assertEquals(inputPaths, report.inputsWithNoOwners);
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 49 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class OwnersReportTest method verifyInputsWithMultipleOwnersAreCorrectlyReported.

/**
   * Verify that owners are correctly detected:
   *  - inputs that belong to multiple targets
   */
@Test
public void verifyInputsWithMultipleOwnersAreCorrectlyReported() throws CmdLineException, IOException, InterruptedException {
    ImmutableSet<String> inputs = ImmutableSet.of("java/somefolder/badfolder/somefile.java", "java/somefolder/perfect.java", "com/test/subtest/random.java");
    ImmutableSet<Path> inputPaths = RichStream.from(inputs).map(filesystem::getPath).toImmutableSet();
    for (Path path : inputPaths) {
        filesystem.mkdirs(path.getParent());
        filesystem.writeContentsToPath("", path);
    }
    BuildTarget target1 = BuildTargetFactory.newInstance("//base/name1:name");
    BuildTarget target2 = BuildTargetFactory.newInstance("//base/name2:name");
    TargetNode<?, ?> targetNode1 = createTargetNode(target1, inputPaths);
    TargetNode<?, ?> targetNode2 = createTargetNode(target2, inputPaths);
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    OwnersReport report = OwnersReport.emptyReport();
    report = report.updatedWith(OwnersReport.generateOwnersReport(cell, targetNode1, inputs));
    report = report.updatedWith(OwnersReport.generateOwnersReport(cell, targetNode2, inputs));
    assertTrue(report.nonFileInputs.isEmpty());
    assertTrue(report.nonExistentInputs.isEmpty());
    assertTrue(report.inputsWithNoOwners.isEmpty());
    assertTrue(report.owners.containsKey(targetNode1));
    assertTrue(report.owners.containsKey(targetNode2));
    assertEquals(targetNode1.getInputs(), report.owners.get(targetNode1));
    assertEquals(targetNode2.getInputs(), report.owners.get(targetNode2));
}
Also used : Path(java.nio.file.Path) BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 50 with TestCellBuilder

use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.

the class OwnersReportTest method verifyPathsThatAreNotFilesAreCorrectlyReported.

@Test
public void verifyPathsThatAreNotFilesAreCorrectlyReported() throws CmdLineException, IOException, InterruptedException {
    filesystem.mkdirs(filesystem.getPath("java/somefolder/badfolder"));
    filesystem.mkdirs(filesystem.getPath("com/test/subtest"));
    // Inputs that should be treated as "non-files", i.e. as directories
    ImmutableSet<String> inputs = ImmutableSet.of("java/somefolder/badfolder", "java/somefolder", "com/test/subtest");
    BuildTarget target = BuildTargetFactory.newInstance("//base:name");
    TargetNode<?, ?> targetNode = createTargetNode(target, ImmutableSet.of());
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    OwnersReport report = OwnersReport.generateOwnersReport(cell, targetNode, inputs);
    assertTrue(report.owners.isEmpty());
    assertTrue(report.nonExistentInputs.isEmpty());
    assertTrue(report.inputsWithNoOwners.isEmpty());
    assertEquals(inputs, report.nonFileInputs);
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Aggregations

TestCellBuilder (com.facebook.buck.rules.TestCellBuilder)50 Cell (com.facebook.buck.rules.Cell)39 Test (org.junit.Test)39 Path (java.nio.file.Path)31 BuckConfig (com.facebook.buck.cli.BuckConfig)29 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)29 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)18 PathSourcePath (com.facebook.buck.rules.PathSourcePath)18 BuildTarget (com.facebook.buck.model.BuildTarget)15 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)14 Before (org.junit.Before)8 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)7 ParserConfig (com.facebook.buck.parser.ParserConfig)7 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)6 TestConsole (com.facebook.buck.testutil.TestConsole)6 FakeAndroidDirectoryResolver (com.facebook.buck.android.FakeAndroidDirectoryResolver)5 Config (com.facebook.buck.config.Config)5 BuckEventBus (com.facebook.buck.event.BuckEventBus)5 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)5 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)5