|
| 1 | +var test = require('../'); |
| 2 | +var harness = test.createHarness(); |
| 3 | + |
| 4 | +// minimal write stream mockery |
| 5 | +var collector = { |
| 6 | + written: [], |
| 7 | + ended: false, |
| 8 | + writable: true, |
| 9 | + write: function (c) { |
| 10 | + console.log('#> %s', c.replace(/\n$/, '').split(/\n/).join('\n#> ')); |
| 11 | + if (this.ended) |
| 12 | + throw new Error('write after end'); |
| 13 | + this.written.push(c); |
| 14 | + return true; |
| 15 | + }, |
| 16 | + end: function (c) { |
| 17 | + console.error('collector end'); |
| 18 | + if (this.ended) |
| 19 | + throw new Error('end after end'); |
| 20 | + if (c) |
| 21 | + this.write(c); |
| 22 | + this.ended = true; |
| 23 | + }, |
| 24 | + on: function () {}, |
| 25 | + emit: function () {}, |
| 26 | + removeListener: function () {} |
| 27 | +}; |
| 28 | + |
| 29 | +var wanted = |
| 30 | + [ 'TAP version 13', |
| 31 | + '# harness test', |
| 32 | + '# hello', |
| 33 | + 'ok 1 this is ok', |
| 34 | + 'not ok 2 this is not ok', |
| 35 | + ' ---', |
| 36 | + ' operator: fail', |
| 37 | + ' expected:', |
| 38 | + ' actual:', |
| 39 | + ' ...', |
| 40 | + '# sub harness test', |
| 41 | + 'ok 3 math still works', |
| 42 | + 'ok 4 except when it doesn\'t', |
| 43 | + '# sub harness internal test', |
| 44 | + 'ok 5 gas', |
| 45 | + 'ok 6 lulz i am immature', |
| 46 | + '', |
| 47 | + '1..6', |
| 48 | + '# tests 6', |
| 49 | + '# pass 5', |
| 50 | + '# fail 1', |
| 51 | + '' ]; |
| 52 | + |
| 53 | +harness.stream.pipe(collector); |
| 54 | + |
| 55 | +test('correct output', function (t) { |
| 56 | + harness.stream.on('end', function () { |
| 57 | + // accept trailing whitespace, or multiple lines on the same write(), |
| 58 | + var found = collector.written.join('').split(/\n/).map(function (s) { |
| 59 | + return s.replace(/\s+$/, ''); |
| 60 | + }); |
| 61 | + t.same(found, wanted, 'got expected output'); |
| 62 | + t.end(); |
| 63 | + }); |
| 64 | + |
| 65 | + harness('harness test', function (ht) { |
| 66 | + // console.error('harness stream', harness.stream); |
| 67 | + ht.comment('hello'); |
| 68 | + ht.pass('this is ok'); |
| 69 | + ht.fail('this is not ok'); |
| 70 | + ht.test('sub harness test', function (sht) { |
| 71 | + sht.equal(4, 4, 'math still works'); |
| 72 | + sht.notEqual(0.1 + 0.1 + 0.1, 0.3, 'except when it doesn\'t'); |
| 73 | + sht.test('sub harness internal test', function (shit) { |
| 74 | + console.error('sub harness internal test'); |
| 75 | + // shit.plan(2); |
| 76 | + shit.pass('gas'); |
| 77 | + shit.pass('lulz i am immature'); |
| 78 | + shit.end(); |
| 79 | + }); |
| 80 | + sht.end(); |
| 81 | + }); |
| 82 | + ht.end(); |
| 83 | + console.error('called ht.end'); |
| 84 | + }); |
| 85 | +}); |
| 86 | + |
| 87 | + |
| 88 | +// vim: set softtabstop=4 shiftwidth=4: |
0 commit comments