Search in sources :

Example 66 with TestConsole

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

the class AaptStepTest method createTestExecutionContext.

/**
   * Create an execution context with the given verbosity level. The execution context
   * will yield fake values relative to the base path for all target queries.
   * The mock context returned has not been replayed, so the calling code
   * may add additional expectations, and is responsible for calling replay().
   */
private ExecutionContext createTestExecutionContext(Verbosity verbosity) {
    final AndroidPlatformTarget androidPlatformTarget = createMock(AndroidPlatformTarget.class);
    expect(androidPlatformTarget.getAaptExecutable()).andReturn(basePath.resolve("mock_aapt_bin"));
    expect(androidPlatformTarget.getAndroidJar()).andReturn(basePath.resolve("mock_android.jar"));
    replay(androidPlatformTarget);
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setConsole(new TestConsole(verbosity)).setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatformTarget)).build();
    return executionContext;
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 67 with TestConsole

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

the class AdbHelperTest method testNonQuietShowsOutput.

@Test
public void testNonQuietShowsOutput() throws InterruptedException {
    final File apk = new File("/some/file.apk");
    final AtomicReference<String> apkPath = new AtomicReference<>();
    TestDevice device = new TestDevice() {

        @Override
        public void installPackage(String s, boolean b, String... strings) throws InstallException {
            apkPath.set(s);
        }
    };
    device.setSerialNumber("serial#1");
    device.setName("testDevice");
    final List<IDevice> deviceList = Lists.newArrayList((IDevice) device);
    TestConsole console = new TestConsole();
    BuckEventBus eventBus = BuckEventBusFactory.newInstance();
    AdbHelper adbHelper = new AdbHelper(new AdbOptions(), new TargetDeviceOptions(), TestExecutionContext.newInstance(), console, eventBus, true) {

        @Override
        protected boolean isDeviceTempWritable(IDevice device, String name) {
            return true;
        }

        @Override
        public List<IDevice> getDevices(boolean quiet) {
            return deviceList;
        }
    };
    boolean success = adbHelper.adbCall(new AdbHelper.AdbCallable() {

        @Override
        public boolean call(IDevice device) throws Exception {
            return basicAdbHelper.installApkOnDevice(device, apk, false, false);
        }

        @Override
        public String toString() {
            return "install apk";
        }
    }, false);
    assertTrue(success);
    assertEquals(apk.getAbsolutePath(), apkPath.get());
    assertEquals("", console.getTextWrittenToStdOut());
    assertEquals("Successfully ran install apk on 1 device(s)\n", console.getTextWrittenToStdErr());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) IDevice(com.android.ddmlib.IDevice) AtomicReference(java.util.concurrent.atomic.AtomicReference) AdbOptions(com.facebook.buck.step.AdbOptions) CmdLineException(org.kohsuke.args4j.CmdLineException) InstallException(com.android.ddmlib.InstallException) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) TestConsole(com.facebook.buck.testutil.TestConsole) File(java.io.File) Test(org.junit.Test)

Example 68 with TestConsole

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

the class BuiltinApplePackageIntegrationTest method packageSupportsFatBinaries.

@Test
public void packageSupportsFatBinaries() throws IOException, InterruptedException {
    assumeTrue(Platform.detect() == Platform.MACOS);
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple_application_bundle_no_debug", tmp);
    workspace.setUp();
    BuildTarget packageTarget = BuildTargetFactory.newInstance("//:DemoAppPackage#iphonesimulator-i386,iphonesimulator-x86_64");
    workspace.runBuckCommand("build", packageTarget.getFullyQualifiedName()).assertSuccess();
    Unzip.extractZipFile(workspace.getPath(BuildTargets.getGenPath(filesystem, packageTarget, "%s.ipa")), workspace.getDestPath(), Unzip.ExistingFileMode.OVERWRITE_AND_CLEAN_DIRECTORIES);
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("lipo", "-info", workspace.getDestPath().resolve("Payload/DemoApp.app/DemoApp").toString())).build();
    // Specify that stdout is expected, or else output may be wrapped in Ansi escape chars.
    Set<ProcessExecutor.Option> options = EnumSet.of(ProcessExecutor.Option.EXPECTING_STD_OUT, ProcessExecutor.Option.IS_SILENT);
    ProcessExecutor.Result result = executor.launchAndExecute(processExecutorParams, options, /* stdin */
    Optional.empty(), /* timeOutMs */
    Optional.empty(), /* timeOutHandler */
    Optional.empty());
    assertEquals(result.getExitCode(), 0);
    assertTrue(result.getStdout().isPresent());
    String output = result.getStdout().get();
    assertTrue(output.contains("i386"));
    assertTrue(output.contains("x86_64"));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) BuildTarget(com.facebook.buck.model.BuildTarget) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 69 with TestConsole

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

the class AppleNativeIntegrationTestUtils method discoverSystemSdkPaths.

private static ImmutableMap<AppleSdk, AppleSdkPaths> discoverSystemSdkPaths(BuckConfig buckConfig) {
    AppleConfig appleConfig = new AppleConfig(buckConfig);
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    return appleConfig.getAppleSdkPaths(executor);
}
Also used : DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 70 with TestConsole

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

the class ProvisioningProfileCopyStepTest method testFailsWithNoSuitableProfilesFound.

@Test
public void testFailsWithNoSuitableProfilesFound() throws Exception {
    assumeTrue(Platform.detect() == Platform.MACOS);
    thrown.expect(HumanReadableException.class);
    thrown.expectMessage("No valid non-expired provisioning profiles match for *.com.example.TestApp");
    Path emptyDir = TestDataHelper.getTestDataDirectory(this).resolve("provisioning_profiles_empty");
    ProvisioningProfileCopyStep step = new ProvisioningProfileCopyStep(projectFilesystem, testdataDir.resolve("Info.plist"), ApplePlatform.IPHONEOS, Optional.empty(), Optional.empty(), ProvisioningProfileStore.fromSearchPath(new DefaultProcessExecutor(new TestConsole()), ProvisioningProfileStore.DEFAULT_READ_COMMAND, emptyDir), outputFile, xcentFile, codeSignIdentityStore, Optional.empty());
    step.execute(executionContext);
}
Also used : Path(java.nio.file.Path) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Aggregations

TestConsole (com.facebook.buck.testutil.TestConsole)100 Test (org.junit.Test)74 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)27 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)27 ExecutionContext (com.facebook.buck.step.ExecutionContext)25 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)25 Path (java.nio.file.Path)21 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)16 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)16 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)16 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)16 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)16 BuckEventBus (com.facebook.buck.event.BuckEventBus)15 FakeProcess (com.facebook.buck.util.FakeProcess)14 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)13 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)12 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)11 Clock (com.facebook.buck.timing.Clock)10 FakeProcessExecutor (com.facebook.buck.util.FakeProcessExecutor)9 BuildTarget (com.facebook.buck.model.BuildTarget)8