use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class JavaSourceJarTest method shouldOnlyIncludePathBasedSources.
@Test
public void shouldOnlyIncludePathBasedSources() {
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
SourcePath fileBased = new FakeSourcePath("some/path/File.java");
SourcePath ruleBased = new DefaultBuildTargetSourcePath(BuildTargetFactory.newInstance("//cheese:cake"));
JavaPackageFinder finderStub = createNiceMock(JavaPackageFinder.class);
expect(finderStub.findJavaPackageFolder((Path) anyObject())).andStubReturn(Paths.get("cheese"));
expect(finderStub.findJavaPackage((Path) anyObject())).andStubReturn("cheese");
// No need to verify. It's a stub. I don't care about the interactions.
EasyMock.replay(finderStub);
JavaSourceJar rule = new JavaSourceJar(new FakeBuildRuleParamsBuilder("//example:target").build(), ImmutableSortedSet.of(fileBased, ruleBased), Optional.empty());
BuildContext buildContext = BuildContext.builder().setActionGraph(new ActionGraph(ImmutableList.of())).setSourcePathResolver(pathResolver).setJavaPackageFinder(finderStub).setEventBus(BuckEventBusFactory.newInstance()).build();
ImmutableList<Step> steps = rule.getBuildSteps(buildContext, new FakeBuildableContext());
// There should be a CopyStep per file being copied. Count 'em.
int copyStepsCount = FluentIterable.from(steps).filter(CopyStep.class::isInstance).size();
assertEquals(1, copyStepsCount);
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges.
@Test
public void ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final Path output = Paths.get("output");
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build();
BuildRule rule = new NoopBuildRule(params) {
@AddToRuleKey
RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(new PathSourcePath(filesystem, output));
};
// Build a rule key with a particular hash set for the output for the above rule.
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0)));
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
// Now, build a rule key with a different hash for the output for the above rule.
hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1)));
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class ExecutableMacroExpanderTest method testBuildTimeDependencies.
@Test
public void testBuildTimeDependencies() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
final BuildRule dep1 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep1")).setOut("arg1").build(ruleResolver, filesystem);
final BuildRule dep2 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep2")).setOut("arg2").build(ruleResolver, filesystem);
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
ruleResolver.addToIndex(new NoopBinaryBuildRule(params) {
@Override
public Tool getExecutableCommand() {
return new CommandTool.Builder().addArg(SourcePathArg.of(dep1.getSourcePathToOutput())).addArg(SourcePathArg.of(dep2.getSourcePathToOutput())).build();
}
});
// Verify that the correct cmd was created.
ExecutableMacroExpander expander = new ExecutableMacroExpander();
assertThat(expander.extractBuildTimeDeps(target, createCellRoots(filesystem), ruleResolver, ImmutableList.of("//:rule")), Matchers.containsInAnyOrder(dep1, dep2));
assertThat(expander.expand(target, createCellRoots(filesystem), ruleResolver, ImmutableList.of("//:rule")), Matchers.equalTo(String.format("%s %s", pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep1.getSourcePathToOutput())), pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep2.getSourcePathToOutput())))));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class ExecutableMacroExpanderTest method extractRuleKeyAppendable.
@Test
public void extractRuleKeyAppendable() throws MacroException {
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildTarget target = BuildTargetFactory.newInstance("//:rule");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
final Tool tool = new CommandTool.Builder().addArg("command").build();
ruleResolver.addToIndex(new NoopBinaryBuildRule(params) {
@Override
public Tool getExecutableCommand() {
return tool;
}
});
ExecutableMacroExpander expander = new ExecutableMacroExpander();
assertThat(expander.extractRuleKeyAppendables(target, createCellRoots(params.getProjectFilesystem()), ruleResolver, ImmutableList.of("//:rule")), Matchers.equalTo(tool));
}
use of com.facebook.buck.rules.FakeBuildRuleParamsBuilder in project buck by facebook.
the class ShTestTest method testHasTestResultFiles.
@Test
public void testHasTestResultFiles() throws IOException {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
ShTest shTest = new ShTest(new FakeBuildRuleParamsBuilder("//test/com/example:my_sh_test").setProjectFilesystem(filesystem).build(), ruleFinder, new FakeSourcePath("run_test.sh"), /* args */
ImmutableList.of(), /* env */
ImmutableMap.of(), /* resources */
ImmutableSortedSet.of(), Optional.empty(), /* runTestSeparately */
false, /* labels */
ImmutableSet.of(), /* contacts */
ImmutableSet.of());
filesystem.touch(shTest.getPathToTestOutputResult());
assertTrue("hasTestResultFiles() should return true if result.json exists.", shTest.hasTestResultFiles());
}
Aggregations