@ -10,9 +10,13 @@ var skipSymlinks = false;
common . refreshTmpDir ( ) ;
var root = '/' ;
var assertEqualPath = assert . equal ;
if ( common . isWindows ) {
// something like "C:\\"
root = process . cwd ( ) . substr ( 0 , 3 ) ;
assertEqualPath = function ( path_left , path_right , message ) {
assert . equal ( path_left . toLowerCase ( ) , path_right . toLowerCase ( ) , message ) ;
} ;
// On Windows, creating symlinks requires admin privileges.
// We'll only try to run symlink test if we have enough privileges.
@ -96,9 +100,9 @@ function test_simple_relative_symlink(callback) {
unlink . push ( t [ 0 ] ) ;
} ) ;
var result = fs . realpathSync ( entry ) ;
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
} ) ;
}
@ -122,9 +126,9 @@ function test_simple_absolute_symlink(callback) {
unlink . push ( t [ 0 ] ) ;
} ) ;
var result = fs . realpathSync ( entry ) ;
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
} ) ;
}
@ -151,9 +155,9 @@ function test_deep_relative_file_symlink(callback) {
unlink . push ( linkPath1 ) ;
unlink . push ( entry ) ;
assert . equal ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
} ) ;
}
@ -178,10 +182,10 @@ function test_deep_relative_dir_symlink(callback) {
unlink . push ( linkPath1b ) ;
unlink . push ( entry ) ;
assert . equal ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
} ) ;
}
@ -223,9 +227,9 @@ function test_cyclic_link_overprotection(callback) {
try { fs . unlinkSync ( link ) ; } catch ( ex ) { }
fs . symlinkSync ( cycles , link , 'dir' ) ;
unlink . push ( link ) ;
assert . equal ( fs . realpathSync ( testPath ) , path . resolve ( expected ) ) ;
assertEqualPath ( fs . realpathSync ( testPath ) , path . resolve ( expected ) ) ;
asynctest ( fs . realpath , [ testPath ] , callback , function ( er , res ) {
assert . equal ( res , path . resolve ( expected ) ) ;
assertEqualPath ( res , path . resolve ( expected ) ) ;
} ) ;
}
@ -258,10 +262,10 @@ function test_relative_input_cwd(callback) {
var origcwd = process . cwd ( ) ;
process . chdir ( entrydir ) ;
assert . equal ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
process . chdir ( origcwd ) ;
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
return true ;
} ) ;
}
@ -311,9 +315,9 @@ function test_deep_symlink_mix(callback) {
unlink . push ( tmp ( 'node-test-realpath-d2' ) ) ;
}
var expected = tmpAbsDir + '/cycles/root.js' ;
assert . equal ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
return true ;
} ) ;
}
@ -325,10 +329,10 @@ function test_non_symlinks(callback) {
var expected = tmpAbsDir + '/cycles/root.js' ;
var origcwd = process . cwd ( ) ;
process . chdir ( entrydir ) ;
assert . equal ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
process . chdir ( origcwd ) ;
assert . equal ( result , path . resolve ( expected ) ) ;
assertEqualPath ( result , path . resolve ( expected ) ) ;
return true ;
} ) ;
}
@ -337,13 +341,13 @@ var upone = path.join(process.cwd(), '..');
function test_escape_cwd ( cb ) {
console . log ( 'test_escape_cwd' ) ;
asynctest ( fs . realpath , [ '..' ] , cb , function ( er , uponeActual ) {
assert . equal ( upone , uponeActual ,
assertEqualPath ( upone , uponeActual ,
'realpath("..") expected: ' + path . resolve ( upone ) +
' actual:' + uponeActual ) ;
} ) ;
}
var uponeActual = fs . realpathSync ( '..' ) ;
assert . equal ( upone , uponeActual ,
assertEqualPath ( upone , uponeActual ,
'realpathSync("..") expected: ' + path . resolve ( upone ) +
' actual:' + uponeActual ) ;
@ -385,14 +389,14 @@ function test_up_multiple(cb) {
var abedabeda = tmp ( 'abedabeda' . split ( '' ) . join ( '/' ) ) ;
var abedabeda_real = tmp ( 'a' ) ;
assert . equal ( fs . realpathSync ( abedabeda ) , abedabeda_real ) ;
assert . equal ( fs . realpathSync ( abedabed ) , abedabed_real ) ;
assertEqualPath ( fs . realpathSync ( abedabeda ) , abedabeda_real ) ;
assertEqualPath ( fs . realpathSync ( abedabed ) , abedabed_real ) ;
fs . realpath ( abedabeda , function ( er , real ) {
if ( er ) throw er ;
assert . equal ( abedabeda_real , real ) ;
assertEqualPath ( abedabeda_real , real ) ;
fs . realpath ( abedabed , function ( er , real ) {
if ( er ) throw er ;
assert . equal ( abedabed_real , real ) ;
assertEqualPath ( abedabed_real , real ) ;
cb ( ) ;
cleanup ( ) ;
} ) ;
@ -450,56 +454,14 @@ function test_abs_with_kids(cb) {
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 , path . resolve ( expectPath ) ) ;
assertEqualPath ( actual , path . resolve ( expectPath ) ) ;
asynctest ( fs . realpath , [ linkPath ] , cb , function ( er , actual ) {
// console.log({link:linkPath,expect:expectPath,actual:actual},'async');
assert . equal ( actual , path . resolve ( expectPath ) ) ;
assertEqualPath ( actual , path . resolve ( expectPath ) ) ;
cleanup ( ) ;
} ) ;
}
function test_lying_cache_liar ( cb ) {
var n = 2 ;
// this should not require *any* stat calls, since everything
// checked by realpath will be found in the cache.
console . log ( 'test_lying_cache_liar' ) ;
var cache = { '/foo/bar/baz/bluff' : '/foo/bar/bluff' ,
'/1/2/3/4/5/6/7' : '/1' ,
'/a' : '/a' ,
'/a/b' : '/a/b' ,
'/a/b/c' : '/a/b' ,
'/a/b/d' : '/a/b/d' } ;
if ( common . isWindows ) {
var wc = { } ;
Object . keys ( cache ) . forEach ( function ( k ) {
wc [ path . resolve ( k ) ] = path . resolve ( cache [ k ] ) ;
} ) ;
cache = wc ;
}
var bluff = path . resolve ( '/foo/bar/baz/bluff' ) ;
var rps = fs . realpathSync ( bluff , cache ) ;
assert . equal ( cache [ bluff ] , rps ) ;
var nums = path . resolve ( '/1/2/3/4/5/6/7' ) ;
var called = false ; // no sync cb calling!
fs . realpath ( nums , cache , function ( er , rp ) {
called = true ;
assert . equal ( cache [ nums ] , rp ) ;
if ( -- n === 0 ) cb ( ) ;
} ) ;
assert ( called === false ) ;
const test = path . resolve ( '/a/b/c/d' ) ;
const expect = path . resolve ( '/a/b/d' ) ;
var actual = fs . realpathSync ( test , cache ) ;
assert . equal ( expect , actual ) ;
fs . realpath ( test , cache , function ( er , actual ) {
assert . equal ( expect , actual ) ;
if ( -- n === 0 ) cb ( ) ;
} ) ;
}
// ----------------------------------------------------------------------------
var tests = [
@ -515,7 +477,6 @@ var tests = [
test_non_symlinks ,
test_escape_cwd ,
test_abs_with_kids ,
test_lying_cache_liar ,
test_up_multiple
] ;
var numtests = tests . length ;
@ -532,10 +493,10 @@ function runNextTest(err) {
}
assert . equal ( root , fs . realpathSync ( '/' ) ) ;
assertEqualPath ( root , fs . realpathSync ( '/' ) ) ;
fs . realpath ( '/' , function ( err , result ) {
assert . equal ( null , err ) ;
assert . equal ( root , result ) ;
assertEqualPath ( root , result ) ;
} ) ;