Search in sources :

Example 51 with Reader

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));
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 52 with Reader

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));
    }
}
Also used : Path(java.nio.file.Path) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) Reader(java.io.Reader) StringReader(java.io.StringReader) TestResultSummary(com.facebook.buck.test.TestResultSummary) Test(org.junit.Test)

Example 53 with Reader

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());
    }
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 54 with Reader

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);
}
Also used : HumanReadableException(com.facebook.buck.util.HumanReadableException) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 55 with Reader

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(""));
}
Also used : StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) Test(org.junit.Test)

Aggregations

Reader (java.io.Reader)1498 InputStreamReader (java.io.InputStreamReader)526 StringReader (java.io.StringReader)498 IOException (java.io.IOException)348 BufferedReader (java.io.BufferedReader)242 InputStream (java.io.InputStream)219 TokenStream (org.apache.lucene.analysis.TokenStream)171 Test (org.junit.Test)170 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)159 Connection (java.sql.Connection)137 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)126 FileReader (java.io.FileReader)108 FileInputStream (java.io.FileInputStream)107 File (java.io.File)105 BeforeClass (org.junit.BeforeClass)99 Tokenizer (org.apache.lucene.analysis.Tokenizer)91 SqlSession (org.apache.ibatis.session.SqlSession)83 StringWriter (java.io.StringWriter)81 ArrayList (java.util.ArrayList)77 Writer (java.io.Writer)63