Skip to content
Permalink
Browse files
8263659: Reflow GTestResultParser for better readability
Reviewed-by: shade, iignatyev
  • Loading branch information
alblue authored and iignatev committed Mar 18, 2021
1 parent e333b6e commit 21db0f6768d086f49e0ab1265c274b8917c23ebd
Showing 1 changed file with 21 additions and 22 deletions.
@@ -21,6 +21,7 @@
* questions.
*/

import javax.xml.XMLConstants;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
@@ -39,34 +40,32 @@ public class GTestResultParser {
public GTestResultParser(Path file) {
List<String> failedTests = new ArrayList<>();
try (Reader r = Files.newBufferedReader(file)) {
try {
XMLStreamReader xmlReader = XMLInputFactory.newInstance()
.createXMLStreamReader(r);
String testSuite = null;
String testCase = null;
while (xmlReader.hasNext()) {
switch (xmlReader.next()) {
case XMLStreamConstants.START_ELEMENT:
switch (xmlReader.getLocalName()) {
case "testsuite":
testSuite = xmlReader.getAttributeValue("", "name");
break;
case "testcase":
testCase = xmlReader.getAttributeValue("", "name");
break;
case "failure":
failedTests.add(testSuite + "::" + testCase);
default:
// ignore
}
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
XMLStreamReader xmlReader = factory.createXMLStreamReader(r);
String testSuite = null;
String testCase = null;
while (xmlReader.hasNext()) {
int code = xmlReader.next();
if (code == XMLStreamConstants.START_ELEMENT) {
switch (xmlReader.getLocalName()) {
case "testsuite":
testSuite = xmlReader.getAttributeValue("", "name");
break;
case "testcase":
testCase = xmlReader.getAttributeValue("", "name");
break;
case "failure":
failedTests.add(testSuite + "::" + testCase);
break;
default:
// ignore
}
}
} catch (XMLStreamException e) {
throw new IllegalArgumentException("can't open parse xml " + file, e);
}
} catch (XMLStreamException e) {
throw new IllegalArgumentException("can't open parse xml " + file, e);
} catch (IOException e) {
throw new IllegalArgumentException("can't open result file " + file, e);
}

0 comments on commit 21db0f6

Please sign in to comment.