X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Ftest%2FTestLauncher.java;h=895b565ae0f607522e494d92c8bc87541c672f51;hb=601003e69e1dc81774243c6eadf7982b6b563b33;hp=10a6e2794811036a12f21239d254f7dd3e2c483b;hpb=16d593780fa5a4c39cc36b29382da610eae951da;p=fanfix.git diff --git a/src/be/nikiroo/utils/test/TestLauncher.java b/src/be/nikiroo/utils/test/TestLauncher.java index 10a6e27..895b565 100644 --- a/src/be/nikiroo/utils/test/TestLauncher.java +++ b/src/be/nikiroo/utils/test/TestLauncher.java @@ -20,7 +20,7 @@ public class TestLauncher { private class SetupException extends Exception { private static final long serialVersionUID = 1L; - public SetupException(Exception e) { + public SetupException(Throwable e) { super(e); } } @@ -33,13 +33,15 @@ public class TestLauncher { private class TearDownException extends Exception { private static final long serialVersionUID = 1L; - public TearDownException(Exception e) { + public TearDownException(Throwable e) { super(e); } } private List series; private List tests; + private TestLauncher parent; + private int columns; private String okString; private String koString; @@ -50,6 +52,7 @@ public class TestLauncher { protected int total; private int currentSeries = 0; + private boolean details = false; /** * Create a new {@link TestLauncher} with default parameters. @@ -90,6 +93,33 @@ public class TestLauncher { cont = true; } + /** + * Display the details of the errors + * + * @return TRUE to display them, false to simply mark the test as failed + */ + public boolean isDetails() { + if (parent != null) { + return parent.isDetails(); + } + + return details; + } + + /** + * Display the details of the errors + * + * @param details + * TRUE to display them, false to simply mark the test as failed + */ + public void setDetails(boolean details) { + if (parent != null) { + parent.setDetails(details); + } + + this.details = details; + } + /** * Called before actually starting the tests themselves. * @@ -114,6 +144,7 @@ public class TestLauncher { protected void addSeries(TestLauncher series) { this.series.add(series); + series.parent = this; } /** @@ -185,20 +216,20 @@ public class TestLauncher { for (TestCase test : tests) { print(depth, test.getName()); - Exception ex = null; + Throwable ex = null; try { try { test.setUp(); - } catch (Exception e) { + } catch (Throwable e) { throw new SetupException(e); } test.test(); try { test.tearDown(); - } catch (Exception e) { + } catch (Throwable e) { throw new TearDownException(e); } - } catch (Exception e) { + } catch (Throwable e) { ex = e; } @@ -278,18 +309,19 @@ public class TestLauncher { * * @param depth * the level at which is the launcher (0 = main launcher) - * @param test - * the {@link TestCase} + * @param name + * the {@link TestCase} name */ protected void print(int depth, String name) { name = prefix(depth, false) + (name == null ? "" : name).replace("\t", " "); - while (name.length() < columns - 11) { - name += "."; + StringBuilder dots = new StringBuilder(); + while ((name.length() + dots.length()) < columns - 11) { + dots.append('.'); } - System.out.print(name); + System.out.print(name + dots.toString()); } /** @@ -300,15 +332,17 @@ public class TestLauncher { * @param error * the {@link Exception} it ran into if any */ - private void print(int depth, Exception error) { + private void print(int depth, Throwable error) { if (error != null) { System.out.println(" " + koString); - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - error.printStackTrace(pw); - String lines = sw.toString(); - for (String line : lines.split("\n")) { - System.out.println(prefix(depth, false) + "\t\t" + line); + if (isDetails()) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + error.printStackTrace(pw); + String lines = sw.toString(); + for (String line : lines.split("\n")) { + System.out.println(prefix(depth, false) + "\t\t" + line); + } } } else { System.out.println(" " + okString);