use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class XctoolRunTestsStepTest method xctoolCommandWithAppAndLogicTests.
@Test
public void xctoolCommandWithAppAndLogicTests() throws Exception {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.of("name=iPhone 5s,OS=8.2"), ImmutableSet.of(Paths.get("/path/to/FooLogicTest.xctest")), ImmutableMap.of(Paths.get("/path/to/FooAppTest.xctest"), Paths.get("/path/to/Foo.app")), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.EMPTY, false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "-destination", "name=iPhone 5s,OS=8.2", "run-tests", "-logicTest", "/path/to/FooLogicTest.xctest", "-appTest", "/path/to/FooAppTest.xctest:/path/to/Foo.app")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
FakeProcess fakeXctoolSuccess = new FakeProcess(0, "", "");
FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolParams, fakeXctoolSuccess));
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).build();
assertThat(step.execute(executionContext).getExitCode(), equalTo(0));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class XctoolRunTestsStepTest method xctoolCommandWithOnlyAppTests.
@Test
public void xctoolCommandWithOnlyAppTests() throws Exception {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.of("name=iPhone 5s"), ImmutableSet.of(), ImmutableMap.of(Paths.get("/path/to/FooAppTest.xctest"), Paths.get("/path/to/Foo.app")), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.EMPTY, false, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "-destination", "name=iPhone 5s", "run-tests", "-appTest", "/path/to/FooAppTest.xctest:/path/to/Foo.app")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir")).setDirectory(projectFilesystem.getRootPath().toAbsolutePath()).setRedirectOutput(ProcessBuilder.Redirect.PIPE).build();
FakeProcess fakeXctoolSuccess = new FakeProcess(0, "", "");
FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolParams, fakeXctoolSuccess));
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(processExecutor).setEnvironment(ImmutableMap.of()).build();
assertThat(step.execute(executionContext).getExitCode(), equalTo(0));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ProjectGeneratorTest method setUp.
@Before
public void setUp() throws InterruptedException, IOException {
assumeTrue(Platform.detect() == Platform.MACOS || Platform.detect() == Platform.LINUX);
clock = new SettableFakeClock(0, 0);
fakeProjectFilesystem = new FakeProjectFilesystem(clock);
projectCell = (new TestCellBuilder()).setFilesystem(fakeProjectFilesystem).build();
projectFilesystem = projectCell.getFilesystem();
rootPath = projectFilesystem.getRootPath();
// Add files and directories used to test resources.
projectFilesystem.createParentDirs(Paths.get("foodir", "foo.png"));
projectFilesystem.writeContentsToPath("", Paths.get("foodir", "foo.png"));
projectFilesystem.writeContentsToPath("", Paths.get("bar.png"));
fakeProjectFilesystem.touch(Paths.get("Base.lproj", "Bar.storyboard"));
halideBuckConfig = HalideLibraryBuilder.createDefaultHalideConfig(fakeProjectFilesystem);
ImmutableMap<String, ImmutableMap<String, String>> sections = ImmutableMap.of("cxx", ImmutableMap.of("cflags", "-Wno-deprecated -Wno-conversion", "cxxflags", "-Wundeclared-selector -Wno-objc-designated-initializers"), "apple", ImmutableMap.of("force_dsym_mode_in_build_with_buck", "false"), "swift", ImmutableMap.of("version", "1.23"));
BuckConfig config = FakeBuckConfig.builder().setSections(sections).build();
cxxBuckConfig = new CxxBuckConfig(config);
appleConfig = new AppleConfig(config);
swiftBuckConfig = new SwiftBuckConfig(config);
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class ProjectGeneratorTest method testAggregateTargetForBundleForBuildWithBuck.
@Test
public void testAggregateTargetForBundleForBuildWithBuck() throws IOException {
BuildTarget binaryTarget = BuildTarget.builder(rootPath, "//foo", "binary").build();
TargetNode<?, ?> binaryNode = AppleBinaryBuilder.createBuilder(binaryTarget).setConfigs(ImmutableSortedMap.of("Debug", ImmutableMap.of())).build();
BuildTarget bundleTarget = BuildTarget.builder(rootPath, "//foo", "bundle").build();
TargetNode<?, ?> bundleNode = AppleBundleBuilder.createBuilder(bundleTarget).setExtension(Either.ofLeft(AppleBundleExtension.APP)).setInfoPlist(new FakeSourcePath("Info.plist")).setBinary(binaryTarget).build();
ImmutableSet<TargetNode<?, ?>> nodes = ImmutableSet.of(bundleNode, binaryNode);
final TargetGraph targetGraph = TargetGraphFactory.newInstance(nodes);
final AppleDependenciesCache cache = new AppleDependenciesCache(targetGraph);
ProjectGenerator projectGenerator = new ProjectGenerator(targetGraph, cache, nodes.stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()), projectCell, OUTPUT_DIRECTORY, PROJECT_NAME, "BUCK", ImmutableSet.of(), Optional.of(bundleTarget), ImmutableList.of("--flag", "value with spaces"), false, Optional.empty(), ImmutableSet.of(), Optional.empty(), new AlwaysFoundExecutableFinder(), ImmutableMap.of(), PLATFORMS, DEFAULT_PLATFORM, getBuildRuleResolverNodeFunction(targetGraph), getFakeBuckEventBus(), halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig);
projectGenerator.createXcodeProjects();
PBXTarget buildWithBuckTarget = null;
for (PBXTarget target : projectGenerator.getGeneratedProject().getTargets()) {
if (target.getProductName() != null && target.getProductName().endsWith("-Buck")) {
buildWithBuckTarget = target;
}
}
assertThat(buildWithBuckTarget, is(notNullValue()));
assertHasConfigurations(buildWithBuckTarget, "Debug");
assertKeepsConfigurationsInMainGroup(projectGenerator.getGeneratedProject(), buildWithBuckTarget);
ProjectFilesystem filesystem = new FakeProjectFilesystem();
assertEquals("Should have exact number of build phases", 2, buildWithBuckTarget.getBuildPhases().size());
PBXBuildPhase buildPhase = Iterables.get(buildWithBuckTarget.getBuildPhases(), 0);
assertThat(buildPhase, instanceOf(PBXShellScriptBuildPhase.class));
PBXShellScriptBuildPhase shellScriptBuildPhase = (PBXShellScriptBuildPhase) buildPhase;
assertThat(shellScriptBuildPhase.getShellScript(), containsString("-- \"--show-output --report-absolute-paths --flag 'value with spaces'\" " + bundleTarget.getFullyQualifiedName() + " dwarf dwarf-and-dsym"));
Path fixUUIDScriptPath = ProjectGenerator.getFixUUIDScriptPath(filesystem);
assertThat(shellScriptBuildPhase.getShellScript(), containsString("python " + fixUUIDScriptPath + " --verbose " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app") + " " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.dSYM") + " " + bundleTarget.getShortName()));
assertThat(shellScriptBuildPhase.getShellScript(), containsString("machoutils absolutify_object_paths --binary $BUCK_BUNDLE_OUTPUT_PATH/bundle " + "--output " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app/bundle") + " --old_compdir " + "\"./////////////////////"));
// skipping some slashes: ".//////////// ..... ///////"
assertThat(shellScriptBuildPhase.getShellScript(), containsString("////////\" --new_compdir \"" + filesystem.getRootPath().toString() + "\""));
PBXBuildPhase codesignPhase = buildWithBuckTarget.getBuildPhases().get(1);
assertThat(codesignPhase, instanceOf(PBXShellScriptBuildPhase.class));
PBXShellScriptBuildPhase codesignShellScriptPhase = (PBXShellScriptBuildPhase) codesignPhase;
Path codesignScriptPath = ProjectGenerator.getCodesignScriptPath(filesystem);
assertThat(codesignShellScriptPhase.getShellScript(), containsString("python " + codesignScriptPath + " /usr/bin/codesign " + filesystem.resolve(filesystem.getBuckPaths().getBuckOut()).resolve("bin/foo/bundle-unsanitised/bundle.app")));
}
use of com.facebook.buck.testutil.FakeProjectFilesystem in project buck by facebook.
the class PlistProcessStepTest method testOverrideReplacesExistingKey.
@Test
public void testOverrideReplacesExistingKey() throws Exception {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
PlistProcessStep plistProcessStep = new PlistProcessStep(projectFilesystem, INPUT_PATH, Optional.empty(), OUTPUT_PATH, ImmutableMap.of(), ImmutableMap.of("Key1", new NSString("OverrideValue")), PlistProcessStep.OutputFormat.XML);
NSDictionary dict = new NSDictionary();
dict.put("Key1", "Value1");
dict.put("Key2", "Value2");
projectFilesystem.writeContentsToPath(dict.toXMLPropertyList(), INPUT_PATH);
ExecutionContext executionContext = TestExecutionContext.newInstance();
int errorCode = plistProcessStep.execute(executionContext).getExitCode();
assertThat(errorCode, equalTo(0));
dict.put("Key1", "OverrideValue");
assertThat(projectFilesystem.readFileIfItExists(OUTPUT_PATH), equalTo(Optional.of(dict.toXMLPropertyList())));
}
Aggregations