Search in sources :

Example 6 with TestCellBuilder

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

the class DaemonIntegrationTest method whenAndroidNdkVersionChangesParserInvalidated.

@Test
public void whenAndroidNdkVersionChangesParserInvalidated() throws IOException, InterruptedException {
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    BuckConfig buckConfig1 = FakeBuckConfig.builder().setSections(ImmutableMap.of("ndk", ImmutableMap.of("ndk_version", "something"))).build();
    BuckConfig buckConfig2 = FakeBuckConfig.builder().setSections(ImmutableMap.of("ndk", ImmutableMap.of("ndk_version", "different"))).build();
    Object daemon = Main.getDaemon(new TestCellBuilder().setBuckConfig(buckConfig1).setFilesystem(filesystem).build(), ObjectMappers.newDefaultInstance());
    assertNotEquals("Daemon should be replaced when not equal.", daemon, Main.getDaemon(new TestCellBuilder().setBuckConfig(buckConfig2).setFilesystem(filesystem).build(), ObjectMappers.newDefaultInstance()));
}
Also used : ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Test(org.junit.Test)

Example 7 with TestCellBuilder

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

the class OwnersReportTest method verifyInputsAgainstRulesThatListDirectoryInputs.

@Test
public void verifyInputsAgainstRulesThatListDirectoryInputs() throws IOException, InterruptedException {
    // Inputs that should be treated as existing files
    ImmutableSet<String> inputs = ImmutableSet.of("java/somefolder/badfolder/somefile.java", "java/somefolder/perfect.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, ImmutableSet.of(filesystem.getPath("java/somefolder")));
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    OwnersReport report = OwnersReport.generateOwnersReport(cell, targetNode, inputs);
    assertTrue(report.owners.containsKey(targetNode));
    assertEquals(inputPaths, report.owners.get(targetNode));
    assertTrue(report.nonFileInputs.isEmpty());
    assertTrue(report.nonExistentInputs.isEmpty());
    assertTrue(report.inputsWithNoOwners.isEmpty());
}
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 8 with TestCellBuilder

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

the class OwnersReportTest method verifyMissingFilesAreCorrectlyReported.

@Test
public void verifyMissingFilesAreCorrectlyReported() throws CmdLineException, IOException, InterruptedException {
    // Inputs that should be treated as missing files
    ImmutableSet<String> inputs = ImmutableSet.of("java/somefolder/badfolder/somefile.java", "java/somefolder/perfect.java", "com/test/subtest/random.java");
    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.inputsWithNoOwners.isEmpty());
    assertEquals(inputs, report.nonExistentInputs);
}
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 9 with TestCellBuilder

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

the class QueryCommandTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    TestConsole console = new TestConsole();
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "query_command", tmp);
    workspace.setUp();
    ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath().toRealPath().normalize());
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver();
    ArtifactCache artifactCache = new NoopArtifactCache();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    ObjectMapper objectMapper = ObjectMappers.newDefaultInstance();
    queryCommand = new QueryCommand();
    queryCommand.outputAttributes = Suppliers.ofInstance(ImmutableSet.<String>of());
    params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, androidDirectoryResolver, artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
    executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) Before(org.junit.Before)

Example 10 with TestCellBuilder

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

the class TargetsCommandTest method setUp.

@Before
public void setUp() throws IOException, InterruptedException {
    console = new TestConsole();
    workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "target_command", tmp);
    workspace.setUp();
    filesystem = new ProjectFilesystem(workspace.getDestPath().toRealPath().normalize());
    Cell cell = new TestCellBuilder().setFilesystem(filesystem).build();
    AndroidDirectoryResolver androidDirectoryResolver = new FakeAndroidDirectoryResolver();
    ArtifactCache artifactCache = new NoopArtifactCache();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    objectMapper = ObjectMappers.newDefaultInstance();
    targetsCommand = new TargetsCommand();
    params = CommandRunnerParamsForTesting.createCommandRunnerParamsForTesting(console, cell, androidDirectoryResolver, artifactCache, eventBus, FakeBuckConfig.builder().build(), Platform.detect(), ImmutableMap.copyOf(System.getenv()), new FakeJavaPackageFinder(), objectMapper, Optional.empty());
    executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeJavaPackageFinder(com.facebook.buck.jvm.java.FakeJavaPackageFinder) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Cell(com.facebook.buck.rules.Cell) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) ArtifactCache(com.facebook.buck.artifact_cache.ArtifactCache) NoopArtifactCache(com.facebook.buck.artifact_cache.NoopArtifactCache) Before(org.junit.Before)

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