1
import java.util.Scanner;
2
import java.util.regex.Matcher;
3
import java.util.regex.Pattern;
6
* A simple utility class for trimming test output (if successful).
8
* Created to shrink down the output for Travis.
10
* Created by st on 03/07/17.
12
public class LogTrimmer {
14
private static Pattern TEST_START_PATTERN = Pattern.compile("(\\[INFO\\] )?Running (.*)");
15
private static int TEST_NAME_GROUP = 2;
17
public static void main(String[] args) {
18
try (Scanner scanner = new Scanner(System.in)) {
19
String testRunning = null;
21
Matcher testMatcher = null;
22
StringBuilder testText = new StringBuilder();
24
while (scanner.hasNextLine()) {
25
line = scanner.nextLine();
26
if (testRunning == null) {
27
testMatcher = TEST_START_PATTERN.matcher(line);
28
if (testMatcher.find()) {
29
testRunning = testMatcher.group(TEST_NAME_GROUP);
30
System.out.println(line);
32
System.out.println("-- " + line);
35
if (line.contains("Tests run:")) {
36
if (!(line.contains("Failures: 0") && line.contains("Errors: 0"))) {
37
System.out.println("--------- " + testRunning + " output start ---------");
38
System.out.println(testText.toString());
39
System.out.println("--------- " + testRunning + " output end ---------");
41
System.out.println(line);
43
testText = new StringBuilder();
45
testText.append(testRunning.substring(testRunning.lastIndexOf('.') + 1) + " ++ " + line);
46
testText.append("\n");