Search in sources :

Example 26 with FakeProjectFilesystem

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));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 27 with FakeProjectFilesystem

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));
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProcessExecutor(com.facebook.buck.util.FakeProcessExecutor) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProcess(com.facebook.buck.util.FakeProcess) Test(org.junit.Test)

Example 28 with FakeProjectFilesystem

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);
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) ReactNativeBuckConfig(com.facebook.buck.js.ReactNativeBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) HalideBuckConfig(com.facebook.buck.halide.HalideBuckConfig) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SettableFakeClock(com.facebook.buck.timing.SettableFakeClock) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NSString(com.dd.plist.NSString) SwiftBuckConfig(com.facebook.buck.swift.SwiftBuckConfig) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) ImmutableMap(com.google.common.collect.ImmutableMap) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Before(org.junit.Before)

Example 29 with FakeProjectFilesystem

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")));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) PBXTarget(com.facebook.buck.apple.xcode.xcodeproj.PBXTarget) SourceTreePath(com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) TargetNode(com.facebook.buck.rules.TargetNode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) TargetGraph(com.facebook.buck.rules.TargetGraph) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) PBXShellScriptBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXShellScriptBuildPhase) BuildTarget(com.facebook.buck.model.BuildTarget) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase) AppleDependenciesCache(com.facebook.buck.apple.AppleDependenciesCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Test(org.junit.Test)

Example 30 with FakeProjectFilesystem

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())));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) NSDictionary(com.dd.plist.NSDictionary) NSString(com.dd.plist.NSString) Test(org.junit.Test)

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