Search in sources :

Example 31 with ExecutionContext

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

the class PlistProcessStepTest method testMergeFromFileReplacesExistingKey.

@Test
public void testMergeFromFileReplacesExistingKey() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    PlistProcessStep plistProcessStep = new PlistProcessStep(projectFilesystem, INPUT_PATH, Optional.of(MERGE_PATH), OUTPUT_PATH, ImmutableMap.of(), ImmutableMap.of(), PlistProcessStep.OutputFormat.XML);
    NSDictionary dict = new NSDictionary();
    dict.put("Key1", "Value1");
    dict.put("Key2", "Value2");
    projectFilesystem.writeContentsToPath(dict.toXMLPropertyList(), INPUT_PATH);
    NSDictionary overrideDict = new NSDictionary();
    overrideDict.put("Key1", "OverrideValue");
    projectFilesystem.writeContentsToPath(overrideDict.toXMLPropertyList(), MERGE_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) Test(org.junit.Test)

Example 32 with ExecutionContext

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

the class PlistProcessStepTest method testAdditionDoesNotReplaceExistingKey.

@Test
public void testAdditionDoesNotReplaceExistingKey() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    PlistProcessStep plistProcessStep = new PlistProcessStep(projectFilesystem, INPUT_PATH, Optional.empty(), OUTPUT_PATH, ImmutableMap.of("Key1", new NSString("OverrideValue")), ImmutableMap.of(), 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));
    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)

Example 33 with ExecutionContext

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

the class PlistProcessStepTest method testHandlesNonDictionaryPlists.

@Test
public void testHandlesNonDictionaryPlists() 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);
    NSArray array = new NSArray(new NSString("Value1"), new NSString("Value2"));
    projectFilesystem.writeContentsToPath(array.toXMLPropertyList(), INPUT_PATH);
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    int errorCode = plistProcessStep.execute(executionContext).getExitCode();
    assertThat(errorCode, equalTo(0));
    assertThat(projectFilesystem.readFileIfItExists(OUTPUT_PATH), equalTo(Optional.of(array.toXMLPropertyList())));
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) NSArray(com.dd.plist.NSArray) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) NSString(com.dd.plist.NSString) Test(org.junit.Test)

Example 34 with ExecutionContext

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

the class XctoolRunTestsStepTest method xctoolCommandWithOnlyLogicTests.

@Test
public void xctoolCommandWithOnlyLogicTests() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.empty(), ImmutableSet.of(Paths.get("/path/to/Foo.xctest")), ImmutableMap.of(), 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", "run-tests", "-logicTest", "/path/to/Foo.xctest")).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 35 with ExecutionContext

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

the class XctoolRunTestsStepTest method testDirectoryAndLevelPassedInEnvironment.

@Test
public void testDirectoryAndLevelPassedInEnvironment() throws Exception {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    XctoolRunTestsStep step = new XctoolRunTestsStep(projectFilesystem, Paths.get("/path/to/xctool"), ImmutableMap.of(), Optional.empty(), "iphonesimulator", Optional.empty(), ImmutableSet.of(Paths.get("/path/to/Foo.xctest")), ImmutableMap.of(), Paths.get("/path/to/output.json"), Optional.empty(), Suppliers.ofInstance(Optional.of(Paths.get("/path/to/developer/dir"))), TestSelectorList.EMPTY, false, Optional.of("TEST_LOG_PATH"), Optional.of(Paths.get("/path/to/test-logs")), Optional.of("TEST_LOG_LEVEL"), Optional.of("verbose"), Optional.empty(), Optional.of("/path/to/snapshotimages"));
    ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder().setCommand(ImmutableList.of("/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "run-tests", "-logicTest", "/path/to/Foo.xctest")).setEnvironment(ImmutableMap.of("DEVELOPER_DIR", "/path/to/developer/dir", "XCTOOL_TEST_ENV_TEST_LOG_PATH", "/path/to/test-logs", "XCTOOL_TEST_ENV_TEST_LOG_LEVEL", "verbose", "XCTOOL_TEST_ENV_FB_REFERENCE_IMAGE_DIR", "/path/to/snapshotimages")).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)

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