2012-09-10 18:24:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 Trent Mick. All rights reserved.
|
|
|
|
*
|
|
|
|
* Make sure cycles are safe.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var Logger = require('../lib/bunyan.js');
|
|
|
|
|
2013-01-07 19:18:12 +00:00
|
|
|
// node-tap API
|
|
|
|
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
|
|
|
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
|
|
|
var tap4nodeunit = require('./tap4nodeunit.js');
|
|
|
|
var after = tap4nodeunit.after;
|
|
|
|
var before = tap4nodeunit.before;
|
|
|
|
var test = tap4nodeunit.test;
|
|
|
|
|
|
|
|
|
2012-09-10 18:24:39 +00:00
|
|
|
var Stream = require('stream').Stream;
|
|
|
|
var outstr = new Stream;
|
|
|
|
outstr.writable = true;
|
|
|
|
var output = [];
|
|
|
|
outstr.write = function (c) {
|
|
|
|
output.push(JSON.parse(c + ''));
|
|
|
|
};
|
|
|
|
outstr.end = function (c) {
|
|
|
|
if (c) this.write(c);
|
|
|
|
this.emit('end');
|
|
|
|
};
|
|
|
|
|
|
|
|
// these are lacking a few fields that will probably never match
|
|
|
|
var expect =
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"name": "blammo",
|
|
|
|
"level": 30,
|
|
|
|
"msg": "bango { bang: 'boom', KABOOM: [Circular] }",
|
|
|
|
"v": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "blammo",
|
|
|
|
"level": 30,
|
|
|
|
"msg": "kaboom { bang: 'boom', KABOOM: [Circular] }",
|
|
|
|
"v": 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "blammo",
|
|
|
|
"level": 30,
|
|
|
|
"bang": "boom",
|
|
|
|
"KABOOM": {
|
|
|
|
"bang": "boom",
|
|
|
|
"KABOOM": "[Circular]"
|
|
|
|
},
|
|
|
|
"msg": "",
|
|
|
|
"v": 0
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
var log = new Logger({
|
|
|
|
name: 'blammo',
|
|
|
|
streams: [
|
|
|
|
{
|
|
|
|
type: 'stream',
|
|
|
|
level: 'info',
|
|
|
|
stream: outstr
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
test('cycles', function (t) {
|
|
|
|
outstr.on('end', function () {
|
|
|
|
output.forEach(function (o, i) {
|
2013-01-07 19:18:12 +00:00
|
|
|
// Drop variable parts for comparison.
|
|
|
|
delete o.hostname;
|
|
|
|
delete o.pid;
|
|
|
|
delete o.time;
|
|
|
|
// Hack object/dict comparison: JSONify.
|
|
|
|
t.equal(JSON.stringify(o), JSON.stringify(expect[i]),
|
|
|
|
'log item ' + i + ' matches');
|
2012-09-10 18:24:39 +00:00
|
|
|
});
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
var obj = { bang: 'boom' };
|
|
|
|
obj.KABOOM = obj;
|
|
|
|
log.info('bango', obj);
|
|
|
|
log.info('kaboom', obj.KABOOM);
|
|
|
|
log.info(obj);
|
|
|
|
outstr.end();
|
2013-01-07 19:18:12 +00:00
|
|
|
t.ok('did not throw');
|
2012-09-10 18:24:39 +00:00
|
|
|
});
|