Make some test windows friendly.

This commit is contained in:
Pavel Sysolyatin 2014-07-17 14:29:03 +07:00
parent eaa77b0454
commit 3c4c98bb0b
7 changed files with 38 additions and 28 deletions

View File

@ -2,7 +2,8 @@
var vows = require('vows') var vows = require('vows')
, fs = require('fs') , fs = require('fs')
, assert = require('assert'); , assert = require('assert')
, EOL = require('os').EOL || '\n';
function remove(filename) { function remove(filename) {
try { try {
@ -66,7 +67,7 @@ vows.describe('log4js categoryFilter').addBatch({
fs.readFile(__dirname + '/categoryFilter-noweb.log', 'utf8', this.callback); fs.readFile(__dirname + '/categoryFilter-noweb.log', 'utf8', this.callback);
}, },
'should contain all log messages': function(contents) { 'should contain all log messages': function(contents) {
var messages = contents.trim().split('\n'); var messages = contents.trim().split(EOL);
assert.deepEqual(messages, ['Loading app','Initialising indexes']); assert.deepEqual(messages, ['Loading app','Initialising indexes']);
} }
}, },
@ -75,7 +76,7 @@ vows.describe('log4js categoryFilter').addBatch({
fs.readFile(__dirname + '/categoryFilter-web.log','utf8',this.callback); fs.readFile(__dirname + '/categoryFilter-web.log','utf8',this.callback);
}, },
'should contain only error and warning log messages': function(contents) { 'should contain only error and warning log messages': function(contents) {
var messages = contents.trim().split('\n'); var messages = contents.trim().split(EOL);
assert.deepEqual(messages, ['00:00:00 GET / 200','00:00:00 GET / 500']); assert.deepEqual(messages, ['00:00:00 GET / 200','00:00:00 GET / 500']);
} }
} }

View File

@ -214,7 +214,8 @@ vows.describe('../lib/appenders/dateFile').addBatch({
return fileOpened; return fileOpened;
}, },
'should prepend options.cwd to config.filename': function (fileOpened) { 'should prepend options.cwd to config.filename': function (fileOpened) {
assert.equal(fileOpened, "/absolute/path/to/whatever.log"); var expected = path.sep + path.join("absolute", "path", "to", "whatever.log");
assert.equal(fileOpened, expected);
} }
} }

View File

@ -4,7 +4,8 @@ var vows = require('vows')
, path = require('path') , path = require('path')
, sandbox = require('sandboxed-module') , sandbox = require('sandboxed-module')
, log4js = require('../lib/log4js') , log4js = require('../lib/log4js')
, assert = require('assert'); , assert = require('assert')
, EOL = require('os').EOL || '\n';
log4js.clearAppenders(); log4js.clearAppenders();
@ -94,7 +95,7 @@ vows.describe('log4js fileAppender').addBatch({
}, 100); }, 100);
}, },
'should write log messages to the file': function (err, fileContents) { 'should write log messages to the file': function (err, fileContents) {
assert.include(fileContents, "This should be in the file.\n"); assert.include(fileContents, "This should be in the file." + EOL);
}, },
'log messages should be in the basic layout format': function(err, fileContents) { 'log messages should be in the basic layout format': function(err, fileContents) {
assert.match( assert.match(
@ -125,7 +126,7 @@ vows.describe('log4js fileAppender').addBatch({
}, 100); }, 100);
}, },
'log file should only contain the second message': function(err, fileContents) { 'log file should only contain the second message': function(err, fileContents) {
assert.include(fileContents, "This is the second log message.\n"); assert.include(fileContents, "This is the second log message.");
assert.equal(fileContents.indexOf("This is the first log message."), -1); assert.equal(fileContents.indexOf("This is the first log message."), -1);
}, },
'the number of files': { 'the number of files': {
@ -230,7 +231,7 @@ vows.describe('log4js fileAppender').addBatch({
fs.readFile('tmp-tests.log', 'utf8', this.callback); fs.readFile('tmp-tests.log', 'utf8', this.callback);
}, },
'should load appender configuration from a json file': function (err, contents) { 'should load appender configuration from a json file': function (err, contents) {
assert.include(contents, 'this should be written to the file\n'); assert.include(contents, 'this should be written to the file' + EOL);
assert.equal(contents.indexOf('this should not be written to the file'), -1); assert.equal(contents.indexOf('this should not be written to the file'), -1);
} }
} }

View File

