|
@ -9,6 +9,28 @@ function tmp(p) { |
|
|
return path.join(common.tmpDir, 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) { |
|
|
function asynctest(testBlock, args, callback, assertBlock) { |
|
|
async_expected++; |
|
|
async_expected++; |
|
|
testBlock.apply(testBlock, args.concat(function(err) { |
|
|
testBlock.apply(testBlock, args.concat(function(err) { |
|
@ -36,10 +58,10 @@ function bashRealpath(path, callback) { |
|
|
|
|
|
|
|
|
function test_simple_relative_symlink(callback) { |
|
|
function test_simple_relative_symlink(callback) { |
|
|
console.log('test_simple_relative_symlink'); |
|
|
console.log('test_simple_relative_symlink'); |
|
|
var entry = common.fixturesDir + '/cycles/symlink', |
|
|
var entry = common.tmpDir + '/symlink', |
|
|
expected = common.fixturesDir + '/cycles/root.js'; |
|
|
expected = common.fixturesDir + '/cycles/root.js'; |
|
|
[ |
|
|
[ |
|
|
[entry, 'root.js'] |
|
|
[entry, '../fixtures/cycles/root.js'] |
|
|
].forEach(function(t) { |
|
|
].forEach(function(t) { |
|
|
try {fs.unlinkSync(t[0]);}catch (e) {} |
|
|
try {fs.unlinkSync(t[0]);}catch (e) {} |
|
|
fs.symlinkSync(t[1], t[0]); |
|
|
fs.symlinkSync(t[1], t[0]); |
|
@ -48,7 +70,7 @@ function test_simple_relative_symlink(callback) { |
|
|
var result = fs.realpathSync(entry); |
|
|
var result = fs.realpathSync(entry); |
|
|
assert.equal(result, expected, |
|
|
assert.equal(result, expected, |
|
|
'got ' + common.inspect(result) + ' expected ' + |
|
|
'got ' + common.inspect(result) + ' expected ' + |
|
|
common.inspect(expected)); |
|
|
common.inspect(expected)); |
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
assert.equal(result, expected, |
|
|
assert.equal(result, expected, |
|
|
'got ' + |
|
|
'got ' + |
|
@ -60,30 +82,27 @@ function test_simple_relative_symlink(callback) { |
|
|
|
|
|
|
|
|
function test_simple_absolute_symlink(callback) { |
|
|
function test_simple_absolute_symlink(callback) { |
|
|
console.log('test_simple_absolute_symlink'); |
|
|
console.log('test_simple_absolute_symlink'); |
|
|
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) { |
|
|
var entry = fixturesAbsDir + '/cycles/symlink', |
|
|
if (err) return callback(err); |
|
|
expected = fixturesAbsDir + '/nested-index/one/index.js'; |
|
|
var entry = fixturesAbsDir + '/cycles/symlink', |
|
|
[ |
|
|
expected = fixturesAbsDir + '/nested-index/one/index.js'; |
|
|
[entry, expected] |
|
|
[ |
|
|
].forEach(function(t) { |
|
|
[entry, expected] |
|
|
try {fs.unlinkSync(t[0]);} catch (e) {} |
|
|
].forEach(function(t) { |
|
|
fs.symlinkSync(t[1], t[0]); |
|
|
try {fs.unlinkSync(t[0]);} catch (e) {} |
|
|
unlink.push(t[0]); |
|
|
fs.symlinkSync(t[1], t[0]); |
|
|
}); |
|
|
unlink.push(t[0]); |
|
|
var result = fs.realpathSync(entry); |
|
|
}); |
|
|
assert.equal(result, expected, |
|
|
var result = fs.realpathSync(entry); |
|
|
'got ' + |
|
|
|
|
|
common.inspect(result) + |
|
|
|
|
|
' expected ' + |
|
|
|
|
|
common.inspect(expected)); |
|
|
|
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
assert.equal(result, expected, |
|
|
assert.equal(result, expected, |
|
|
'got ' + |
|
|
'got ' + |
|
|
common.inspect(result) + |
|
|
common.inspect(result) + |
|
|
' expected ' + |
|
|
' expected ' + |
|
|
common.inspect(expected)); |
|
|
common.inspect(expected)); |
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
|
|
|
assert.equal(result, expected, |
|
|
|
|
|
'got ' + |
|
|
|
|
|
common.inspect(result) + |
|
|
|
|
|
' expected ' + |
|
|
|
|
|
common.inspect(expected)); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -213,76 +232,70 @@ function test_deep_symlink_mix(callback) { |
|
|
// todo: check to see that common.fixturesDir is not rooted in the
|
|
|
// todo: check to see that common.fixturesDir is not rooted in the
|
|
|
// same directory as our test symlink.
|
|
|
// same directory as our test symlink.
|
|
|
// obtain our current realpath using bash (so we can test ourselves)
|
|
|
// 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 |
|
|
/tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo |
|
|
/tmp/node-test-realpath-d2/foo -> ../node-test-realpath-f2 |
|
|
/tmp/node-test-realpath-d1 -> ../node-test-realpath-d2 |
|
|
/tmp/node-test-realpath-f2 |
|
|
/tmp/node-test-realpath-d2/foo -> ../node-test-realpath-f2 |
|
|
-> /node/test/fixtures/nested-index/one/realpath-c |
|
|
/tmp/node-test-realpath-f2 |
|
|
/node/test/fixtures/nested-index/one/realpath-c |
|
|
-> /node/test/fixtures/nested-index/one/realpath-c |
|
|
-> /node/test/fixtures/nested-index/two/realpath-c |
|
|
/node/test/fixtures/nested-index/one/realpath-c |
|
|
/node/test/fixtures/nested-index/two/realpath-c -> ../../cycles/root.js |
|
|
-> /node/test/fixtures/nested-index/two/realpath-c |
|
|
/node/test/fixtures/cycles/root.js (hard) |
|
|
/node/test/fixtures/nested-index/two/realpath-c -> ../../cycles/root.js |
|
|
*/ |
|
|
/node/test/fixtures/cycles/root.js (hard) |
|
|
var entry = tmp('node-test-realpath-f1'); |
|
|
*/ |
|
|
try { fs.unlinkSync(tmp('node-test-realpath-d2/foo')); } catch (e) {} |
|
|
var entry = tmp('node-test-realpath-f1'); |
|
|
try { fs.rmdirSync(tmp('node-test-realpath-d2')); } catch (e) {} |
|
|
try { fs.unlinkSync(tmp('node-test-realpath-d2/foo')); } catch (e) {} |
|
|
fs.mkdirSync(tmp('node-test-realpath-d2'), 0700); |
|
|
try { fs.rmdirSync(tmp('node-test-realpath-d2')); } catch (e) {} |
|
|
try { |
|
|
fs.mkdirSync(tmp('node-test-realpath-d2'), 0700); |
|
|
[ |
|
|
try { |
|
|
[entry, '../tmp/node-test-realpath-d1/foo'], |
|
|
[ |
|
|
[tmp('node-test-realpath-d1'), '../tmp/node-test-realpath-d2'], |
|
|
[entry, '../tmp/node-test-realpath-d1/foo'], |
|
|
[tmp('node-test-realpath-d2/foo'), '../node-test-realpath-f2'], |
|
|
[tmp('node-test-realpath-d1'), '../tmp/node-test-realpath-d2'], |
|
|
[tmp('node-test-realpath-f2'), fixturesAbsDir + |
|
|
[tmp('node-test-realpath-d2/foo'), '../node-test-realpath-f2'], |
|
|
'/nested-index/one/realpath-c'], |
|
|
[tmp('node-test-realpath-f2'), fixturesAbsDir + |
|
|
[fixturesAbsDir + '/nested-index/one/realpath-c', fixturesAbsDir + |
|
|
'/nested-index/one/realpath-c'], |
|
|
'/nested-index/two/realpath-c'], |
|
|
[fixturesAbsDir + '/nested-index/one/realpath-c', fixturesAbsDir + |
|
|
[fixturesAbsDir + '/nested-index/two/realpath-c', |
|
|
'/nested-index/two/realpath-c'], |
|
|
'../../cycles/root.js'] |
|
|
[fixturesAbsDir + '/nested-index/two/realpath-c', |
|
|
].forEach(function(t) { |
|
|
'../../cycles/root.js'] |
|
|
//common.debug('setting up '+t[0]+' -> '+t[1]);
|
|
|
].forEach(function(t) { |
|
|
try { fs.unlinkSync(t[0]); } catch (e) {} |
|
|
//common.debug('setting up '+t[0]+' -> '+t[1]);
|
|
|
fs.symlinkSync(t[1], t[0]); |
|
|
try { fs.unlinkSync(t[0]); } catch (e) {} |
|
|
unlink.push(t[0]); |
|
|
fs.symlinkSync(t[1], t[0]); |
|
|
|
|
|
unlink.push(t[0]); |
|
|
|
|
|
}); |
|
|
|
|
|
} finally { |
|
|
|
|
|
unlink.push(tmp('node-test-realpath-d2')); |
|
|
|
|
|
} |
|
|
|
|
|
var expected = fixturesAbsDir + '/cycles/root.js'; |
|
|
|
|
|
assert.equal(fs.realpathSync(entry), expected); |
|
|
|
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
|
|
|
assert.equal(result, expected, |
|
|
|
|
|
'got ' + |
|
|
|
|
|
common.inspect(result) + |
|
|
|
|
|
' expected ' + |
|
|
|
|
|
common.inspect(expected)); |
|
|
|
|
|
return true; |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
} finally { |
|
|
|
|
|
unlink.push(tmp('node-test-realpath-d2')); |
|
|
|
|
|
} |
|
|
|
|
|
var expected = fixturesAbsDir + '/cycles/root.js'; |
|
|
|
|
|
assert.equal(fs.realpathSync(entry), expected); |
|
|
|
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
|
|
|
assert.equal(result, expected, |
|
|
|
|
|
'got ' + |
|
|
|
|
|
common.inspect(result) + |
|
|
|
|
|
' expected ' + |
|
|
|
|
|
common.inspect(expected)); |
|
|
|
|
|
return true; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function test_non_symlinks(callback) { |
|
|
function test_non_symlinks(callback) { |
|
|
console.log('test_non_symlinks'); |
|
|
console.log('test_non_symlinks'); |
|
|
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) { |
|
|
var p = fixturesAbsDir.lastIndexOf('/'); |
|
|
if (err) return callback(err); |
|
|
var entrydir = fixturesAbsDir.substr(0, p); |
|
|
var p = fixturesAbsDir.lastIndexOf('/'); |
|
|
var entry = fixturesAbsDir.substr(p + 1) + '/cycles/root.js'; |
|
|
var entrydir = fixturesAbsDir.substr(0, p); |
|
|
var expected = fixturesAbsDir + '/cycles/root.js'; |
|
|
var entry = fixturesAbsDir.substr(p + 1) + '/cycles/root.js'; |
|
|
var origcwd = process.cwd(); |
|
|
var expected = fixturesAbsDir + '/cycles/root.js'; |
|
|
process.chdir(entrydir); |
|
|
var origcwd = process.cwd(); |
|
|
assert.equal(fs.realpathSync(entry), expected); |
|
|
process.chdir(entrydir); |
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
assert.equal(fs.realpathSync(entry), expected); |
|
|
process.chdir(origcwd); |
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
assert.equal(result, expected, |
|
|
process.chdir(origcwd); |
|
|
'got ' + |
|
|
assert.equal(result, expected, |
|
|
common.inspect(result) + |
|
|
'got ' + |
|
|
' expected ' + |
|
|
common.inspect(result) + |
|
|
common.inspect(expected)); |
|
|
' expected ' + |
|
|
return true; |
|
|
common.inspect(expected)); |
|
|
|
|
|
return true; |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -308,46 +321,44 @@ assert.equal(upone, uponeActual, |
|
|
// realpath(root+'/a/link/c/x.txt') ==> root+'/a/b/c/x.txt'
|
|
|
// realpath(root+'/a/link/c/x.txt') ==> root+'/a/b/c/x.txt'
|
|
|
function test_abs_with_kids(cb) { |
|
|
function test_abs_with_kids(cb) { |
|
|
console.log('test_abs_with_kids'); |
|
|
console.log('test_abs_with_kids'); |
|
|
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) { |
|
|
var root = fixturesAbsDir + '/node-test-realpath-abs-kids'; |
|
|
var root = fixturesAbsDir + '/node-test-realpath-abs-kids'; |
|
|
function cleanup() { |
|
|
function cleanup() { |
|
|
['/a/b/c/x.txt', |
|
|
['/a/b/c/x.txt', |
|
|
'/a/link' |
|
|
'/a/link' |
|
|
].forEach(function(file) { |
|
|
].forEach(function(file) { |
|
|
try {fs.unlinkSync(root + file)} catch (ex) {} |
|
|
try {fs.unlinkSync(root + file)} catch (ex) {} |
|
|
}); |
|
|
}); |
|
|
['/a/b/c', |
|
|
['/a/b/c', |
|
|
'/a/b', |
|
|
'/a/b', |
|
|
'/a', |
|
|
'/a', |
|
|
'' |
|
|
'' |
|
|
].forEach(function(folder) { |
|
|
].forEach(function(folder) { |
|
|
try {fs.rmdirSync(root + folder)} catch (ex) {} |
|
|
try {fs.rmdirSync(root + folder)} catch (ex) {} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
function setup() { |
|
|
|
|
|
cleanup(); |
|
|
|
|
|
['', |
|
|
|
|
|
'/a', |
|
|
|
|
|
'/a/b', |
|
|
|
|
|
'/a/b/c' |
|
|
|
|
|
].forEach(function(folder) { |
|
|
|
|
|
console.log('mkdir ' + root + folder); |
|
|
|
|
|
fs.mkdirSync(root + folder, 0700); |
|
|
|
|
|
}); |
|
|
|
|
|
fs.writeFileSync(root + '/a/b/c/x.txt', 'foo'); |
|
|
|
|
|
fs.symlinkSync(root + '/a/b', root + '/a/link'); |
|
|
|
|
|
} |
|
|
|
|
|
setup(); |
|
|
|
|
|
var linkPath = root + '/a/link/c/x.txt'; |
|
|
|
|
|
var expectPath = root + '/a/b/c/x.txt'; |
|
|
|
|
|
var actual = fs.realpathSync(linkPath); |
|
|
|
|
|
// console.log({link:linkPath,expect:expectPath,actual:actual},'sync');
|
|
|
|
|
|
assert.equal(actual, expectPath); |
|
|
|
|
|
asynctest(fs.realpath, [linkPath], cb, function(er, actual) { |
|
|
|
|
|
// console.log({link:linkPath,expect:expectPath,actual:actual},'async');
|
|
|
|
|
|
assert.equal(actual, expectPath); |
|
|
|
|
|
cleanup(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
function setup() { |
|
|
|
|
|
cleanup(); |
|
|
|
|
|
['', |
|
|
|
|
|
'/a', |
|
|
|
|
|
'/a/b', |
|
|
|
|
|
'/a/b/c' |
|
|
|
|
|
].forEach(function(folder) { |
|
|
|
|
|
console.log('mkdir ' + root + folder); |
|
|
|
|
|
fs.mkdirSync(root + folder, 0700); |
|
|
|
|
|
}); |
|
|
|
|
|
fs.writeFileSync(root + '/a/b/c/x.txt', 'foo'); |
|
|
|
|
|
fs.symlinkSync(root + '/a/b', root + '/a/link'); |
|
|
|
|
|
} |
|
|
|
|
|
setup(); |
|
|
|
|
|
var linkPath = root + '/a/link/c/x.txt'; |
|
|
|
|
|
var expectPath = root + '/a/b/c/x.txt'; |
|
|
|
|
|
var actual = fs.realpathSync(linkPath); |
|
|
|
|
|
// console.log({link:linkPath,expect:expectPath,actual:actual},'sync');
|
|
|
|
|
|
assert.equal(actual, expectPath); |
|
|
|
|
|
asynctest(fs.realpath, [linkPath], cb, function(er, actual) { |
|
|
|
|
|
// console.log({link:linkPath,expect:expectPath,actual:actual},'async');
|
|
|
|
|
|
assert.equal(actual, expectPath); |
|
|
|
|
|
cleanup(); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -374,7 +385,10 @@ function runNextTest(err) { |
|
|
' subtests completed OK for fs.realpath'); |
|
|
' subtests completed OK for fs.realpath'); |
|
|
else test(runNextTest); |
|
|
else test(runNextTest); |
|
|
} |
|
|
} |
|
|
runNextTest(); |
|
|
getAbsPaths(function(er) { |
|
|
|
|
|
if (er) throw er; |
|
|
|
|
|
runNextTest(); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert.equal('/', fs.realpathSync('/')); |
|
|
assert.equal('/', fs.realpathSync('/')); |
|
|