only want TZ set for the tests that need it, not everything run via this Makefile

This commit is contained in:
Trent Mick 2016-02-10 22:31:53 -08:00
parent 6ff1f36abc
commit 8bb8a746dc
2 changed files with 28 additions and 15 deletions

View file

@ -18,8 +18,6 @@ ifeq ($(shell uname -s),Darwin)
endif endif
NODEOPT ?= $(HOME)/opt NODEOPT ?= $(HOME)/opt
# Run tests in a set timezone, so local time is predictable
export TZ=Pacific/Honolulu
#---- Files #---- 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) NON_DTRACE_TEST_FILES := $(shell ls -1 test/*.test.js | grep -v dtrace | xargs)
#---- Targets #---- Targets
all $(NODEUNIT): all $(NODEUNIT):

View file

@ -20,17 +20,29 @@ var before = tap4nodeunit.before;
var test = tap4nodeunit.test; var test = tap4nodeunit.test;
// ---- globals
var BUNYAN = path.resolve(__dirname, '../bin/bunyan'); var BUNYAN = path.resolve(__dirname, '../bin/bunyan');
//child = exec('cat *.js bad_file | wc -l',
// function (error, stdout, stderr) { // ---- support stuff
// console.log('stdout: ' + stdout);
// console.log('stderr: ' + stderr); /**
// if (error !== null) { * Copies over all keys in `from` to `to`, or
// console.log('exec error: ' + error); * 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) { test('--version', function (t) {
var version = require('../package.json').version; 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) { test('time: simple.log local long', function (t) {
exec(_('%s -o long -L %s/corpus/simple.log', BUNYAN, __dirname), 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.ifError(err)
t.equal(stdout, t.equal(stdout,
'[2012-02-08T12:56:52.856-10:00] INFO: myservice/123 on example.com: ' '[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) { test('time: simple.log utc long', function (t) {
exec(_('%s -o long --time utc %s/corpus/simple.log', BUNYAN, __dirname), 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.ifError(err)
t.equal(stdout, t.equal(stdout,
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: ' '[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) { test('time: simple.log local short', function (t) {
exec(_('%s -o short -L %s/corpus/simple.log', BUNYAN, __dirname), 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.ifError(err)
t.equal(stdout, t.equal(stdout,
'12:56:52.856 INFO myservice: ' '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) { test('time: simple.log utc short', function (t) {
exec(_('%s -o short %s/corpus/simple.log', BUNYAN, __dirname), exec(_('%s -o short %s/corpus/simple.log', BUNYAN, __dirname),
function (err, stdout, stderr) { {env: tzEnv}, function (err, stdout, stderr) {
t.ifError(err) t.ifError(err)
t.equal(stdout, t.equal(stdout,
'22:56:52.856Z INFO myservice: ' '22:56:52.856Z INFO myservice: '