From 104af1fcad7f92d866cc2ddc7e4f688c854995cb Mon Sep 17 00:00:00 2001 From: James Halliday Date: Mon, 3 Dec 2012 13:53:50 -0800 Subject: [PATCH] failing exit test --- test/exit.js | 72 +++++++++++++++++++++++++++++++++++++++++++++++ test/exit/fail.js | 35 +++++++++++++++++++++++ test/exit_ok.js | 37 ------------------------ 3 files changed, 107 insertions(+), 37 deletions(-) create mode 100644 test/exit.js create mode 100644 test/exit/fail.js delete mode 100644 test/exit_ok.js diff --git a/test/exit.js b/test/exit.js new file mode 100644 index 00000000..76902081 --- /dev/null +++ b/test/exit.js @@ -0,0 +1,72 @@ +var tap = require('tap'); +var spawn = require('child_process').spawn; + +tap.test('exit ok', function (t) { + t.plan(2); + + var tc = tap.createConsumer(); + + var rows = []; + tc.on('data', function (r) { rows.push(r) }); + tc.on('end', function () { + var rs = rows.map(function (r) { + if (r && typeof r === 'object') { + return { id : r.id, ok : r.ok, name : r.name.trim() }; + } + else return r; + }); + t.same(rs, [ + 'TAP version 13', + 'array', + { id: 1, ok: true, name: 'should be equivalent' }, + { id: 2, ok: true, name: 'should be equivalent' }, + { id: 3, ok: true, name: 'should be equivalent' }, + { id: 4, ok: true, name: 'should be equivalent' }, + { id: 5, ok: true, name: 'should be equivalent' }, + 'tests 5', + 'pass 5', + 'ok' + ]); + }); + + var ps = spawn(process.execPath, [ __dirname + '/exit/ok.js' ]); + ps.stdout.pipe(tc); + ps.on('exit', function (code) { + t.equal(code, 0); + }); +}); + +tap.test('exit fail', function (t) { + t.plan(2); + + var tc = tap.createConsumer(); + + var rows = []; + tc.on('data', function (r) { rows.push(r) }); + tc.on('end', function () { + var rs = rows.map(function (r) { + if (r && typeof r === 'object') { + return { id : r.id, ok : r.ok, name : r.name.trim() }; + } + else return r; + }); + t.same(rs, [ + 'TAP version 13', + 'array', + { id: 1, ok: true, name: 'should be equivalent' }, + { id: 2, ok: true, name: 'should be equivalent' }, + { id: 3, ok: true, name: 'should be equivalent' }, + { id: 4, ok: true, name: 'should be equivalent' }, + { id: 5, ok: false, name: 'should be equivalent' }, + 'tests 5', + 'pass 4', + 'fail 1' + ]); + }); + + var ps = spawn(process.execPath, [ __dirname + '/exit/fail.js' ]); + ps.stdout.pipe(tc); + ps.on('exit', function (code) { + t.notEqual(code, 0); + }); +}); diff --git a/test/exit/fail.js b/test/exit/fail.js new file mode 100644 index 00000000..d7fd3ce7 --- /dev/null +++ b/test/exit/fail.js @@ -0,0 +1,35 @@ +var test = require('../../'); +var falafel = require('falafel'); + +test('array', function (t) { + t.plan(5); + + var src = '(' + function () { + var xs = [ 1, 2, [ 3, 4 ] ]; + var ys = [ 5, 6 ]; + g([ xs, ys ]); + } + ')()'; + + var output = falafel(src, function (node) { + if (node.type === 'ArrayExpression') { + node.update('fn(' + node.source() + ')'); + } + }); + + var arrays = [ + [ 3, 4 ], + [ 1, 2, [ 3, 4 ] ], + [ 5, 6 ], + [ [ 1, 2, [ 3, 4 ] ], [ 5, 6 ] ], + ]; + + Function(['fn','g'], output)( + function (xs) { + t.same(arrays.shift(), xs); + return xs; + }, + function (xs) { + t.same(xs, [ [ 1, 2, [ 3, 4444 ] ], [ 5, 6 ] ]); + } + ); +}); diff --git a/test/exit_ok.js b/test/exit_ok.js deleted file mode 100644 index 5492b990..00000000 --- a/test/exit_ok.js +++ /dev/null @@ -1,37 +0,0 @@ -var tap = require('tap'); -var spawn = require('child_process').spawn; - -tap.test('array test', function (t) { - t.plan(2); - - var tc = tap.createConsumer(); - - var rows = []; - tc.on('data', function (r) { rows.push(r) }); - tc.on('end', function () { - var rs = rows.map(function (r) { - if (r && typeof r === 'object') { - return { id : r.id, ok : r.ok, name : r.name.trim() }; - } - else return r; - }); - t.same(rs, [ - 'TAP version 13', - 'array', - { id: 1, ok: true, name: 'should be equivalent' }, - { id: 2, ok: true, name: 'should be equivalent' }, - { id: 3, ok: true, name: 'should be equivalent' }, - { id: 4, ok: true, name: 'should be equivalent' }, - { id: 5, ok: true, name: 'should be equivalent' }, - 'tests 5', - 'pass 5', - 'ok' - ]); - }); - - var ps = spawn(process.execPath, [ __dirname + '/exit/ok.js' ]); - ps.stdout.pipe(tc); - ps.on('exit', function (code) { - t.equal(code, 0); - }); -});