@ -4,7 +4,8 @@ var vows = require('vows')
, path = require('path') , path = require('path')
, sandbox = require('sandboxed-module') , sandbox = require('sandboxed-module')
, log4js = require('../lib/log4js') , log4js = require('../lib/log4js')
, assert = require('assert'); , assert = require('assert')
, EOL = require('os').EOL || '\n';
log4js.clearAppenders(); log4js.clearAppenders();
@ -32,7 +33,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
fs.readFile(testFile, "utf8", that.callback); fs.readFile(testFile, "utf8", that.callback);
}, },
'should write log messages to the file': function (err, fileContents) { 'should write log messages to the file': function (err, fileContents) {
assert.include(fileContents, "This should be in the file.\n"); assert.include(fileContents, "This should be in the file." + EOL);
}, },
'log messages should be in the basic layout format': function(err, fileContents) { 'log messages should be in the basic layout format': function(err, fileContents) {
assert.match( assert.match(
@ -61,7 +62,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
fs.readFile(testFile, "utf8", that.callback); fs.readFile(testFile, "utf8", that.callback);
}, },
'log file should only contain the second message': function (err, fileContents) { 'log file should only contain the second message': function (err, fileContents) {
assert.include(fileContents, "This is the second log message.\n"); assert.include(fileContents, "This is the second log message." + EOL);
assert.equal(fileContents.indexOf("This is the first log message."), -1); assert.equal(fileContents.indexOf("This is the first log message."), -1);
}, },
'the number of files': { 'the number of files': {
@ -173,7 +174,7 @@ vows.describe('log4js fileSyncAppender').addBatch({
fs.readFile('tmp-sync-tests.log', 'utf8', this.callback); fs.readFile('tmp-sync-tests.log', 'utf8', this.callback);
}, },
'should load appender configuration from a json file': function(err, contents) { 'should load appender configuration from a json file': function(err, contents) {
assert.include(contents, 'this should be written to the file\n'); assert.include(contents, 'this should be written to the file' + EOL);
assert.equal(contents.indexOf('this should not be written to the file'), -1); assert.equal(contents.indexOf('this should not be written to the file'), -1);
} }
} }

View File

@ -1,6 +1,8 @@
"use strict"; "use strict";
var vows = require('vows') var vows = require('vows')
, assert = require('assert'); , assert = require('assert')
, os = require('os')
, EOL = os.EOL || '\n';
//used for patternLayout tests. //used for patternLayout tests.
function test(args, pattern, value) { function test(args, pattern, value) {
@ -195,7 +197,7 @@ vows.describe('log4js layouts').addBatch({
}, },
'should default to "time logLevel loggerName - message"': function(args) { 'should default to "time logLevel loggerName - message"': function(args) {
test(args, null, "14:18:30 DEBUG multiple.levels.of.tests - this is a test\n"); test(args, null, "14:18:30 DEBUG multiple.levels.of.tests - this is a test" + EOL);
}, },
'%r should output time only': function(args) { '%r should output time only': function(args) {
test(args, '%r', '14:18:30'); test(args, '%r', '14:18:30');
@ -210,10 +212,10 @@ vows.describe('log4js layouts').addBatch({
test(args, '%m', 'this is a test'); test(args, '%m', 'this is a test');
}, },
'%n should output a new line': function(args) { '%n should output a new line': function(args) {
test(args, '%n', '\n'); test(args, '%n', EOL);
}, },
'%h should output hostname' : function(args) { '%h should output hostname' : function(args) {
test(args, '%h', require('os').hostname().toString()); test(args, '%h', os.hostname().toString());
}, },
'%c should handle category names like java-style package names': function(args) { '%c should handle category names like java-style package names': function(args) {
test(args, '%c{1}', 'tests'); test(args, '%c{1}', 'tests');
@ -247,7 +249,7 @@ vows.describe('log4js layouts').addBatch({
'should handle complicated patterns': function(args) { 'should handle complicated patterns': function(args) {
test(args, test(args,
'%m%n %c{2} at %d{ABSOLUTE} cheese %p%n', '%m%n %c{2} at %d{ABSOLUTE} cheese %p%n',
'this is a test\n of.tests at 14:18:30.045 cheese DEBUG\n' 'this is a test'+ EOL +' of.tests at 14:18:30.045 cheese DEBUG' + EOL
); );
}, },
'should truncate fields if specified': function(args) { 'should truncate fields if specified': function(args) {

View File

@ -1,6 +1,7 @@
"use strict"; "use strict";
var vows = require('vows') var vows = require('vows')
, assert = require('assert') , assert = require('assert')
, path = require('path')
, sandbox = require('sandboxed-module'); , sandbox = require('sandboxed-module');
vows.describe('log4js-abspath').addBatch({ vows.describe('log4js-abspath').addBatch({
@ -69,7 +70,8 @@ vows.describe('log4js-abspath').addBatch({
return fileOpened; return fileOpened;
}, },
'should prepend options.cwd to config.filename': function(fileOpened) { 'should prepend options.cwd to config.filename': function(fileOpened) {
assert.equal(fileOpened, "/absolute/path/to/whatever.log"); var expected = path.sep + path.join("absolute", "path", "to", "whatever.log");
assert.equal(fileOpened, expected);
} }
}, },
}).export(module); }).export(module);

View File

@ -1,7 +1,9 @@
"use strict"; "use strict";
var vows = require('vows') var vows = require('vows')
, fs = require('fs') , fs = require('fs')
, assert = require('assert'); , assert = require('assert')
, os = require('os')
, EOL = require('os').EOL || '\n';
function remove(filename) { function remove(filename) {
try { try {
@ -61,7 +63,7 @@ vows.describe('log4js logLevelFilter').addBatch({
fs.readFile(__dirname + '/logLevelFilter.log', 'utf8', this.callback); fs.readFile(__dirname + '/logLevelFilter.log', 'utf8', this.callback);
}, },
'should contain all log messages': function (contents) { 'should contain all log messages': function (contents) {
var messages = contents.trim().split('\n'); var messages = contents.trim().split(EOL);
assert.deepEqual(messages, ['main','both','both','main']); assert.deepEqual(messages, ['main','both','both','main']);
} }
}, },
@ -70,7 +72,7 @@ vows.describe('log4js logLevelFilter').addBatch({
fs.readFile(__dirname + '/logLevelFilter-warnings.log','utf8',this.callback); fs.readFile(__dirname + '/logLevelFilter-warnings.log','utf8',this.callback);
}, },
'should contain only error and warning log messages': function(contents) { 'should contain only error and warning log messages': function(contents) {
var messages = contents.trim().split('\n'); var messages = contents.trim().split(EOL);
assert.deepEqual(messages, ['both','both']); assert.deepEqual(messages, ['both','both']);
} }
} }