use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class CacheCommandTest method testRunCommandAndFetchArtifactsSuccessfully.
@Test
public void testRunCommandAndFetchArtifactsSuccessfully() throws IOException, InterruptedException {
final String ruleKeyHash = "b64009ae3762a42a1651c139ec452f0d18f48e21";
ArtifactCache cache = createMock(ArtifactCache.class);
expect(cache.fetch(eq(new RuleKey(ruleKeyHash)), isA(LazyPath.class))).andReturn(CacheResult.hit("http"));
TestConsole console = new TestConsole();
CommandRunnerParams commandRunnerParams = CommandRunnerParamsForTesting.builder().setConsole(console).setArtifactCache(cache).build();
replayAll();
CacheCommand cacheCommand = new CacheCommand();
cacheCommand.setArguments(ImmutableList.of(ruleKeyHash));
int exitCode = cacheCommand.run(commandRunnerParams);
assertEquals(0, exitCode);
assertThat(console.getTextWrittenToStdErr(), startsWith("Successfully downloaded artifact with id " + ruleKeyHash + " at "));
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class CacheCommandTest method testRunCommandWithNoArguments.
@Test
public void testRunCommandWithNoArguments() throws IOException, InterruptedException {
TestConsole console = new TestConsole();
console.printErrorText("No cache keys specified.");
CommandRunnerParams commandRunnerParams = CommandRunnerParamsForTesting.builder().setConsole(console).build();
CacheCommand cacheCommand = new CacheCommand();
int exitCode = cacheCommand.run(commandRunnerParams);
assertEquals(1, exitCode);
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class CacheCommandTest method testRunCommandAndFetchArtifactsUnsuccessfully.
@Test
public void testRunCommandAndFetchArtifactsUnsuccessfully() throws IOException, InterruptedException {
final String ruleKeyHash = "b64009ae3762a42a1651c139ec452f0d18f48e21";
ArtifactCache cache = createMock(ArtifactCache.class);
expect(cache.fetch(eq(new RuleKey(ruleKeyHash)), isA(LazyPath.class))).andReturn(CacheResult.miss());
TestConsole console = new TestConsole();
console.printErrorText("Failed to retrieve an artifact with id " + ruleKeyHash + ".");
CommandRunnerParams commandRunnerParams = CommandRunnerParamsForTesting.builder().setConsole(console).setArtifactCache(cache).build();
replayAll();
CacheCommand cacheCommand = new CacheCommand();
cacheCommand.setArguments(ImmutableList.of(ruleKeyHash));
int exitCode = cacheCommand.run(commandRunnerParams);
assertEquals(1, exitCode);
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class JavacStepTest method failedCompileSendsStdoutAndStderrToConsole.
@Test
public void failedCompileSendsStdoutAndStderrToConsole() throws Exception {
FakeJavac fakeJavac = new FakeJavac();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").build();
ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
FakeProcess fakeJavacProcess = new FakeProcess(1, "javac stdout\n", "javac stderr\n");
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
executionContext.getBuckEventBus().register(listener);
StepExecutionResult result = step.execute(executionContext);
// JavacStep itself writes stdout to the console on error; we expect the Build class to write
// the stderr stream returned in the StepExecutionResult
assertThat(result, equalTo(StepExecutionResult.of(1, Optional.of("javac stderr\n"))));
assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("javac stdout\n")));
}
use of com.facebook.buck.testutil.TestConsole in project buck by facebook.
the class JavacStepTest method existingBootclasspathDirSucceeds.
@Test
public void existingBootclasspathDirSucceeds() throws Exception {
FakeJavac fakeJavac = new FakeJavac();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").setBootclasspath("/this-totally-exists").build();
ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> true, file -> false, (path, glob) -> ImmutableSet.of());
JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
FakeProcess fakeJavacProcess = new FakeProcess(0, "javac stdout\n", "javac stderr\n");
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
executionContext.getBuckEventBus().register(listener);
StepExecutionResult result = step.execute(executionContext);
assertThat(result, equalTo(StepExecutionResult.SUCCESS));
assertThat(listener.getLogMessages(), empty());
}
Aggregations