Search in sources :

Example 76 with FakeProjectFilesystem

use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.

the class CxxTestStepTest method setUp.

@Before
public void setUp() throws IOException {
    exitCode = tmpDir.newFile("exitCode").toPath();
    output = tmpDir.newFile("output").toPath();
    context = TestExecutionContext.newInstance();
    filesystem = new FakeProjectFilesystem();
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) Before(org.junit.Before)

Example 77 with FakeProjectFilesystem

use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.

the class CxxTestTest method runTests.

@Test
public void runTests() {
    final ImmutableList<String> command = ImmutableList.of("hello", "world");
    FakeCxxTest cxxTest = new FakeCxxTest() {

        @Override
        public SourcePath getSourcePathToOutput() {
            return new ExplicitBuildTargetSourcePath(getBuildTarget(), Paths.get("output"));
        }

        @Override
        protected ImmutableList<String> getShellCommand(SourcePathResolver resolver, Path output) {
            return command;
        }

        @Override
        public Tool getExecutableCommand() {
            CommandTool.Builder builder = new CommandTool.Builder();
            command.forEach(builder::addArg);
            return builder.build();
        }
    };
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    TestRunningOptions options = TestRunningOptions.builder().setTestSelectorList(TestSelectorList.empty()).build();
    ImmutableList<Step> actualSteps = cxxTest.runTests(executionContext, options, createMock(SourcePathResolver.class), FakeTestRule.NOOP_REPORTING_CALLBACK);
    CxxTestStep cxxTestStep = new CxxTestStep(new FakeProjectFilesystem(), command, ImmutableMap.of(), cxxTest.getPathToTestExitCode(), cxxTest.getPathToTestOutput(), TEST_TIMEOUT_MS);
    assertEquals(cxxTestStep, Iterables.getLast(actualSteps));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) TestRunningOptions(com.facebook.buck.test.TestRunningOptions) Step(com.facebook.buck.step.Step) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) CommandTool(com.facebook.buck.rules.CommandTool) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) Test(org.junit.Test)

Example 78 with FakeProjectFilesystem

use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.

the class DirectHeaderMapTest method setUp.

@Before
public void setUp() throws Exception {
    projectFilesystem = new FakeProjectFilesystem(tmpDir.getRoot());
    // Create a build target to use when building the symlink tree.
    buildTarget = BuildTargetFactory.newInstance("//test:test");
    // Get the first file we're symlinking
    Path link1 = Paths.get("file");
    file1 = tmpDir.newFile();
    Files.write(file1, "hello world".getBytes(Charsets.UTF_8));
    // Get the second file we're symlinking
    Path link2 = Paths.get("directory", "then", "file");
    file2 = tmpDir.newFile();
    Files.write(file2, "hello world".getBytes(Charsets.UTF_8));
    // Setup the map representing the link tree.
    links = ImmutableMap.of(link1, new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), file1)), link2, new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), file2)));
    // The output path used by the buildable for the link tree.
    symlinkTreeRoot = BuildTargets.getGenPath(projectFilesystem, buildTarget, "%s/symlink-tree-root");
    // Setup the symlink tree buildable.
    ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    ruleFinder = new SourcePathRuleFinder(ruleResolver);
    pathResolver = new SourcePathResolver(ruleFinder);
    buildRule = new DirectHeaderMap(buildTarget, projectFilesystem, symlinkTreeRoot, links, ruleFinder);
    ruleResolver.addToIndex(buildRule);
    headerMapPath = pathResolver.getRelativePath(buildRule.getSourcePathToOutput());
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Before(org.junit.Before)

Example 79 with FakeProjectFilesystem

use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.

the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeBuildSteps.

@Test
public void testSymlinkTreeBuildSteps() throws IOException {
    BuildContext buildContext = FakeBuildContext.withSourcePathResolver(resolver);
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    FakeBuildableContext buildableContext = new FakeBuildableContext();
    ImmutableList<Step> expectedBuildSteps = ImmutableList.of(new MakeCleanDirectoryStep(filesystem, symlinkTreeRoot), new SymlinkTreeStep(filesystem, symlinkTreeRoot, resolver.getMappedPaths(links)), new HeaderMapStep(filesystem, HeaderSymlinkTreeWithHeaderMap.getPath(filesystem, buildTarget), ImmutableMap.of(Paths.get("file"), filesystem.getBuckPaths().getBuckOut().relativize(symlinkTreeRoot).resolve("file"), Paths.get("directory/then/file"), filesystem.getBuckPaths().getBuckOut().relativize(symlinkTreeRoot).resolve("directory/then/file"))));
    ImmutableList<Step> actualBuildSteps = symlinkTreeBuildRule.getBuildSteps(buildContext, buildableContext);
    assertEquals(expectedBuildSteps, actualBuildSteps.subList(1, actualBuildSteps.size()));
}
Also used : FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) BuildContext(com.facebook.buck.rules.BuildContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) SymlinkTreeStep(com.facebook.buck.step.fs.SymlinkTreeStep) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Step(com.facebook.buck.step.Step) SymlinkTreeStep(com.facebook.buck.step.fs.SymlinkTreeStep) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) Test(org.junit.Test)

Example 80 with FakeProjectFilesystem

use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.

the class HeaderSymlinkTreeWithHeaderMapTest method setUp.

@Before
public void setUp() throws Exception {
    projectFilesystem = new FakeProjectFilesystem(tmpDir.getRoot());
    // Create a build target to use when building the symlink tree.
    buildTarget = BuildTargetFactory.newInstance("//test:test");
    // Get the first file we're symlinking
    Path link1 = Paths.get("file");
    Path file1 = tmpDir.newFile();
    Files.write(file1, "hello world".getBytes(Charsets.UTF_8));
    // Get the second file we're symlinking
    Path link2 = Paths.get("directory", "then", "file");
    Path file2 = tmpDir.newFile();
    Files.write(file2, "hello world".getBytes(Charsets.UTF_8));
    // Setup the map representing the link tree.
    links = ImmutableMap.of(link1, new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), file1)), link2, new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), file2)));
    // The output path used by the buildable for the link tree.
    symlinkTreeRoot = BuildTargets.getGenPath(projectFilesystem, buildTarget, "%s/symlink-tree-root");
    ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    ruleFinder = new SourcePathRuleFinder(ruleResolver);
    resolver = new SourcePathResolver(ruleFinder);
    // Setup the symlink tree buildable.
    symlinkTreeBuildRule = HeaderSymlinkTreeWithHeaderMap.create(buildTarget, projectFilesystem, symlinkTreeRoot, links, ruleFinder);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Before(org.junit.Before)

Aggregations

FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)438 Test (org.junit.Test)384 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)268 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)189 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)186 Path (java.nio.file.Path)169 BuildTarget (com.facebook.buck.model.BuildTarget)138 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)111 TargetGraph (com.facebook.buck.rules.TargetGraph)107 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)103 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)85 PathSourcePath (com.facebook.buck.rules.PathSourcePath)68 BuildRule (com.facebook.buck.rules.BuildRule)61 SourcePath (com.facebook.buck.rules.SourcePath)56 RuleKey (com.facebook.buck.rules.RuleKey)42 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)40 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)39 ExecutionContext (com.facebook.buck.step.ExecutionContext)38 Before (org.junit.Before)30 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)29