use of java.io.Reader in project buck by facebook.
the class XctestOutputParsingTest method streamingSimpleFailure.
@Test
public void streamingSimpleFailure() throws Exception {
Path outputPath = TestDataHelper.getTestDataDirectory(this).resolve("xctest-output/simple-failure.txt");
final List<Object> streamedObjects = new ArrayList<>();
try (Reader outputReader = Files.newBufferedReader(outputPath, StandardCharsets.UTF_8)) {
XctestOutputParsing.streamOutput(outputReader, eventCallbackAddingEventsToList(streamedObjects));
}
assertThat(streamedObjects, hasSize(8));
Iterator<Object> iter = streamedObjects.iterator();
Object nextStreamedObject;
nextStreamedObject = iter.next();
assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.BeginXctestEvent.class));
nextStreamedObject = iter.next();
assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.BeginTestSuiteEvent.class));
XctestOutputParsing.BeginTestSuiteEvent beginTestSuiteEvent1 = (XctestOutputParsing.BeginTestSuiteEvent) nextStreamedObject;
assertThat(beginTestSuiteEvent1.suite, equalTo("Example/ExampleTests.xctest(Tests)"));
nextStreamedObject = iter.next();
assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.BeginTestSuiteEvent.class));
XctestOutputParsing.BeginTestSuiteEvent beginTestSuiteEvent2 = (XctestOutputParsing.BeginTestSuiteEvent) nextStreamedObject;
assertThat(beginTestSuiteEvent2.suite, equalTo("FailureTests"));
nextStreamedObject = iter.next();
assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.BeginTestCaseEvent.class));
XctestOutputParsing.BeginTestCaseEvent beginTestEvent = (XctestOutputParsing.BeginTestCaseEvent) nextStreamedObject;
assertThat(beginTestEvent.test, equalTo("-[FailureTests testFailure]"));
assertThat(beginTestEvent.className, equalTo("FailureTests"));
assertThat(beginTestEvent.methodName, equalTo("testFailure"));
nextStreamedObject = iter.next();
assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.EndTestCaseEvent.class));
XctestOutputParsing.EndTestCaseEvent endTestEvent = (XctestOutputParsing.EndTestCaseEvent) nextStreamedObject;
assertThat(endTestEvent.totalDuration, closeTo(0.000, EPSILON));
assertThat(endTestEvent.test, equalTo("-[FailureTests testFailure]"));
assertThat(endTestEvent.className, equalTo("FailureTests"));
assertThat(endTestEvent.methodName, equalTo("testFailure"));
assertThat(endTestEvent.output, equalTo("-- test output --\n"));
assertThat(endTestEvent.succeeded, is(false));
assertThat(endTestEvent.exceptions, hasSize(1));
XctestOutputParsing.TestError testException = endTestEvent.exceptions.get(0);
assertThat(testException.lineNumber, equalTo(9));
assertThat(testException.filePathInProject, equalTo("FailureTests.m"));
assertThat(testException.reason, equalTo("failure reason"));
nextStreamedObject = iter.next();
assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.EndTestSuiteEvent.class));
XctestOutputParsing.EndTestSuiteEvent endTestSuiteEvent2 = (XctestOutputParsing.EndTestSuiteEvent) nextStreamedObject;
assertThat(endTestSuiteEvent2.suite, equalTo("FailureTests"));
assertThat(endTestSuiteEvent2.testCaseCount, equalTo(0));
assertThat(endTestSuiteEvent2.totalFailureCount, equalTo(1));
assertThat(endTestSuiteEvent2.unexpectedExceptionCount, equalTo(0));
assertThat(endTestSuiteEvent2.testDuration, closeTo(0.012, EPSILON));
assertThat(endTestSuiteEvent2.totalDuration, closeTo(0.013, EPSILON));
nextStreamedObject = iter.next();
assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.EndTestSuiteEvent.class));
XctestOutputParsing.EndTestSuiteEvent endTestSuiteEvent1 = (XctestOutputParsing.EndTestSuiteEvent) nextStreamedObject;
assertThat(endTestSuiteEvent1.suite, equalTo("Example/ExampleTests.xctest(Tests)"));
assertThat(endTestSuiteEvent1.testCaseCount, equalTo(0));
assertThat(endTestSuiteEvent1.totalFailureCount, equalTo(1));
assertThat(endTestSuiteEvent1.unexpectedExceptionCount, equalTo(0));
assertThat(endTestSuiteEvent1.testDuration, closeTo(0.012, EPSILON));
assertThat(endTestSuiteEvent1.totalDuration, closeTo(0.051, EPSILON));
nextStreamedObject = iter.next();
assertThat(nextStreamedObject, instanceOf(XctestOutputParsing.EndXctestEvent.class));
}
use of java.io.Reader in project buck by facebook.
the class XctestOutputParsingTest method mixedPassAndFailReturnsMixedResultSummary.
@Test
@SuppressWarnings("unchecked")
public void mixedPassAndFailReturnsMixedResultSummary() throws Exception {
Path outputPath = TestDataHelper.getTestDataDirectory(this).resolve("xctest-output/mixed-pass-and-fail.txt");
try (Reader outputReader = Files.newBufferedReader(outputPath, StandardCharsets.UTF_8)) {
TestCaseSummariesBuildingXctestEventHandler xctestEventHandler = new TestCaseSummariesBuildingXctestEventHandler(TestRule.NOOP_REPORTING_CALLBACK);
XctestOutputParsing.streamOutput(outputReader, xctestEventHandler);
List<TestCaseSummary> summaries = xctestEventHandler.getTestCaseSummaries();
assertThat(summaries, hasSize(2));
Matcher<TestResultSummary> isOtherTestsTestSomethingSuccess = allOf(hasProperty("testCaseName", equalTo("OtherTests")), hasProperty("testName", equalTo("testSomething")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(3L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
List<TestResultSummary> otherTestsResults = summaries.get(0).getTestResults();
assertThat(otherTestsResults, contains(isOtherTestsTestSomethingSuccess));
Matcher<TestResultSummary> isSomeTestsTestWillFail = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("testWillFail")), hasProperty("type", equalTo(ResultType.FAILURE)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
Matcher<TestResultSummary> isSomeTestsTestWillPass = allOf(hasProperty("testCaseName", equalTo("SomeTests")), hasProperty("testName", equalTo("testWillPass")), hasProperty("type", equalTo(ResultType.SUCCESS)), hasProperty("time", equalTo(0L)), hasProperty("message", nullValue(String.class)), hasProperty("stacktrace", nullValue(String.class)), hasProperty("stdOut", nullValue(String.class)), hasProperty("stdErr", nullValue(String.class)));
List<TestResultSummary> someTestsResults = summaries.get(1).getTestResults();
assertThat(someTestsResults, contains(isSomeTestsTestWillFail, isSomeTestsTestWillPass));
}
}
use of java.io.Reader in project buck by facebook.
the class BuckConfigTest method testDuplicateAliasDefinitionThrows.
@Test
public void testDuplicateAliasDefinitionThrows() throws IOException, NoSuchBuildTargetException {
Reader reader = new StringReader(Joiner.on('\n').join("[alias]", "foo = //java/com/example:foo", "foo = //java/com/example:foo"));
try {
BuckConfigTestUtils.createWithDefaultFilesystem(temporaryFolder, reader);
fail("Should have thrown HumanReadableException.");
} catch (HumanReadableException e) {
assertEquals("Throw an exception if there are duplicate definitions for an alias, " + "even if the values are the same.", "Duplicate definition for foo in the [alias] section of your .buckconfig or " + ".buckconfig.local.", e.getHumanReadableErrorMessage());
}
}
use of java.io.Reader in project buck by facebook.
the class BuckConfigTest method testConstructorThrowsForMalformedBuildTarget.
@Test
public void testConstructorThrowsForMalformedBuildTarget() throws IOException {
Reader reader = new StringReader(Joiner.on('\n').join("[alias]", "fb4a = :fb4a"));
ProjectFilesystem projectFilesystem = EasyMock.createMock(ProjectFilesystem.class);
EasyMock.replay(projectFilesystem);
try {
BuckConfigTestUtils.createWithDefaultFilesystem(temporaryFolder, reader);
fail("Should have thrown HumanReadableException.");
} catch (HumanReadableException e) {
assertEquals("Path in :fb4a must start with //", e.getHumanReadableErrorMessage());
}
EasyMock.verify(projectFilesystem);
}
use of java.io.Reader in project buck by facebook.
the class BuckConfigTest method testInvalidResourceAmountsConfiguration.
@Test
public void testInvalidResourceAmountsConfiguration() throws IOException {
Reader reader = new StringReader(Joiner.on('\n').join("[resources_per_rule]", "some_rule = 1, 20, 3, 4", "other_rule = 4,30,2,1", "wrong_config = 1,2,3,4,5,6,7,8,9,0"));
BuckConfig config = BuckConfigTestUtils.createWithDefaultFilesystem(temporaryFolder, reader);
try {
config.getResourceAmountsPerRuleType();
} catch (IllegalArgumentException e) {
assertThat(e.getMessage(), Matchers.containsString("Buck config entry [resources_per_rule].wrong_config" + " contains 10 values, but expected to contain 4 values in the following order: " + "cpu, memory, disk_io, network_io"));
return;
}
assertThat("IllegalArgumentException should be thrown", Matchers.equalTo(""));
}
Aggregations