From c15b83be52ec2db7369dbdfa3db0044b3de9ff76 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Mon, 3 Apr 2017 17:12:10 +0200 Subject: Add cleanup hooks to SummaryReporter --- .../test/dotty/tools/dotc/vulpix/SummaryReport.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/compiler/test/dotty/tools/dotc/vulpix/SummaryReport.java b/compiler/test/dotty/tools/dotc/vulpix/SummaryReport.java index 1d900e777..4f2b6350b 100644 --- a/compiler/test/dotty/tools/dotc/vulpix/SummaryReport.java +++ b/compiler/test/dotty/tools/dotc/vulpix/SummaryReport.java @@ -18,6 +18,7 @@ public class SummaryReport { private static TestReporter rep = TestReporter.reporter(System.out, -1); private static ArrayDeque failedTests = new ArrayDeque<>(); private static ArrayDeque reproduceInstructions = new ArrayDeque<>(); + private static Supplier cleanup; private static int passed; private static int failed; @@ -37,6 +38,23 @@ public class SummaryReport { reproduceInstructions.offer(msg); } + public final static void addCleanup(Function0 func) { + // Wow, look at how neatly we - compose cleanup callbacks: + if (cleanup == null) { + cleanup = () -> { + func.apply(); + return null; + }; + } else { + Supplier oldCleanup = cleanup; + cleanup = () -> { + oldCleanup.get(); + func.apply(); + return null; + }; + } + } + @BeforeClass public final static void setup() { rep = TestReporter.reporter(System.out, -1); failedTests = new ArrayDeque<>(); @@ -71,5 +89,8 @@ public class SummaryReport { if (!isInteractive) rep.flushToStdErr(); if (failed > 0) rep.flushToFile(); + + // Perform cleanup callback: + if (cleanup != null) cleanup.get(); } } -- cgit v1.2.3