From 2b4f0ce7aa59761d5cfb13498c5155f02433d7d1 Mon Sep 17 00:00:00 2001 From: "Mark S. Miller" Date: Fri, 8 Mar 2024 12:47:16 -0800 Subject: [PATCH] fixup! review suggestions --- .../test/test-deep-send-ses-ava.js | 30 ------------------- packages/eventual-send/test/test-deep-send.js | 27 +++++++++++------ .../test/test-deep-stacks-ses-ava.js | 18 ----------- .../eventual-send/test/test-deep-stacks.js | 26 ++++++++++------ 4 files changed, 35 insertions(+), 66 deletions(-) delete mode 100644 packages/eventual-send/test/test-deep-send-ses-ava.js delete mode 100644 packages/eventual-send/test/test-deep-stacks-ses-ava.js diff --git a/packages/eventual-send/test/test-deep-send-ses-ava.js b/packages/eventual-send/test/test-deep-send-ses-ava.js deleted file mode 100644 index 46988636eb..0000000000 --- a/packages/eventual-send/test/test-deep-send-ses-ava.js +++ /dev/null @@ -1,30 +0,0 @@ -// This file is not really useful as an -// automated test. Rather, its purpose is just to run it to see what a -// deep stack looks like. - -// eslint-disable-next-line import/no-extraneous-dependencies -import { test } from './prepare-test-env-ava.js'; - -import { E } from './get-hp.js'; - -const { freeze } = Object; - -const carol = freeze({ - bar: () => assert.fail('Wut?'), -}); - -const bob = freeze({ - foo: carolP => E(carolP).bar(), -}); - -const alice = freeze({ - test: () => E(bob).foo(carol), -}); - -test('deep-stacks E ses-ava', t => { - const q = alice.test(); - return q.catch(reason => { - t.assert(reason instanceof Error); - t.log('expected failure', reason); - }); -}); diff --git a/packages/eventual-send/test/test-deep-send.js b/packages/eventual-send/test/test-deep-send.js index f19b622b57..3d4c652476 100644 --- a/packages/eventual-send/test/test-deep-send.js +++ b/packages/eventual-send/test/test-deep-send.js @@ -10,21 +10,30 @@ import { E } from './get-hp.js'; const { freeze } = Object; const carol = freeze({ - bar: () => assert.fail('Wut?'), + // Throw an error with redacted contents (here, a string and a number). + bar: label => assert.Fail`[${assert.quote(label)}] ${'blue'} is not ${42}`, }); const bob = freeze({ - foo: carolP => E(carolP).bar(), + foo: (label, carolP) => E(carolP).bar(label), }); const alice = freeze({ - test: () => E(bob).foo(carol), + test: label => E(bob).foo(label, carol), }); -test('deep-stacks E', t => { - const q = alice.test(); - return q.catch(reason => { - t.assert(reason instanceof Error); - console.log('expected failure', reason); - }); +const testDeepStacksE = test.macro({ + title: (title, loggerDescription, _getLogger) => + `deep-stacks E with ${loggerDescription}${title ? ` (${title})` : ''}`, + exec: (t, loggerDescription, getLogger) => { + const p = alice.test(loggerDescription); + return p.catch(reason => { + t.true(reason instanceof Error); + const log = getLogger(t); + log('expected failure', reason); + }); + }, }); + +test(testDeepStacksE, 'console.log', _t => console.log.bind(console)); +test(testDeepStacksE, 'ses-ava t.log', t => t.log.bind(t)); diff --git a/packages/eventual-send/test/test-deep-stacks-ses-ava.js b/packages/eventual-send/test/test-deep-stacks-ses-ava.js deleted file mode 100644 index b6c4ac60fb..0000000000 --- a/packages/eventual-send/test/test-deep-stacks-ses-ava.js +++ /dev/null @@ -1,18 +0,0 @@ -// This file is not really useful as an -// automated test. Rather, its purpose is just to run it to see what a -// deep stack looks like. - -import { test } from './prepare-test-env-ava.js'; - -import { E } from './get-hp.js'; - -test('deep-stacks when ses-ava', t => { - let r; - const p = new Promise(res => (r = res)); - const q = E.when(p, v1 => E.when(v1 + 1, v2 => assert.equal(v2, 22))); - r(33); - return q.catch(reason => { - t.assert(reason instanceof Error); - t.log('expected failure', reason); - }); -}); diff --git a/packages/eventual-send/test/test-deep-stacks.js b/packages/eventual-send/test/test-deep-stacks.js index c780f07d94..40ad769bed 100644 --- a/packages/eventual-send/test/test-deep-stacks.js +++ b/packages/eventual-send/test/test-deep-stacks.js @@ -6,13 +6,21 @@ import { test } from './prepare-test-env-ava.js'; import { E } from './get-hp.js'; -test('deep-stacks when', t => { - let r; - const p = new Promise(res => (r = res)); - const q = E.when(p, v1 => E.when(v1 + 1, v2 => assert.equal(v2, 22))); - r(33); - return q.catch(reason => { - t.assert(reason instanceof Error); - console.log('expected failure', reason); - }); +const testDeepStacksWhen = test.macro({ + title: (title, loggerDescription, _getLogger) => + `deep-stacks E.when with ${loggerDescription}${title ? ` (${title})` : ''}`, + exec: (t, _loggerDescription, getLogger) => { + let r; + const p = new Promise(res => (r = res)); + const q = E.when(p, v1 => E.when(v1 + 1, v2 => assert.equal(v2, 22))); + r(33); + return q.catch(reason => { + t.assert(reason instanceof Error); + const log = getLogger(t); + log('expected failure', reason); + }); + }, }); + +test(testDeepStacksWhen, 'console.log', _t => console.log.bind(console)); +test(testDeepStacksWhen, 'ses-ava t.log', t => t.log.bind(t));