diff --git a/test/categoryFilter-test.js b/test/categoryFilter-test.js index 1ad10a0..bd40198 100644 --- a/test/categoryFilter-test.js +++ b/test/categoryFilter-test.js @@ -2,7 +2,8 @@ var vows = require('vows') , fs = require('fs') -, assert = require('assert'); +, assert = require('assert') +, EOL = require('os').EOL || '\n'; function remove(filename) { try { @@ -66,7 +67,7 @@ vows.describe('log4js categoryFilter').addBatch({ fs.readFile(__dirname + '/categoryFilter-noweb.log', 'utf8', this.callback); }, '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']); } }, @@ -75,7 +76,7 @@ vows.describe('log4js categoryFilter').addBatch({ fs.readFile(__dirname + '/categoryFilter-web.log','utf8',this.callback); }, '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']); } } diff --git a/test/dateFileAppender-test.js b/test/dateFileAppender-test.js index e64619d..8fa115f 100644 --- a/test/dateFileAppender-test.js +++ b/test/dateFileAppender-test.js @@ -186,7 +186,7 @@ vows.describe('../lib/appenders/dateFile').addBatch({ } }, 'with cwd option': { - topic: function() { + topic: function () { var fileOpened, appender = sandbox.require( '../lib/appenders/dateFile', @@ -213,8 +213,9 @@ vows.describe('../lib/appenders/dateFile').addBatch({ ); return fileOpened; }, - 'should prepend options.cwd to config.filename': function(fileOpened) { - assert.equal(fileOpened, "/absolute/path/to/whatever.log"); + 'should prepend options.cwd to config.filename': function (fileOpened) { + var expected = path.sep + path.join("absolute", "path", "to", "whatever.log"); + assert.equal(fileOpened, expected); } } diff --git a/test/fileAppender-test.js b/test/fileAppender-test.js index 9476ad6..9b4bd0f 100644 --- a/test/fileAppender-test.js +++ b/test/fileAppender-test.js @@ -4,7 +4,8 @@ var vows = require('vows') , path = require('path') , sandbox = require('sandboxed-module') , log4js = require('../lib/log4js') -, assert = require('assert'); +, assert = require('assert') +, EOL = require('os').EOL || '\n'; log4js.clearAppenders(); @@ -93,8 +94,8 @@ vows.describe('log4js fileAppender').addBatch({ fs.readFile(testFile, "utf8", that.callback); }, 100); }, - 'should write log messages to the file': function(err, fileContents) { - assert.include(fileContents, "This should be in the file.\n"); + 'should write log messages to the file': function (err, fileContents) { + assert.include(fileContents, "This should be in the file." + EOL); }, 'log messages should be in the basic layout format': function(err, fileContents) { assert.match( @@ -125,7 +126,7 @@ vows.describe('log4js fileAppender').addBatch({ }, 100); }, '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); }, 'the number of files': { @@ -229,8 +230,8 @@ vows.describe('log4js fileAppender').addBatch({ fs.readFile('tmp-tests.log', 'utf8', this.callback); }, - 'should load appender configuration from a json file': function(err, contents) { - assert.include(contents, 'this should be written to the file\n'); + 'should load appender configuration from a json file': function (err, contents) { + assert.include(contents, 'this should be written to the file' + EOL); assert.equal(contents.indexOf('this should not be written to the file'), -1); } } diff --git a/test/fileSyncAppender-test.js b/test/fileSyncAppender-test.js index 057ab2f..fde2985 100755 --- a/test/fileSyncAppender-test.js +++ b/test/fileSyncAppender-test.js @@ -4,7 +4,8 @@ var vows = require('vows') , path = require('path') , sandbox = require('sandboxed-module') , log4js = require('../lib/log4js') -, assert = require('assert'); +, assert = require('assert') +, EOL = require('os').EOL || '\n'; log4js.clearAppenders(); @@ -31,8 +32,8 @@ vows.describe('log4js fileSyncAppender').addBatch({ fs.readFile(testFile, "utf8", that.callback); }, - 'should write log messages to the file': function(err, fileContents) { - assert.include(fileContents, "This should be in the file.\n"); + 'should write log messages to the file': function (err, fileContents) { + assert.include(fileContents, "This should be in the file." + EOL); }, 'log messages should be in the basic layout format': function(err, fileContents) { assert.match( @@ -60,8 +61,8 @@ vows.describe('log4js fileSyncAppender').addBatch({ fs.readFile(testFile, "utf8", that.callback); }, - 'log file should only contain the second message': function(err, fileContents) { - assert.include(fileContents, "This is the second log message.\n"); + 'log file should only contain the second message': function (err, fileContents) { + assert.include(fileContents, "This is the second log message." + EOL); assert.equal(fileContents.indexOf("This is the first log message."), -1); }, 'the number of files': { @@ -173,7 +174,7 @@ vows.describe('log4js fileSyncAppender').addBatch({ fs.readFile('tmp-sync-tests.log', 'utf8', this.callback); }, '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); } } diff --git a/test/layouts-test.js b/test/layouts-test.js index 6fc17c0..00a3d6c 100644 --- a/test/layouts-test.js +++ b/test/layouts-test.js @@ -1,6 +1,8 @@ "use strict"; var vows = require('vows') -, assert = require('assert'); +, assert = require('assert') +, os = require('os') +, EOL = os.EOL || '\n'; //used for patternLayout tests. function test(args, pattern, value) { @@ -195,7 +197,7 @@ vows.describe('log4js layouts').addBatch({ }, '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) { test(args, '%r', '14:18:30'); @@ -210,10 +212,10 @@ vows.describe('log4js layouts').addBatch({ test(args, '%m', 'this is a test'); }, '%n should output a new line': function(args) { - test(args, '%n', '\n'); + test(args, '%n', EOL); }, '%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) { test(args, '%c{1}', 'tests'); @@ -247,7 +249,7 @@ vows.describe('log4js layouts').addBatch({ 'should handle complicated patterns': function(args) { test(args, '%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) { diff --git a/test/log-abspath-test.js b/test/log-abspath-test.js index 20aa9de..5bb64d3 100644 --- a/test/log-abspath-test.js +++ b/test/log-abspath-test.js @@ -1,6 +1,7 @@ "use strict"; var vows = require('vows') , assert = require('assert') +, path = require('path') , sandbox = require('sandboxed-module'); vows.describe('log4js-abspath').addBatch({ @@ -69,7 +70,8 @@ vows.describe('log4js-abspath').addBatch({ return 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); diff --git a/test/logLevelFilter-test.js b/test/logLevelFilter-test.js index c976689..c74e488 100644 --- a/test/logLevelFilter-test.js +++ b/test/logLevelFilter-test.js @@ -1,7 +1,9 @@ "use strict"; var vows = require('vows') , fs = require('fs') -, assert = require('assert'); +, assert = require('assert') +, os = require('os') +, EOL = require('os').EOL || '\n'; function remove(filename) { try { @@ -60,8 +62,8 @@ vows.describe('log4js logLevelFilter').addBatch({ topic: function() { fs.readFile(__dirname + '/logLevelFilter.log', 'utf8', this.callback); }, - 'should contain all log messages': function(contents) { - var messages = contents.trim().split('\n'); + 'should contain all log messages': function (contents) { + var messages = contents.trim().split(EOL); 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); }, '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']); } }