Browse Source

test-fs-realpath: move absDir fetching to separate function

v0.7.4-release
isaacs 14 years ago
committed by Ryan Dahl
parent
commit
dc2b4b2a81
  1. 40
      test/simple/test-fs-realpath.js

40
test/simple/test-fs-realpath.js

@ -9,6 +9,28 @@ function tmp(p) {
return path.join(common.tmpDir, p);
}
var fixturesAbsDir;
var tmpAbsDir;
function getAbsPaths(cb) {
var failed = false;
var did = 0;
var expect = 2;
bashRealpath(common.fixturesDir, function(er, path) {
if (failed) return;
if (er) return cb(failed = er);
fixturesAbsDir = path;
did++;
if (did === expect) cb();
});
bashRealpath(common.tmpDir, function(er, path) {
if (failed) return;
if (er) return cb(failed = er);
tmpAbsDir = path;
did++;
if (did === expect) cb();
});
}
function asynctest(testBlock, args, callback, assertBlock) {
async_expected++;
testBlock.apply(testBlock, args.concat(function(err) {
@ -36,10 +58,10 @@ function bashRealpath(path, callback) {
function test_simple_relative_symlink(callback) {
console.log('test_simple_relative_symlink');
var entry = common.fixturesDir + '/cycles/symlink',
var entry = common.tmpDir + '/symlink',
expected = common.fixturesDir + '/cycles/root.js';
[
[entry, 'root.js']
[entry, '../fixtures/cycles/root.js']
].forEach(function(t) {
try {fs.unlinkSync(t[0]);}catch (e) {}
fs.symlinkSync(t[1], t[0]);
@ -60,8 +82,6 @@ function test_simple_relative_symlink(callback) {
function test_simple_absolute_symlink(callback) {
console.log('test_simple_absolute_symlink');
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
if (err) return callback(err);
var entry = fixturesAbsDir + '/cycles/symlink',
expected = fixturesAbsDir + '/nested-index/one/index.js';
[
@ -84,7 +104,6 @@ function test_simple_absolute_symlink(callback) {
' expected ' +
common.inspect(expected));
});
});
}
function test_deep_relative_file_symlink(callback) {
@ -213,8 +232,6 @@ function test_deep_symlink_mix(callback) {
// todo: check to see that common.fixturesDir is not rooted in the
// same directory as our test symlink.
// obtain our current realpath using bash (so we can test ourselves)
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
if (err) return callback(err);
/*
/tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo
/tmp/node-test-realpath-d1 -> ../node-test-realpath-d2
@ -260,13 +277,10 @@ function test_deep_symlink_mix(callback) {
common.inspect(expected));
return true;
});
});
}
function test_non_symlinks(callback) {
console.log('test_non_symlinks');
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
if (err) return callback(err);
var p = fixturesAbsDir.lastIndexOf('/');
var entrydir = fixturesAbsDir.substr(0, p);
var entry = fixturesAbsDir.substr(p + 1) + '/cycles/root.js';
@ -283,7 +297,6 @@ function test_non_symlinks(callback) {
common.inspect(expected));
return true;
});
});
}
var upone = path.join(process.cwd(), '..');
@ -308,7 +321,6 @@ assert.equal(upone, uponeActual,
// realpath(root+'/a/link/c/x.txt') ==> root+'/a/b/c/x.txt'
function test_abs_with_kids(cb) {
console.log('test_abs_with_kids');
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
var root = fixturesAbsDir + '/node-test-realpath-abs-kids';
function cleanup() {
['/a/b/c/x.txt',
@ -348,7 +360,6 @@ function test_abs_with_kids(cb) {
assert.equal(actual, expectPath);
cleanup();
});
});
}
// ----------------------------------------------------------------------------
@ -374,7 +385,10 @@ function runNextTest(err) {
' subtests completed OK for fs.realpath');
else test(runNextTest);
}
getAbsPaths(function(er) {
if (er) throw er;
runNextTest();
});
assert.equal('/', fs.realpathSync('/'));

Loading…
Cancel
Save