use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class BuildFileSpecTest method findWithWatchmanThrowsOnFailure.
@Test
public void findWithWatchmanThrowsOnFailure() throws IOException, InterruptedException {
Path watchRoot = Paths.get(".").toAbsolutePath().normalize();
FakeProjectFilesystem filesystem = new FakeProjectFilesystem(watchRoot.resolve("project-name"));
Path buildFile = Paths.get("a", "BUCK");
BuildFileSpec recursiveSpec = BuildFileSpec.fromRecursivePath(buildFile.getParent(), filesystem.getRootPath());
FakeWatchmanClient fakeWatchmanClient = new FakeWatchmanClient(0, ImmutableMap.of(ImmutableList.of("query", watchRoot.toString(), ImmutableMap.of("relative_root", "project-name", "sync_timeout", 0, "path", ImmutableList.of("a"), "fields", ImmutableList.of("name"), "expression", ImmutableList.of("allof", "exists", ImmutableList.of("name", "BUCK"), ImmutableList.of("type", "f")))), ImmutableMap.of("files", ImmutableList.of("a/BUCK"))), new IOException("Whoopsie!"));
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setWatchman(new Watchman(ImmutableMap.of(filesystem.getRootPath(), ProjectWatch.of(watchRoot.toString(), Optional.of("project-name"))), ImmutableSet.of(Watchman.Capability.SUPPORTS_PROJECT_WATCH, Watchman.Capability.DIRNAME, Watchman.Capability.WILDMATCH_GLOB), ImmutableMap.of(), Optional.of(Paths.get(".watchman-sock")), Optional.of(fakeWatchmanClient))).build();
thrown.expect(IOException.class);
thrown.expectMessage("Whoopsie!");
recursiveSpec.findBuildFiles(cell, ParserConfig.BuildFileSearchMethod.WATCHMAN);
}
use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class ParserTest method whenAllRulesAreRequestedWithDifferingIncludesThenRulesAreParsedTwice.
@Test
public void whenAllRulesAreRequestedWithDifferingIncludesThenRulesAreParsedTwice() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setSections(ImmutableMap.of(ParserConfig.BUILDFILE_SECTION_NAME, ImmutableMap.of(ParserConfig.INCLUDES_PROPERTY_NAME, "//bar.py"))).build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
assertEquals("Should have invalidated cache.", 2, counter.calls);
}
use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class ParserTest method whenBuckConfigEntryRemovedThenCachedRulesAreInvalidated.
@Test
public void whenBuckConfigEntryRemovedThenCachedRulesAreInvalidated() throws Exception {
Path buckFile = cellRoot.resolve("BUCK");
Files.write(buckFile, Joiner.on("").join(ImmutableList.of("read_config('foo', 'bar')\n", "genrule(name = 'cake', out = 'file.txt', cmd = 'touch $OUT')\n")).getBytes(UTF_8));
BuckConfig config = FakeBuckConfig.builder().setSections(ImmutableMap.of("foo", ImmutableMap.of("bar", "value"))).setFilesystem(filesystem).build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
// Call filterAllTargetsInProject to request cached rules.
config = FakeBuckConfig.builder().setFilesystem(filesystem).build();
cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
parser.getAllTargetNodes(eventBus, cell, false, executorService, buckFile);
// Test that the second parseBuildFile call repopulated the cache.
assertEquals("Should have invalidated.", 2, counter.calls);
}
use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class ParserTest method whenEnvironmentNotChangedThenCacheRulesAreNotInvalidated.
@Test
public void whenEnvironmentNotChangedThenCacheRulesAreNotInvalidated() throws BuildFileParseException, BuildTargetException, IOException, InterruptedException {
BuckConfig config = FakeBuckConfig.builder().setFilesystem(filesystem).setEnvironment(ImmutableMap.of("Some Key", "Some Value", "PATH", System.getenv("PATH"))).build();
Cell cell = new TestCellBuilder().setFilesystem(filesystem).setBuckConfig(config).build();
// Call filterAllTargetsInProject to populate the cache.
filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
// Call filterAllTargetsInProject to request cached rules with identical environment.
filterAllTargetsInProject(parser, cell, x -> true, eventBus, executorService);
// Test that the second parseBuildFile call repopulated the cache.
assertEquals("Should not have invalidated cache.", 1, counter.calls);
}
use of com.facebook.buck.rules.TestCellBuilder in project buck by facebook.
the class BuckQueryEnvironmentTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "query_command", tmp);
workspace.setUp();
Cell cell = new TestCellBuilder().setFilesystem(new ProjectFilesystem(workspace.getDestPath())).build();
TestConsole console = new TestConsole();
DefaultTypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
Parser parser = new Parser(new BroadcastEventListener(), cell.getBuckConfig().getView(ParserConfig.class), typeCoercerFactory, new ConstructorArgMarshaller(typeCoercerFactory));
BuckEventBus eventBus = BuckEventBusFactory.newInstance();
parserState = new PerBuildState(parser, eventBus, executor, cell, /* enableProfiling */
false, SpeculativeParsing.of(true), /* ignoreBuckAutodepsFiles */
false);
TargetPatternEvaluator targetPatternEvaluator = new TargetPatternEvaluator(cell, FakeBuckConfig.builder().build(), parser, eventBus, /* enableProfiling */
false);
OwnersReport.Builder ownersReportBuilder = OwnersReport.builder(cell, parser, eventBus, console);
buckQueryEnvironment = BuckQueryEnvironment.from(cell, ownersReportBuilder, parserState, targetPatternEvaluator);
cellRoot = workspace.getDestPath();
executor = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
}
Aggregations