changes for node 0.1.30, tests run but don't pass yet

This commit is contained in:
csausdev 2010-02-22 20:09:56 +11:00
parent 15e9a30d05
commit f130b95b08
3 changed files with 14 additions and 30 deletions

View File

@ -1,4 +1,4 @@
var posix = require('posix'), sys = require('sys'); var fs = require('fs'), sys = require('sys');
var DEFAULT_CATEGORY = '[default]'; var DEFAULT_CATEGORY = '[default]';
var ALL_CATEGORIES = '[all]'; var ALL_CATEGORIES = '[all]';
@ -146,13 +146,7 @@ var log4js = {
}, },
configure: function(configurationFile) { configure: function(configurationFile) {
var config; var config = JSON.parse(fs.readFileSync(configurationFile));
posix
.cat(configurationFile)
.addCallback(
function(contents) { config = JSON.parse(contents); }
).wait();
configureAppenders(config.appenders); configureAppenders(config.appenders);
configureLevels(config.levels); configureLevels(config.levels);
}, },
@ -382,16 +376,16 @@ consoleAppender = function (layout) {
fileAppender = function(file, layout) { fileAppender = function(file, layout) {
layout = layout || basicLayout; layout = layout || basicLayout;
file = file || "log4js.log"; file = file || "log4js.log";
//waits are generally bad, but we need //syncs are generally bad, but we need
//the file to be open before we start doing any writing. //the file to be open before we start doing any writing.
var logFile = posix.open(file, process.O_APPEND | process.O_WRONLY | process.O_CREAT, 0644).wait(); var logFile = fs.openSync(file, process.O_APPEND | process.O_WRONLY | process.O_CREAT, 0644);
//register ourselves as listeners for shutdown //register ourselves as listeners for shutdown
//so that we can close the file. //so that we can close the file.
//not entirely sure this is necessary, but still. //not entirely sure this is necessary, but still.
process.addListener("exit", function() { posix.close(logFile); }); process.addListener("exit", function() { fs.close(logFile); });
return function(loggingEvent) { return function(loggingEvent) {
posix.write(logFile, layout(loggingEvent)+'\n', null, "utf-8"); fs.write(logFile, layout(loggingEvent)+'\n', null, "utf-8");
}; };
}; };

View File

@ -1,12 +1,12 @@
posix = require('posix'); fs = require('fs'), events = require('events');
waitForWriteAndThenRead = function (filename) { waitForWriteAndThenRead = function (filename) {
//here's the tricky part - writes are asynchronous //here's the tricky part - writes are asynchronous
//so I'm going to make a promise, wait a bit and then //so I'm going to make a promise, wait a bit and then
//try to read the file. //try to read the file.
var content, promise = new process.Promise(); var content, promise = new events.Promise();
promise.addCallback(function() { promise.addCallback(function() {
content = posix.cat(filename).timeout(500).wait(); content = posix.readFileSync(filename);
}); });
setTimeout(function() { setTimeout(function() {
promise.emitSuccess(); promise.emitSuccess();
@ -185,12 +185,12 @@ describe 'log4js'
before_each before_each
log4js.clearAppenders(); log4js.clearAppenders();
try { try {
posix.unlink('./tmp-tests.log').wait(); posix.unlinkSync('./tmp-tests.log');
} catch(e) { } catch(e) {
print('Could not delete tmp-tests.log: '+e.message); print('Could not delete tmp-tests.log: '+e.message);
} }
try { try {
posix.unlink('./tmp-tests-warnings.log').wait(); posix.unlinkSync('./tmp-tests-warnings.log');
} catch (e) { } catch (e) {
print('Could not delete tmp-tests-warnings.log: '+e.message); print('Could not delete tmp-tests-warnings.log: '+e.message);
} }

View File

@ -3,7 +3,7 @@ require("jspec");
log4js = require("log4js-node"); log4js = require("log4js-node");
var sys = require("sys"), posix = require("posix"); var sys = require("sys"), fs = require("fs");
quit = process.exit quit = process.exit
print = sys.puts print = sys.puts
@ -11,11 +11,7 @@ print = sys.puts
readFile = function(path) { readFile = function(path) {
var result; var result;
try { try {
posix result = fs.readFileSync(path);
.cat(path)
.addCallback(
function(contents){ result = contents; }
).wait();
} catch (e) { } catch (e) {
throw e; throw e;
} }
@ -28,13 +24,7 @@ if (process.ARGV[2]) {
specsFound = true; specsFound = true;
JSpec.exec('spec/spec.' + process.ARGV[2] + '.js'); JSpec.exec('spec/spec.' + process.ARGV[2] + '.js');
} else { } else {
var files; var files = fs.readdirSync('spec/');
posix
.readdir('spec/')
.addCallback(
function(dirFiles) { files = dirFiles; }
).wait();
files.filter( files.filter(
function (file) { function (file) {
return file.indexOf('spec.') === 0; return file.indexOf('spec.') === 0;