From 9bdb7ccbf6dec79375b31de8dec0be899e59f3f5 Mon Sep 17 00:00:00 2001 From: Juraj Kirchheim Date: Wed, 10 Feb 2021 15:54:04 +0100 Subject: [PATCH 1/4] Adjust to corresponding branch of tink_streams. --- src/tink/testrunner/Assertions.hx | 18 ++++++++--------- src/tink/testrunner/Runner.hx | 32 +++++++++++++++---------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/tink/testrunner/Assertions.hx b/src/tink/testrunner/Assertions.hx index 902a830..04b6e77 100644 --- a/src/tink/testrunner/Assertions.hx +++ b/src/tink/testrunner/Assertions.hx @@ -5,7 +5,7 @@ import haxe.PosInfos; using tink.CoreApi; -private typedef Impl = Stream; +private typedef Impl = Stream; @:forward @:transitive abstract Assertions(Impl) from Impl to Impl { @@ -21,7 +21,7 @@ abstract Assertions(Impl) from Impl to Impl { public static inline function ofPromiseArray(o:Promise>):Assertions { return o.next(function(o):Impl return o.iterator()); } - + @:from public static function ofFutureAssertion(p:Future):Assertions { #if (java && pure) // HACK: somehow this passes the java native compilation @@ -30,12 +30,12 @@ abstract Assertions(Impl) from Impl to Impl { return p.map(function(a) return Success(ofAssertion(a))); #end } - + @:from public static function ofFutureAssertions(p:Future):Assertions { return p.map(Success); } - + @:from public static function ofSurpriseAssertion(p:Surprise):Assertions { #if (java && pure) // HACK: somehow this passes the java native compilation @@ -47,17 +47,17 @@ abstract Assertions(Impl) from Impl to Impl { return p >> function(o:Assertion) return ofAssertion(o); #end } - + @:from public static inline function ofOutcomeAssertions(o:Outcome):Assertions { return ofSurpriseAssertions(Future.sync(o)); } - + @:from public static inline function ofPromiseAssertions(p:Promise):Assertions { return ofSurpriseAssertions(p); } - + @:from public static inline function ofSurpriseAssertions(p:Surprise):Assertions { #if pure @@ -69,11 +69,9 @@ abstract Assertions(Impl) from Impl to Impl { #else return Stream.promise((p:Surprise)); #end - #else - return Stream.later((p:Surprise)); #end } - + #if tink_unittest // TODO: use solution from https://github.com/HaxeFoundation/haxe/issues/9611 @:from diff --git a/src/tink/testrunner/Runner.hx b/src/tink/testrunner/Runner.hx index 017c10e..7221cc2 100644 --- a/src/tink/testrunner/Runner.hx +++ b/src/tink/testrunner/Runner.hx @@ -12,20 +12,20 @@ using tink.testrunner.Runner.TimeoutHelper; using tink.CoreApi; class Runner { - + public static function exit(result:BatchResult) { Helper.exit(result.summary().failures.length); } - + public static function run(batch:Batch, ?reporter:Reporter, ?timers:TimerManager):Future { - + if(reporter == null) reporter = new BasicReporter(); if(timers == null) { #if ((haxe_ver >= 3.3) || flash || js || openfl) timers = new HaxeTimerManager(); #end } - + var includeMode = false; for(s in batch.suites) { if(includeMode) break; @@ -34,7 +34,7 @@ class Runner { break; } } - + return Future.async(function(cb) { reporter.report(BatchStart).handle(function(_) { var iter = batch.suites.iterator(); @@ -54,17 +54,17 @@ class Runner { }); }); } - - + + static function runSuite(suite:Suite, reporter:Reporter, timers:TimerManager, includeMode:Bool):Future { return Future.async(function(cb) { var cases = suite.getCasesToBeRun(includeMode); var hasCases = cases.length > 0; reporter.report(SuiteStart(suite.info, hasCases)).handle(function(_) { - + function setup() return hasCases ? suite.setup() : Promise.NOISE; function teardown() return hasCases ? suite.teardown() : Promise.NOISE; - + var iter = suite.cases.iterator(); var results = []; function next() { @@ -91,7 +91,7 @@ class Runner { }); }); } - + static function runCase(caze:Case, suite:Suite, reporter:Reporter, timers:TimerManager, shouldRun:Bool):Future { return Future.async(function(cb) { if(shouldRun) { @@ -99,14 +99,14 @@ class Runner { suite.before().timeout(caze.timeout, timers, caze.pos) .next(function(_) { var assertions = []; - return caze.execute().forEach(function(a) { + return caze.execute().forEach(function(a, _) { assertions.push(a); - return reporter.report(Assertion(a)).map(function(_) return Resume); + return reporter.report(Assertion(a)).map(function(_) return null); }) .next(function(o):Outcome, Error> return switch o { - case Depleted: Success(assertions); - case Halted(_): throw 'unreachable'; - case Failed(e): Failure(e); + case Done: Success(assertions); + case Stopped(rest, Failure(e)): Failure(e); + default: throw 'unreachable'; }) .timeout(caze.timeout, timers); }) @@ -134,7 +134,7 @@ class Runner { } }); } - + } class TimeoutHelper { From c7f9b9882deb30a16c33822e64748a4049103be3 Mon Sep 17 00:00:00 2001 From: Juraj Kirchheim Date: Wed, 10 Feb 2021 19:58:03 +0100 Subject: [PATCH 2/4] Adjust to api changes. --- src/tink/testrunner/Runner.hx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/tink/testrunner/Runner.hx b/src/tink/testrunner/Runner.hx index 7221cc2..eb54447 100644 --- a/src/tink/testrunner/Runner.hx +++ b/src/tink/testrunner/Runner.hx @@ -99,9 +99,10 @@ class Runner { suite.before().timeout(caze.timeout, timers, caze.pos) .next(function(_) { var assertions = []; - return caze.execute().forEach(function(a, _) { + return + caze.execute().forEach(a -> { assertions.push(a); - return reporter.report(Assertion(a)).map(function(_) return null); + reporter.report(Assertion(a)).map(_ -> None); }) .next(function(o):Outcome, Error> return switch o { case Done: Success(assertions); From 4ee853978546310972c3177fbf2c0a6d0e6eaa29 Mon Sep 17 00:00:00 2001 From: Juraj Kirchheim Date: Thu, 11 Feb 2021 12:14:44 +0100 Subject: [PATCH 3/4] Wahoops. --- src/tink/testrunner/Runner.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tink/testrunner/Runner.hx b/src/tink/testrunner/Runner.hx index eb54447..7399859 100644 --- a/src/tink/testrunner/Runner.hx +++ b/src/tink/testrunner/Runner.hx @@ -106,7 +106,7 @@ class Runner { }) .next(function(o):Outcome, Error> return switch o { case Done: Success(assertions); - case Stopped(rest, Failure(e)): Failure(e); + case Failed(_, e): Failure(e); default: throw 'unreachable'; }) .timeout(caze.timeout, timers); From 866de8b991be89b969825b0c0f5565d51f96a6f7 Mon Sep 17 00:00:00 2001 From: Juraj Kirchheim Date: Fri, 12 Feb 2021 16:06:05 +0100 Subject: [PATCH 4/4] Get rid of some deprecation warnings. --- src/tink/testrunner/Assertions.hx | 24 ++---------------------- src/tink/testrunner/Runner.hx | 8 ++++---- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/tink/testrunner/Assertions.hx b/src/tink/testrunner/Assertions.hx index 04b6e77..74a5f18 100644 --- a/src/tink/testrunner/Assertions.hx +++ b/src/tink/testrunner/Assertions.hx @@ -24,11 +24,7 @@ abstract Assertions(Impl) from Impl to Impl { @:from public static function ofFutureAssertion(p:Future):Assertions { - #if (java && pure) // HACK: somehow this passes the java native compilation - return Stream.flatten(p.map(function(a):Stream return Stream.single(a))); - #else return p.map(function(a) return Success(ofAssertion(a))); - #end } @:from @@ -38,14 +34,7 @@ abstract Assertions(Impl) from Impl to Impl { @:from public static function ofSurpriseAssertion(p:Surprise):Assertions { - #if (java && pure) // HACK: somehow this passes the java native compilation - return Stream.flatten(p.map(function(o):Stream return switch o { - case Success(a): Stream.single(a); - case Failure(e): Stream.ofError(e); - })); - #else - return p >> function(o:Assertion) return ofAssertion(o); - #end + return Promise.lift(p).next(ofAssertion); } @:from @@ -60,16 +49,7 @@ abstract Assertions(Impl) from Impl to Impl { @:from public static inline function ofSurpriseAssertions(p:Surprise):Assertions { - #if pure - #if java // HACK: somehow this passes the java native compilation - return Stream.flatten(p.map(function(o):Stream return switch o { - case Success(a): (a:Stream); - case Failure(e): Stream.ofError(e); - })); - #else - return Stream.promise((p:Surprise)); - #end - #end + return Stream.promise((p:Surprise)); } #if tink_unittest diff --git a/src/tink/testrunner/Runner.hx b/src/tink/testrunner/Runner.hx index 7399859..3bc733e 100644 --- a/src/tink/testrunner/Runner.hx +++ b/src/tink/testrunner/Runner.hx @@ -35,7 +35,7 @@ class Runner { } } - return Future.async(function(cb) { + return Future.irreversible(function(cb) { reporter.report(BatchStart).handle(function(_) { var iter = batch.suites.iterator(); var results:BatchResult = []; @@ -57,7 +57,7 @@ class Runner { static function runSuite(suite:Suite, reporter:Reporter, timers:TimerManager, includeMode:Bool):Future { - return Future.async(function(cb) { + return Future.irreversible(function(cb) { var cases = suite.getCasesToBeRun(includeMode); var hasCases = cases.length > 0; reporter.report(SuiteStart(suite.info, hasCases)).handle(function(_) { @@ -93,7 +93,7 @@ class Runner { } static function runCase(caze:Case, suite:Suite, reporter:Reporter, timers:TimerManager, shouldRun:Bool):Future { - return Future.async(function(cb) { + return Future.irreversible(function(cb) { if(shouldRun) { reporter.report(CaseStart(caze.info, shouldRun)).handle(function(_) { suite.before().timeout(caze.timeout, timers, caze.pos) @@ -140,7 +140,7 @@ class Runner { class TimeoutHelper { public static function timeout(promise:Promise, ms:Int, timers:TimerManager, ?pos:PosInfos):Promise { - return Future.async(function(cb) { + return Future.irreversible(function(cb) { var done = false; var timer = null; var link = promise.handle(function(o) {