use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class ChromeTraceBuildListenerTest method canCompressTraces.
@Test
public void canCompressTraces() throws IOException {
ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
ChromeTraceBuildListener listener = new ChromeTraceBuildListener(projectFilesystem, invocationInfo, new FakeClock(TIMESTAMP_NANOS), ObjectMappers.newDefaultInstance(), Locale.US, TimeZone.getTimeZone("America/Los_Angeles"), /* tracesToKeep */
1, true);
listener.outputTrace(invocationInfo.getBuildId());
Path tracePath = Paths.get(EXPECTED_DIR + "build.2014-09-02.16-55-51.BUILD_ID.trace.gz");
assertTrue(projectFilesystem.exists(tracePath));
BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(projectFilesystem.newFileInputStream(tracePath))));
List<?> elements = new Gson().fromJson(reader, List.class);
assertThat(elements, notNullValue());
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class ParsingJavaPackageFinderTest method setUp.
@Before
public void setUp() throws IOException {
matchPath = Paths.get("case1/org/test/package1/Match.java");
mismatchPath = Paths.get("case1/org/test/package2/Mismatch.java");
placeholderPath = Paths.get("case3/com/test/placeholder");
fakeProjectFilesystem = new FakeProjectFilesystem(new FakeClock(0), Paths.get(".").toAbsolutePath(), ImmutableSet.of(matchPath, mismatchPath, placeholderPath));
fakeProjectFilesystem.writeContentsToPath("package org.test.package1; \n class Match {} \n", matchPath);
fakeProjectFilesystem.writeContentsToPath("package org.test.\nhaha; \n class Mismatch {} \n", mismatchPath);
dummyPackageFinder = new JavaPackageFinder() {
@Override
public Path findJavaPackageFolder(Path pathRelativeToProjectRoot) {
return Paths.get("dummy");
}
@Override
public String findJavaPackage(Path pathRelativeToProjectRoot) {
return "dummy";
}
@Override
public String findJavaPackage(BuildTarget buildTarget) {
return "dummy";
}
};
javaFileParser = JavaFileParser.createJavaFileParser(JavaCompilationConstants.DEFAULT_JAVAC_OPTIONS);
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class PythonBuckConfigTest method testPathToPexExecuterUsesConfigSetting.
@Test
public void testPathToPexExecuterUsesConfigSetting() throws IOException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Path projectDir = Files.createTempDirectory("project");
Path pexExecuter = Paths.get("pex-exectuter");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new FakeClock(0), projectDir, ImmutableSet.of(pexExecuter));
Files.createFile(projectFilesystem.resolve(pexExecuter));
assertTrue("Should be able to set file executable", projectFilesystem.resolve(pexExecuter).toFile().setExecutable(true));
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("path_to_pex_executer", pexExecuter.toString()))).setFilesystem(projectFilesystem).build(), new ExecutableFinder());
assertThat(config.getPexExecutor(resolver).get().getCommandPrefix(pathResolver), Matchers.contains(pexExecuter.toString()));
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessReturnsWarningThenConsoleEventPublished.
@Test
public void whenSubprocessReturnsWarningThenConsoleEventPublished() throws IOException, BuildFileParseException, InterruptedException {
// This test depends on unix utilities that don't exist on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
final List<ConsoleEvent> consoleEvents = new ArrayList<>();
final List<WatchmanDiagnosticEvent> watchmanDiagnosticEvents = new ArrayList<>();
class EventListener {
@Subscribe
public void on(ConsoleEvent consoleEvent) {
consoleEvents.add(consoleEvent);
}
@Subscribe
public void on(WatchmanDiagnosticEvent event) {
watchmanDiagnosticEvents.add(event);
}
}
EventListener eventListener = new EventListener();
buckEventBus.register(eventListener);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessWithWarning(buckEventBus, "This is a warning", "parser")) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Warning raised by BUCK file parser: This is a warning")));
assertThat("Should not receive any watchman diagnostic events", watchmanDiagnosticEvents, Matchers.empty());
}
use of com.facebook.buck.timing.FakeClock in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessPrintsWarningToStderrThenConsoleEventPublished.
@Test
public void whenSubprocessPrintsWarningToStderrThenConsoleEventPublished() throws IOException, BuildFileParseException, InterruptedException {
// This test depends on unix utilities that don't exist on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
final List<ConsoleEvent> consoleEvents = new ArrayList<>();
class EventListener {
@Subscribe
public void onConsoleEvent(ConsoleEvent consoleEvent) {
consoleEvents.add(consoleEvent);
}
}
EventListener eventListener = new EventListener();
buckEventBus.register(eventListener);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessAndPrintsToStderr(buckEventBus)) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Warning raised by BUCK file parser: Don't Panic!")));
}
Aggregations