Skip to content

Commit

Permalink
only want TZ set for the tests that need it, not everything run via t…
Browse files Browse the repository at this point in the history
…his Makefile
  • Loading branch information
trentm committed Feb 11, 2016
1 parent 6ff1f36 commit 8bb8a74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
3 changes: 0 additions & 3 deletions Makefile
Expand Up @@ -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

Expand All @@ -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):
Expand Down
40 changes: 28 additions & 12 deletions test/cli.test.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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: '
Expand All @@ -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: '
Expand All @@ -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: '
Expand All @@ -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: '
Expand Down

0 comments on commit 8bb8a74

Please sign in to comment.