From 8bb8a746dcf683c7f34dbd862107461e4c7cd319 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Wed, 10 Feb 2016 22:31:53 -0800 Subject: [PATCH] only want TZ set for the tests that need it, not everything run via this Makefile --- Makefile | 3 --- test/cli.test.js | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 0e52310..3c6ea9a 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,6 @@ ifeq ($(shell uname -s),Darwin) endif NODEOPT ?= $(HOME)/opt -# Run tests in a set timezone, so local time is predictable -export TZ=Pacific/Honolulu #---- Files @@ -28,7 +26,6 @@ JSSTYLE_FILES := $(shell find lib test tools examples -name "*.js") bin/bunyan NON_DTRACE_TEST_FILES := $(shell ls -1 test/*.test.js | grep -v dtrace | xargs) - #---- Targets all $(NODEUNIT): diff --git a/test/cli.test.js b/test/cli.test.js index d056548..4a33060 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -20,17 +20,29 @@ var before = tap4nodeunit.before; var test = tap4nodeunit.test; +// ---- globals var BUNYAN = path.resolve(__dirname, '../bin/bunyan'); -//child = exec('cat *.js bad_file | wc -l', -// function (error, stdout, stderr) { -// console.log('stdout: ' + stdout); -// console.log('stderr: ' + stderr); -// if (error !== null) { -// console.log('exec error: ' + error); -// } -//}); + +// ---- support stuff + +/** + * Copies over all keys in `from` to `to`, or + * to a new object if `to` is not given. + */ +function objCopy(from, to) { + if (to === undefined) { + to = {}; + } + for (var k in from) { + to[k] = from[k]; + } + return to; +} + + +// ---- tests test('--version', function (t) { var version = require('../package.json').version; @@ -87,9 +99,13 @@ test('cat simple.log', function (t) { ); }); +// A stable 'TZ' for 'local' timezone output. +tzEnv = objCopy(process.env); +tzEnv.TZ = 'Pacific/Honolulu'; + test('time: simple.log local long', function (t) { exec(_('%s -o long -L %s/corpus/simple.log', BUNYAN, __dirname), - function (err, stdout, stderr) { + {env: tzEnv}, function (err, stdout, stderr) { t.ifError(err) t.equal(stdout, '[2012-02-08T12:56:52.856-10:00] INFO: myservice/123 on example.com: ' @@ -99,7 +115,7 @@ test('time: simple.log local long', function (t) { }); test('time: simple.log utc long', function (t) { exec(_('%s -o long --time utc %s/corpus/simple.log', BUNYAN, __dirname), - function (err, stdout, stderr) { + {env: tzEnv}, function (err, stdout, stderr) { t.ifError(err) t.equal(stdout, '[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: ' @@ -109,7 +125,7 @@ test('time: simple.log utc long', function (t) { }); test('time: simple.log local short', function (t) { exec(_('%s -o short -L %s/corpus/simple.log', BUNYAN, __dirname), - function (err, stdout, stderr) { + {env: tzEnv}, function (err, stdout, stderr) { t.ifError(err) t.equal(stdout, '12:56:52.856 INFO myservice: ' @@ -119,7 +135,7 @@ test('time: simple.log local short', function (t) { }); test('time: simple.log utc short', function (t) { exec(_('%s -o short %s/corpus/simple.log', BUNYAN, __dirname), - function (err, stdout, stderr) { + {env: tzEnv}, function (err, stdout, stderr) { t.ifError(err) t.equal(stdout, '22:56:52.856Z INFO myservice: '