use of com.facebook.buck.test.result.type.ResultType in project buck by facebook.
the class CxxBoostTest method visitTestSuite.
private void visitTestSuite(ImmutableList.Builder<TestResultSummary> builder, Map<String, String> messages, Map<String, List<String>> stdout, Map<String, Long> times, String prefix, Node testSuite) {
NamedNodeMap attributes = testSuite.getAttributes();
String suiteName = attributes.getNamedItem("name").getNodeValue();
if (!prefix.isEmpty()) {
suiteName = prefix + "." + suiteName;
}
NodeList testCases = testSuite.getChildNodes();
for (int index = 0; index < testCases.getLength(); index++) {
Node testCase = testCases.item(index);
if (!testCase.getNodeName().equals("TestCase")) {
visitTestSuite(builder, messages, stdout, times, suiteName, testCase);
continue;
}
NamedNodeMap attrs = testCase.getAttributes();
String caseName = attrs.getNamedItem("name").getNodeValue();
String test = String.format("%s.%s", suiteName, caseName);
Long time = Optional.ofNullable(times.get(test)).orElse(0L);
String resultString = attrs.getNamedItem("result").getNodeValue();
ResultType result = ResultType.SUCCESS;
String output = "";
String message = "";
if (!"passed".equals(resultString)) {
result = ResultType.FAILURE;
message = messages.get(test);
output = Joiner.on("\n").join(stdout.get(test));
}
builder.add(new TestResultSummary(suiteName, caseName, result, time, message, /* stacktrace */
"", /* stdOut */
output, /* stdErr */
""));
}
}
use of com.facebook.buck.test.result.type.ResultType in project buck by facebook.
the class RustTest method parseTestResults.
private ImmutableList<TestResultSummary> parseTestResults() throws IOException {
Map<String, ResultType> testToResult = new HashMap<>();
try (BufferedReader reader = Files.newBufferedReader(testOutputFile, Charsets.UTF_8)) {
String line;
while ((line = reader.readLine()) != null) {
String[] resultAndTestName = line.split(" ");
if (resultAndTestName.length != 2) {
throw new RuntimeException(String.format("Unknown test output format %s", line));
}
ResultType result;
switch(resultAndTestName[0]) {
case "ok":
result = ResultType.SUCCESS;
break;
case "failed":
result = ResultType.FAILURE;
break;
case "ignored":
result = ResultType.DISABLED;
break;
default:
throw new RuntimeException(String.format("Unknown test status %s", line));
}
testToResult.put(resultAndTestName[1], result);
}
}
Map<String, String> testToStdout = new HashMap<>();
try (BufferedReader reader = Files.newBufferedReader(testStdoutFile, Charsets.UTF_8)) {
StringBuilder stdout = new StringBuilder();
String currentStdoutTestName = null;
BiConsumer<String, String> addTestStdout = (key, value) -> {
testToStdout.put(key, value);
stdout.setLength(0);
};
String line;
while ((line = reader.readLine()) != null) {
Matcher matcher;
if ((matcher = TEST_STDOUT_PATTERN.matcher(line)).matches()) {
if (currentStdoutTestName != null) {
// Start of stdout output for new test
// Save current stdout
addTestStdout.accept(currentStdoutTestName, stdout.toString());
}
currentStdoutTestName = matcher.group("name");
} else if (FAILURES_LIST_PATTERN.matcher(line).matches()) {
if (currentStdoutTestName != null) {
addTestStdout.accept(currentStdoutTestName, stdout.toString());
}
} else if (currentStdoutTestName != null) {
stdout.append("\n");
stdout.append(line);
}
}
}
ImmutableList.Builder<TestResultSummary> summariesBuilder = ImmutableList.builder();
for (Map.Entry<String, ResultType> entry : testToResult.entrySet()) {
summariesBuilder.add(new TestResultSummary("rust_test", entry.getKey(), entry.getValue(), // TODO(StanislavGlebik) time
0, // message
"", // stack trace,
"", testToStdout.get(entry.getKey()), // stderr
""));
}
return summariesBuilder.build();
}
Aggregations