Search in sources :

Example 61 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext 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 62 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class HeaderMapStepTest method testHeaderMap.

@Test
public void testHeaderMap() throws IOException {
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
    ExecutionContext context = TestExecutionContext.newInstance();
    Path output = Paths.get("headers.hmap");
    ImmutableMap<Path, Path> entries = ImmutableMap.of(Paths.get("file1.h"), Paths.get("/some/absolute/path.h"), Paths.get("file2.h"), Paths.get("/other/absolute/path.h"), Paths.get("prefix/file1.h"), Paths.get("/some/absolute/path.h"));
    HeaderMapStep step = new HeaderMapStep(projectFilesystem, output, entries);
    step.execute(context);
    assertTrue(projectFilesystem.exists(output));
    byte[] headerMapBytes = ByteStreams.toByteArray(projectFilesystem.newFileInputStream(output));
    HeaderMap headerMap = HeaderMap.deserialize(headerMapBytes);
    assertNotNull(headerMap);
    assertThat(headerMap.getNumEntries(), equalTo(entries.size()));
    for (Map.Entry<Path, Path> entry : entries.entrySet()) {
        assertThat(headerMap.lookup(entry.getKey().toString()), equalTo(entry.getValue().toString()));
    }
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HeaderMap(com.facebook.buck.apple.clang.HeaderMap) Test(org.junit.Test)

Example 63 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class EstimateDexWeightStepTest method testExecuteEstimateDexWeightStep.

@Test
public void testExecuteEstimateDexWeightStep() throws IOException {
    // Create a directory.
    String name = "dir";
    tmp.newFolder(name);
    tmp.newFolder("dir", "com");
    tmp.newFolder("dir", "com", "example");
    tmp.newFolder("dir", "com", "example", "subpackage");
    tmp.newFile(pathWithPlatformSeparators("dir/com/example/Foo.class"));
    tmp.newFile(pathWithPlatformSeparators("dir/com/example/Bar.class"));
    tmp.newFile(pathWithPlatformSeparators("dir/com/example/not_a_class.png"));
    tmp.newFile(pathWithPlatformSeparators("dir/com/example/subpackage/Baz.class"));
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot());
    ExecutionContext context = TestExecutionContext.newInstance();
    Path pathToJarOrClassesDirectory = Paths.get(name);
    EstimateDexWeightStep step = new EstimateDexWeightStep(filesystem, pathToJarOrClassesDirectory, dexWeightEstimator);
    int exitCode = step.execute(context).getExitCode();
    assertEquals(0, exitCode);
    assertEquals(Integer.valueOf(425), step.get());
}
Also used : Path(java.nio.file.Path) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 64 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class AccumulateClassNamesStepTest method testExecuteAccumulateClassNamesStepOnJarFile.

@Test
public void testExecuteAccumulateClassNamesStepOnJarFile() throws IOException {
    // Create a JAR file.
    String name = "example.jar";
    File jarFile = tmp.newFile(name);
    try (JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jarFile)))) {
        out.putNextEntry(new ZipEntry("com/example/Foo.class"));
        out.closeEntry();
        out.putNextEntry(new ZipEntry("com/example/Bar.class"));
        out.closeEntry();
        out.putNextEntry(new ZipEntry("com/example/not_a_class.png"));
        out.closeEntry();
        out.putNextEntry(new ZipEntry("com/example/subpackage/Baz.class"));
        out.closeEntry();
    }
    // Create the AccumulateClassNamesStep and execute it.
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot().toPath());
    AccumulateClassNamesStep accumulateClassNamesStep = new AccumulateClassNamesStep(filesystem, Optional.of(Paths.get(name)), Paths.get("output.txt"));
    ExecutionContext context = TestExecutionContext.newInstance();
    accumulateClassNamesStep.execute(context);
    String contents = Files.toString(new File(tmp.getRoot(), "output.txt"), Charsets.UTF_8);
    String separator = AccumulateClassNamesStep.CLASS_NAME_HASH_CODE_SEPARATOR;
    assertEquals("Verify that the contents are sorted alphabetically and ignore non-.class files.", Joiner.on('\n').join("com/example/Bar" + separator + SHA1_FOR_EMPTY_STRING, "com/example/Foo" + separator + SHA1_FOR_EMPTY_STRING, "com/example/subpackage/Baz" + separator + SHA1_FOR_EMPTY_STRING) + '\n', contents);
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) Test(org.junit.Test)

Example 65 with ExecutionContext

use of com.facebook.buck.step.ExecutionContext in project buck by facebook.

the class AccumulateClassNamesStepTest method testExecuteAccumulateClassNamesStepOnDirectory.

@Test
public void testExecuteAccumulateClassNamesStepOnDirectory() throws IOException {
    // Create a directory.
    String name = "dir";
    tmp.newFolder(name);
    tmp.newFolder("dir", "com");
    tmp.newFolder("dir", "com", "example");
    tmp.newFolder("dir", "com", "example", "subpackage");
    tmp.newFile("dir/com/example/Foo.class");
    tmp.newFile("dir/com/example/Bar.class");
    tmp.newFile("dir/com/example/not_a_class.png");
    tmp.newFile("dir/com/example/subpackage/Baz.class");
    // Create the AccumulateClassNamesStep and execute it.
    ProjectFilesystem filesystem = new ProjectFilesystem(tmp.getRoot().toPath());
    AccumulateClassNamesStep accumulateClassNamesStep = new AccumulateClassNamesStep(filesystem, Optional.of(Paths.get(name)), Paths.get("output.txt"));
    ExecutionContext context = TestExecutionContext.newInstance();
    accumulateClassNamesStep.execute(context);
    String contents = Files.toString(new File(tmp.getRoot(), "output.txt"), Charsets.UTF_8);
    String separator = AccumulateClassNamesStep.CLASS_NAME_HASH_CODE_SEPARATOR;
    assertEquals("Verify that the contents are sorted alphabetically and ignore non-.class files.", Joiner.on('\n').join(MorePaths.pathWithUnixSeparators(Paths.get("com/example/Bar")) + separator + SHA1_FOR_EMPTY_STRING, MorePaths.pathWithUnixSeparators(Paths.get("com/example/Foo")) + separator + SHA1_FOR_EMPTY_STRING, MorePaths.pathWithUnixSeparators(Paths.get("com/example/subpackage/Baz")) + separator + SHA1_FOR_EMPTY_STRING) + '\n', contents);
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) File(java.io.File) Test(org.junit.Test)

Aggregations

ExecutionContext (com.facebook.buck.step.ExecutionContext)176 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)140 Test (org.junit.Test)128 Path (java.nio.file.Path)79 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)67 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)66 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)55 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)50 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)45 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)44 Step (com.facebook.buck.step.Step)34 ImmutableList (com.google.common.collect.ImmutableList)32 BuildTarget (com.facebook.buck.model.BuildTarget)31 SourcePath (com.facebook.buck.rules.SourcePath)26 TestConsole (com.facebook.buck.testutil.TestConsole)25 FakeProcess (com.facebook.buck.util.FakeProcess)21 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)20 ImmutableMap (com.google.common.collect.ImmutableMap)20 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)19 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)19