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));
}
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()));
}
}
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());
}
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);
}
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);
}
Aggregations