From ed803104caae44e1879d1fd9b300a69e8371d3cb Mon Sep 17 00:00:00 2001 From: Jun Matsushita Date: Sun, 12 Nov 2017 21:43:56 +0100 Subject: [PATCH 1/3] Added test for strange exception swallowing origamitower/folktale#163 --- test/source/specs/base/concurrency/task.js | 58 ++++++++++++++++------ 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/test/source/specs/base/concurrency/task.js b/test/source/specs/base/concurrency/task.js index 33e65b4..8f01754 100644 --- a/test/source/specs/base/concurrency/task.js +++ b/test/source/specs/base/concurrency/task.js @@ -168,7 +168,7 @@ describe('Data.Task', () => { $ASSERT(v1 == 1); await b.or(a).run().promise().catch(v => $ASSERT(v == 2)); - + const v2 = await a.or(c).run().promise(); $ASSERT(v2 == 1); @@ -335,8 +335,8 @@ describe('Data.Task', () => { r.cleanup(() => clearTimeout(timer)); }); const result = await Task.do(function *() { - const a = yield delay(10); - const b = yield delay(11); + const a = yield delay(10); + const b = yield delay(11); const c = yield Task.of(5); return Task.of(a + b + c + 4); }).run().promise(); @@ -352,7 +352,7 @@ describe('Data.Task', () => { $ASSERT(exception == 5); }) $ASSERT(exceptionThrown[0] == true); - + const resultCancel = await Task.do(function *() { const a = yield Task.task(r => r.cancel()); return Task.of(a); @@ -363,7 +363,7 @@ describe('Data.Task', () => { const multipleCallsResults = []; const multipleCallsTask = await Task.do(function *() { - const a = yield delay(10); + const a = yield delay(10); return Task.of(a); }); multipleCallsResults[0] = await multipleCallsTask.run().promise(); @@ -386,14 +386,14 @@ describe('Data.Task', () => { }); it('Always invokes cleanup after the task resolves', async () => { - let stack = []; + let stack = []; let d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(1); r.cleanup(() => { stack.push(2); - d.resolve(2) + d.resolve(2) }); r.resolve(1) }).run(); @@ -402,7 +402,7 @@ describe('Data.Task', () => { stack = []; d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(3); r.cleanup(() => { stack.push(4); @@ -415,7 +415,7 @@ describe('Data.Task', () => { stack = []; d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(5); r.cleanup(() => { stack.push(6); @@ -427,10 +427,10 @@ describe('Data.Task', () => { }); it('Invokes onCancelled callbacks if the task is cancelled', async () => { - let stack = []; + let stack = []; let d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(1); r.cleanup(() => { stack.push(2); @@ -447,7 +447,7 @@ describe('Data.Task', () => { stack = []; d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(3); r.cleanup(() => { stack.push(4); @@ -464,7 +464,7 @@ describe('Data.Task', () => { stack = []; d = new Deferred(); - Task.task(r => { + Task.task(r => { stack.push(5); stack.push(r.isCancelled); r.cleanup(() => { @@ -539,6 +539,36 @@ describe('Data.Task', () => { ex.cancel(); return ex.promise().catch(v => $ASSERT(Cancelled.hasInstance(v))); }); + + it('Deals with exception', async () => { + let Result = undefined; + try { + let ex = await Task.of('a') + .map((() => false ? Result.a : Result.b)) + .run() + .promise(); + // Should have thrown by then + $ASSERT(false) + } catch (e) { + if (e.message != 'false') $ASSERT(e instanceof TypeError) + } + }); + + it('Deals with exception corner cases', async () => { + let Result = require('folktale').validation; + try { + let ex = await Task.of('a') + .map((() => false ? Result.a : Result.b)) + .run() + .promise(); + // Should have thrown by then + $ASSERT(false) + } catch (e) { + if (e.message != 'false') $ASSERT(e instanceof TypeError) + } + }); + + }); describe('#future()', () => { From b11ccaf73b1497f77a7fb386822b6ba840b592a3 Mon Sep 17 00:00:00 2001 From: Jun Matsushita Date: Sat, 18 Nov 2017 11:26:09 +0100 Subject: [PATCH 2/3] Clarify test --- test/source/specs/base/concurrency/task.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/source/specs/base/concurrency/task.js b/test/source/specs/base/concurrency/task.js index 8f01754..6efa913 100644 --- a/test/source/specs/base/concurrency/task.js +++ b/test/source/specs/base/concurrency/task.js @@ -25,7 +25,6 @@ const eq = function(that) { return this._state.equals(that._state); } - describe('Data.Task', () => { describe('Conversions', () => { @@ -541,16 +540,18 @@ describe('Data.Task', () => { }); it('Deals with exception', async () => { + const AssertionError = require('assert').AssertionError; let Result = undefined; + try { let ex = await Task.of('a') .map((() => false ? Result.a : Result.b)) .run() .promise(); - // Should have thrown by then + // Should have thrown a TypeError by then $ASSERT(false) } catch (e) { - if (e.message != 'false') $ASSERT(e instanceof TypeError) + $ASSERT(e instanceof TypeError); } }); @@ -561,14 +562,14 @@ describe('Data.Task', () => { .map((() => false ? Result.a : Result.b)) .run() .promise(); - // Should have thrown by then + // Should have thrown a TypeError by then $ASSERT(false) + // But throws an AssertionError instead } catch (e) { - if (e.message != 'false') $ASSERT(e instanceof TypeError) + $ASSERT(e instanceof TypeError); } }); - }); describe('#future()', () => { From be96da55749c125cec433b3b574cfa91c9717606 Mon Sep 17 00:00:00 2001 From: Jun Matsushita Date: Sat, 18 Nov 2017 11:29:48 +0100 Subject: [PATCH 3/3] Cleanup --- package-lock.json | 2 +- test/source/specs/base/concurrency/task.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3a6a86d..20d70b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3001,7 +3001,7 @@ "dev": true }, "furipota": { - "version": "github:origamitower/furipota#babefc35b82e527169aaaa0557f6d018933132ff", + "version": "github:origamitower/furipota#52c4d8d72a93101bc1db18979d96b9aae9dd0649", "dev": true, "requires": { "chalk": "1.1.3", diff --git a/test/source/specs/base/concurrency/task.js b/test/source/specs/base/concurrency/task.js index 6efa913..6e8bbc1 100644 --- a/test/source/specs/base/concurrency/task.js +++ b/test/source/specs/base/concurrency/task.js @@ -540,7 +540,6 @@ describe('Data.Task', () => { }); it('Deals with exception', async () => { - const AssertionError = require('assert').AssertionError; let Result = undefined; try {