use of com.facebook.buck.model.BuildId in project buck by facebook.
the class JUnitStepTest method ensureThatDebugFlagCausesJavaDebugCommandFlagToBeAdded.
@Test
public void ensureThatDebugFlagCausesJavaDebugCommandFlagToBeAdded() {
String testClass1 = "com.facebook.buck.shell.JUnitCommandTest";
String testClass2 = "com.facebook.buck.shell.InstrumentCommandTest";
Set<String> testClassNames = ImmutableSet.of(testClass1, testClass2);
String vmArg1 = "-Dname1=value1";
String vmArg2 = "-Dname1=value2";
ImmutableList<String> vmArgs = ImmutableList.of(vmArg1, vmArg2);
BuildId pretendBuildId = new BuildId("pretend-build-id");
String buildIdArg = String.format("-Dcom.facebook.buck.buildId=%s", pretendBuildId);
Path modulePath = Paths.get("module/submodule");
String modulePathArg = String.format("-Dcom.facebook.buck.moduleBasePath=%s", modulePath);
Path directoryForTestResults = Paths.get("buck-out/gen/theresults/");
Path testRunnerClasspath = Paths.get("build/classes/junit");
ProjectFilesystem filesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
Path classpathFile = filesystem.resolve("foo");
JUnitJvmArgs args = JUnitJvmArgs.builder().setClasspathFile(classpathFile).setBuildId(pretendBuildId).setBuckModuleBaseSourceCodePath(modulePath).setTestRunnerClasspath(testRunnerClasspath).setDebugEnabled(true).setExtraJvmArgs(vmArgs).setTestType(TestType.JUNIT).setDirectoryForTestResults(directoryForTestResults).addAllTestClasses(testClassNames).build();
JUnitStep junit = new JUnitStep(filesystem, ImmutableMap.of(), /* testRuleTimeoutMs */
Optional.empty(), /* testCaseTimeoutMs */
Optional.empty(), ImmutableMap.of(), new ExternalJavaRuntimeLauncher("/foo/bar/custom/java"), args);
TestConsole console = new TestConsole(Verbosity.ALL);
ExecutionContext executionContext = TestExecutionContext.newBuilder().setConsole(console).setDebugEnabled(true).build();
List<String> observedArgs = junit.getShellCommand(executionContext);
MoreAsserts.assertListEquals(ImmutableList.of("/foo/bar/custom/java", "-Dbuck.testrunner_classes=" + testRunnerClasspath, buildIdArg, modulePathArg, "-Dapple.awt.UIElement=true", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", vmArg1, vmArg2, "-verbose", "-classpath", "@" + classpathFile + File.pathSeparator + MorePaths.pathWithPlatformSeparators("build/classes/junit"), FileClassPathRunner.class.getName(), "com.facebook.buck.testrunner.JUnitMain", "--output", directoryForTestResults.toString(), "--default-test-timeout", "0", testClass1, testClass2), observedArgs);
// TODO(shs96c): Why does the CapturingPrintStream append spaces?
assertEquals("Debugging. Suspending JVM. Connect a JDWP debugger to port 5005 to proceed.", console.getTextWrittenToStdErr().trim());
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class UnskippedRulesTrackerTest method setUp.
@Before
public void setUp() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
sourcePathResolver = new SourcePathResolver(ruleFinder);
ListeningExecutorService executor = listeningDecorator(MostExecutors.newMultiThreadExecutor("UnskippedRulesTracker", 7));
RuleDepsCache depsCache = new RuleDepsCache(executor, resolver);
unskippedRulesTracker = new UnskippedRulesTracker(depsCache, resolver, executor);
eventBus = new BuckEventBus(new FakeClock(1), new BuildId());
eventBus.register(new Object() {
@Subscribe
public void onUnskippedRuleCountUpdated(BuckEvent event) {
events.add(event);
}
});
ruleH = resolver.addToIndex(createRule("//:h"));
ruleG = resolver.addToIndex(createRule("//:g"));
ruleF = resolver.addToIndex(createRule("//:f"));
ruleE = resolver.addToIndex(createRule("//:e", ImmutableSet.of(ruleG, ruleH)));
ruleD = resolver.addToIndex(createRule("//:d", ImmutableSet.of(ruleG), ImmutableSet.of(ruleF)));
ruleC = resolver.addToIndex(createRule("//:c", ImmutableSet.of(ruleD, ruleE)));
ruleB = resolver.addToIndex(createRule("//:b", ImmutableSet.of(), ImmutableSet.of(ruleD)));
ruleA = resolver.addToIndex(createRule("//:a", ImmutableSet.of(ruleD)));
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class TargetGraphHashingTest method twoNodeIndependentRootsTargetGraphHasExpectedHashes.
@Test
public void twoNodeIndependentRootsTargetGraphHasExpectedHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
TargetNode<?, ?> nodeA = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
TargetNode<?, ?> nodeB = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//bar:lib"), HashCode.fromLong(49152), ImmutableSet.of(Paths.get("bar/BarLib.java")));
TargetGraph targetGraphA = TargetGraphFactory.newInstance(nodeA);
TargetGraph targetGraphB = TargetGraphFactory.newInstance(nodeB);
TargetGraph commonTargetGraph = TargetGraphFactory.newInstance(nodeA, nodeB);
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("bar/BarLib.java"), HashCode.fromString("123456")));
Map<BuildTarget, HashCode> resultsA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(nodeA)).hashTargetGraph();
Map<BuildTarget, HashCode> resultsB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(nodeB)).hashTargetGraph();
Map<BuildTarget, HashCode> commonResults = new TargetGraphHashing(eventBus, commonTargetGraph, fileHashCache, ImmutableList.of(nodeA, nodeB)).hashTargetGraph();
assertThat(resultsA, aMapWithSize(1));
assertThat(resultsA, hasKey(nodeA.getBuildTarget()));
assertThat(resultsB, aMapWithSize(1));
assertThat(resultsB, hasKey(nodeB.getBuildTarget()));
assertThat(commonResults, aMapWithSize(2));
assertThat(commonResults, hasKey(nodeA.getBuildTarget()));
assertThat(commonResults, hasKey(nodeB.getBuildTarget()));
assertThat(resultsA.get(nodeA.getBuildTarget()), equalTo(commonResults.get(nodeA.getBuildTarget())));
assertThat(resultsB.get(nodeB.getBuildTarget()), equalTo(commonResults.get(nodeB.getBuildTarget())));
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class TargetGraphHashingTest method emptyTargetGraphHasEmptyHashes.
@Test
public void emptyTargetGraphHasEmptyHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
TargetGraph targetGraph = TargetGraphFactory.newInstance();
assertThat(new TargetGraphHashing(eventBus, targetGraph, new NullFileHashCache(), ImmutableList.of()).hashTargetGraph().entrySet(), empty());
}
use of com.facebook.buck.model.BuildId in project buck by facebook.
the class FakeBuildEngineTest method buildRuleFutureHasResult.
@Test
public void buildRuleFutureHasResult() throws Exception {
BuildTarget fakeBuildTarget = BuildTargetFactory.newInstance("//foo:bar");
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
FakeBuildRule fakeBuildRule = new FakeBuildRule(fakeBuildTarget, pathResolver);
BuildResult fakeBuildResult = BuildResult.success(fakeBuildRule, BUILT_LOCALLY, CacheResult.miss());
FakeBuildEngine fakeEngine = new FakeBuildEngine(ImmutableMap.of(fakeBuildTarget, fakeBuildResult), ImmutableMap.of(fakeBuildTarget, new RuleKey("00")));
assertThat(fakeEngine.build(BuildEngineBuildContext.builder().setBuildContext(FakeBuildContext.NOOP_CONTEXT).setArtifactCache(new NoopArtifactCache()).setBuildId(new BuildId()).setObjectMapper(ObjectMappers.newDefaultInstance()).setClock(new DefaultClock()).build(), TestExecutionContext.newInstance(), fakeBuildRule).get(), equalTo(fakeBuildResult));
}
Aggregations