diff options
| author | J08nY | 2018-01-23 17:31:15 +0100 |
|---|---|---|
| committer | J08nY | 2018-01-23 17:31:15 +0100 |
| commit | cb6c6b8b1274fe5a340c4317a4b015ea0ef15396 (patch) | |
| tree | 864a54dcdf07da33cd139312c8b0ee693e1a0eff /src/cz/crcs/ectester/common/output/BaseTextTestWriter.java | |
| parent | 6c46a27a52854aee24f7a37e74002bd6f4485723 (diff) | |
| parent | c581e39e539e6dadb49d9f83f563ab2b375f6e0b (diff) | |
| download | ECTester-0.2.0.tar.gz ECTester-0.2.0.tar.zst ECTester-0.2.0.zip | |
Diffstat (limited to 'src/cz/crcs/ectester/common/output/BaseTextTestWriter.java')
| -rw-r--r-- | src/cz/crcs/ectester/common/output/BaseTextTestWriter.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java new file mode 100644 index 0000000..29eb671 --- /dev/null +++ b/src/cz/crcs/ectester/common/output/BaseTextTestWriter.java @@ -0,0 +1,82 @@ +package cz.crcs.ectester.common.output; + +import cz.crcs.ectester.common.test.*; + +import java.io.PrintStream; + +/** + * @author Jan Jancar johny@neuromancer.sk + */ +public abstract class BaseTextTestWriter implements TestWriter { + private PrintStream output; + + public static int BASE_WIDTH = 90; + + public BaseTextTestWriter(PrintStream output) { + this.output = output; + } + + @Override + public void begin(TestSuite suite) { + output.println("═══ Running test suite: " + suite.getName() + " ═══"); + output.println("═══ " + suite.getDescription()); + output.print(deviceString(suite)); + } + + protected abstract String testableString(Testable t); + + protected abstract String deviceString(TestSuite suite); + + private String testString(Test t, String prefix) { + if (!t.hasRun()) { + return null; + } + boolean compound = t instanceof CompoundTest; + + StringBuilder out = new StringBuilder(); + out.append(t.ok() ? " OK " : "NOK "); + out.append(compound ? "┳ " : "━ "); + int width = BASE_WIDTH - (prefix.length() + out.length()); + String widthSpec = "%-" + String.valueOf(width) + "s"; + out.append(String.format(widthSpec, t.getDescription())); + out.append(" ┃ "); + out.append(String.format("%-9s", t.getResultValue().name())); + out.append(" ┃ "); + + if (compound) { + CompoundTest test = (CompoundTest) t; + out.append(test.getResultCause()); + out.append(System.lineSeparator()); + Test[] tests = test.getTests(); + for (int i = 0; i < tests.length; ++i) { + if (i == tests.length - 1) { + out.append(prefix).append(" ┗ "); + out.append(testString(tests[i], prefix + " ")); + } else { + out.append(prefix).append(" ┣ "); + out.append(testString(tests[i], prefix + " ┃ ")); + } + + if (i != tests.length - 1) { + out.append(System.lineSeparator()); + } + } + } else { + SimpleTest test = (SimpleTest) t; + out.append(testableString(test.getTestable())); + } + return out.toString(); + } + + @Override + public void outputTest(Test t) { + if (!t.hasRun()) + return; + output.println(testString(t, "")); + output.flush(); + } + + @Override + public void end() { + } +} |
