fix: Cleanup dogfood tests.

This commit is contained in:
Jeremy Wall 2024-04-01 10:50:37 -04:00
parent d4da1d7dee
commit 44feb46f69
2 changed files with 50 additions and 41 deletions

View File

@ -64,8 +64,8 @@ class Tap {
* Construct a new Tap Suite with a renderLine function. * Construct a new Tap Suite with a renderLine function.
* @param {TapRenderer} * @param {TapRenderer}
*/ */
constructor(renderFunc) { constructor(renderer) {
this.#renderer = renderFunc; this.#renderer = renderer;
} }
@ -383,6 +383,5 @@ function runBrowserTap(testName, test) {
return runTest(t, testName, test); return runTest(t, testName, test);
} }
// TODO(zaphar): The runner interface as well.
export { Tap, runNodeTap, runBrowserTap }; export { Tap, runNodeTap, runBrowserTap };

View File

@ -1,16 +1,29 @@
/** @implements TapRenderer */
class FakeRenderer {
output = "nothing yet";
diagnostic = "";
out(text) {
this.output = text;
}
diag(lines) {
for (var line of lines) {
this.diagnostic += line;
}
}
}
import('../src/TAP.mjs').then(m => { import('../src/TAP.mjs').then(m => {
var runNodeTap = m.runNodeTap; var runNodeTap = m.runNodeTap;
function tapSuite(t) { function tapSuite(t) {
var out = "nothing yet"; t.plan(23);
var diag = "";
t.plan(17);
var renderer = new FakeRenderer();
var testCan = function () { var testCan = function () {
// setup fake test object // setup fake test object
var f = new m.Tap(function(newout) { out = newout }); // the TAP thats failing var f = new m.Tap(renderer); // the TAP thats failing
f.out = function(newout) { out = newout };
f.diag = function(newdiag) { diag += newdiag };
f.plan(4); f.plan(4);
//mock a fake object to run test against //mock a fake object to run test against
@ -20,10 +33,10 @@ import('../src/TAP.mjs').then(m => {
// begin real tests! // begin real tests!
f.can_ok(obj, 'not_there'); f.can_ok(obj, 'not_there');
t.like(out, /not ok 1 - object can \[ not_there \]/, 'can_ok failed'); t.like(renderer.output, /not ok 1 - object can \[ not_there \]/, 'can_ok failed');
f.can_ok(obj, method); f.can_ok(obj, method);
diag = ''; diag = '';
t.like(out, /ok 2 - object can \[ run \]/, 'can_ok passed'); t.like(renderer.output, /ok 2 - object can \[ run \]/, 'can_ok passed');
//Now we need to test the whole prototype method assignment thing //Now we need to test the whole prototype method assignment thing
@ -34,67 +47,67 @@ import('../src/TAP.mjs').then(m => {
MockObj.prototype.fakeme = function () {}; MockObj.prototype.fakeme = function () {};
f.can_ok(MockObj, 'fakeme'); f.can_ok(MockObj, 'fakeme');
diag = ''; renderer.diagnostic = '';
t.like(out, /^ok .* \[ fakeme \]/, t.like(renderer.output, /^ok .* \[ fakeme \]/,
'can_ok recognized prototype methods'); 'can_ok recognized prototype methods');
f.can_ok(MockObj, 'fakeme2'); f.can_ok(MockObj, 'fakeme2');
diag = ''; renderer.diagnostic = '';
t.like(out, /^not ok .* \[ fakeme2 \]/, t.like(renderer.output, /^not ok .* \[ fakeme2 \]/,
'can_ok prototype recognization doesnt break methods'); 'can_ok prototype recognization doesnt break methods');
}; };
testCan();
var testLike = function() { var testLike = function() {
// setup fake test object // setup fake test object
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing var f = new m.Tap(renderer); // the TAP that's failing
f.out = function(newout) { out = newout };
f.plan(1); f.plan(1);
// begin real tests! // begin real tests!
f.like("hello", /hello/, "hello matches hello"); f.like("hello", /hello/, "hello matches hello");
t.like(out, /ok 1 - hello matches hello/, 'got description in TAP output'); t.like(renderer.output, /ok 1 - hello matches hello/, 'got description in TAP output');
}; };
testLike()
var testDiag = function() { var testDiag = function() {
// setup fake test object // setup fake test object
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing var f = new m.Tap(renderer); // the TAP that's failing
f.out = function(newout) { out = newout };
f.plan(10); f.plan(10);
// begin real tests! // begin real tests!
f.diag("hello"); f.diag("hello");
t.like(out, /# hello/, 'got hello'); t.diag(renderer.diagnostic);
t.like(renderer.diagnostic, /hello/, 'got hello');
}; };
testDiag();
var testException = function() { var testException = function() {
// setup fake test object // setup fake test object
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing var f = new m.Tap(renderer); // the TAP that's failing
f.out = function(newout) { out = newout };
f.plan(2); f.plan(2);
// begin real tests! // begin real tests!
f.throws_ok(function() {throw new Error('I made a boo boo')}, 'I made a boo boo'); f.throws_ok(function() {throw new Error('I made a boo boo')}, 'I made a boo boo');
//t.diag(out); //t.diag(renderer.output);
t.like(out, /ok 1 - code threw \[Error: I made a boo boo\]/, 'uncaught exception'); t.like(renderer.output, /ok 1 - code threw \[Error: I made a boo boo\]/, 'uncaught exception');
f.throws_ok(function() {}, 'I made a boo boo'); f.throws_ok(function() {}, 'I made a boo boo');
//t.diag(out); //t.diag(renderer.output);
t.like(out, /not ok 2 - code threw \[ \]/, 'false failed'); t.like(renderer.output, /not ok 2 - code threw \[ \]/, 'false failed');
}; };
testException(); testException();
var testFails = function() { var testFails = function() {
// setup fake test object // setup fake test object
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing var f = new m.Tap(renderer); // the TAP that's failing
f.out = function(newout) { out = newout };
f.plan(3); f.plan(3);
// begin real tests! // begin real tests!
f.ok(false, 'false fails'); f.ok(false, 'false fails');
t.like(out, /not ok 1 - false fails/, 'false failed'); t.like(renderer.output, /not ok 1 - false fails/, 'false failed');
f.ok(0, 'zero fails'); f.ok(0, 'zero fails');
t.like(out, /not ok 2 - zero fails/, '0 failed'); t.like(renderer.output, /not ok 2 - zero fails/, '0 failed');
f.is(0, 1, 'zero is one'); f.is(0, 1, 'zero is one');
t.like(out, /not ok 3 - zero is one/, '0 != 1'); t.like(renderer.output, /not ok 3 - zero is one/, '0 != 1');
}; };
testFails(); testFails();
@ -109,8 +122,7 @@ import('../src/TAP.mjs').then(m => {
var testPlan = function() { var testPlan = function() {
// setup fake test object // setup fake test object
var f = new m.Tap(function(newout) { out = newout }); // the TAP that's failing var f = new m.Tap(renderer); // the TAP that's failing
f.out = function(newout) { out = newout };
f.plan(2); f.plan(2);
// begin real tests! // begin real tests!
@ -121,29 +133,27 @@ import('../src/TAP.mjs').then(m => {
testPlan(); testPlan();
var testTodoSkip = function() { var testTodoSkip = function() {
var out;
t.can_ok(m.Tap, 'todo', 'skip'); t.can_ok(m.Tap, 'todo', 'skip');
var f = new m.Tap(); // the TAP that's failing var f = new m.Tap(renderer); // the TAP that's failing
f.out = function(newout) { out = newout };
f.plan(4); f.plan(4);
f.todo(function() { f.todo(function() {
f.ok(true, 'true is true'); f.ok(true, 'true is true');
}); });
t.like(out, /ok 1 - # TODO: true is true/g, t.like(renderer.output, /ok 1 - # TODO: true is true/g,
'the non todo output is suitably formatted'); 'the non todo output is suitably formatted');
f.ok(!false, 'not false is true'); f.ok(!false, 'not false is true');
t.like(out, /ok 2 -/g, 'the regular output is suitably formatted'); t.like(renderer.output, /ok 2 -/g, 'the regular output is suitably formatted');
f.skip(true, 'because I said so', 1, f.skip(true, 'because I said so', 1,
function() { function() {
f.is(1, 2, 'one is two'); f.is(1, 2, 'one is two');
} }
); );
t.like(out, /^not ok 3 - # SKIP because I said so$/, t.like(renderer.output, /^not ok 3 - # SKIP because I said so$/,
'the skipped output is suitably formatted'); 'the skipped output is suitably formatted');
f.is(1, 1, 'one is one'); f.is(1, 1, 'one is one');
t.like(out, /ok 4 - one is one/, t.like(renderer.output, /ok 4 - one is one/,
'the non skipped output is suitable formatted'); 'the non skipped output is suitable formatted');
}; };
testTodoSkip(); testTodoSkip();