42
44
var result = fs.realpathSync(entry);
43
45
assert.equal(result, expected,
44
'got '+inspect(result)+' expected '+inspect(expected));
46
'got '+common.inspect(result)+' expected '+common.inspect(expected));
45
47
asynctest(fs.realpath, [entry], callback, function(err, result){
46
48
assert.equal(result, expected,
47
'got '+inspect(result)+' expected '+inspect(expected));
49
'got '+common.inspect(result)+' expected '+common.inspect(expected));
51
53
function test_simple_absolute_symlink(callback) {
52
bashRealpath(fixturesDir, function(err, fixturesAbsDir) {
54
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
53
55
if (err) return callback(err);
54
56
var entry = fixturesAbsDir+'/cycles/symlink',
55
57
expected = fixturesAbsDir+'/nested-index/one/index.js';
63
65
var result = fs.realpathSync(entry);
64
66
assert.equal(result, expected,
65
'got '+inspect(result)+' expected '+inspect(expected));
67
'got '+common.inspect(result)+' expected '+common.inspect(expected));
66
68
asynctest(fs.realpath, [entry], callback, function(err, result){
67
69
assert.equal(result, expected,
68
'got '+inspect(result)+' expected '+inspect(expected));
70
'got '+common.inspect(result)+' expected '+common.inspect(expected));
73
75
function test_deep_relative_file_symlink(callback) {
74
var expected = path.join(fixturesDir, 'cycles', 'root.js');
76
var expected = path.join(common.fixturesDir, 'cycles', 'root.js');
75
77
var linkData1 = "../../cycles/root.js";
76
var linkPath1 = path.join(fixturesDir, "nested-index", 'one', 'symlink1.js');
78
var linkPath1 = path.join(common.fixturesDir, "nested-index", 'one', 'symlink1.js');
77
79
try {fs.unlinkSync(linkPath1);}catch(e){}
78
80
fs.symlinkSync(linkData1, linkPath1);
80
82
var linkData2 = "../one/symlink1.js";
81
var entry = path.join(fixturesDir, "nested-index", 'two', 'symlink1-b.js');
83
var entry = path.join(common.fixturesDir, "nested-index", 'two', 'symlink1-b.js');
82
84
try {fs.unlinkSync(entry);}catch(e){}
83
85
fs.symlinkSync(linkData2, entry);
84
86
unlink.push(linkPath1);
87
89
assert.equal(fs.realpathSync(entry), expected);
88
90
asynctest(fs.realpath, [entry], callback, function(err, result){
89
91
assert.equal(result, expected,
90
'got '+inspect(result)+' expected '+inspect(expected));
92
'got '+common.inspect(result)+' expected '+common.inspect(expected));
94
96
function test_deep_relative_dir_symlink(callback) {
95
var expected = path.join(fixturesDir, 'cycles', 'folder');
97
var expected = path.join(common.fixturesDir, 'cycles', 'folder');
96
98
var linkData1b = "../../cycles/folder";
97
var linkPath1b = path.join(fixturesDir, "nested-index", 'one', 'symlink1-dir');
99
var linkPath1b = path.join(common.fixturesDir, "nested-index", 'one', 'symlink1-dir');
98
100
try {fs.unlinkSync(linkPath1b);}catch(e){}
99
101
fs.symlinkSync(linkData1b, linkPath1b);
101
103
var linkData2b = "../one/symlink1-dir";
102
var entry = path.join(fixturesDir, "nested-index", 'two', 'symlink12-dir');
104
var entry = path.join(common.fixturesDir, "nested-index", 'two', 'symlink12-dir');
103
105
try {fs.unlinkSync(entry);}catch(e){}
104
106
fs.symlinkSync(linkData2b, entry);
105
107
unlink.push(linkPath1b);
106
108
unlink.push(entry);
108
110
assert.equal(fs.realpathSync(entry), expected);
110
112
asynctest(fs.realpath, [entry], callback, function(err, result){
111
113
assert.equal(result, expected,
112
'got '+inspect(result)+' expected '+inspect(expected));
114
'got '+common.inspect(result)+' expected '+common.inspect(expected));
116
118
function test_cyclic_link_protection(callback) {
117
var entry = fixturesDir+'/cycles/realpath-3a';
119
var entry = common.fixturesDir+'/cycles/realpath-3a';
119
121
[entry, '../cycles/realpath-3b'],
120
[fixturesDir+'/cycles/realpath-3b', '../cycles/realpath-3c'],
121
[fixturesDir+'/cycles/realpath-3c', '../cycles/realpath-3a'],
122
[common.fixturesDir+'/cycles/realpath-3b', '../cycles/realpath-3c'],
123
[common.fixturesDir+'/cycles/realpath-3c', '../cycles/realpath-3a'],
122
124
].forEach(function(t) {
123
125
try {fs.unlinkSync(t[0]);}catch(e){}
124
126
fs.symlinkSync(t[1], t[0]);
134
136
function test_relative_input_cwd(callback) {
135
var p = fixturesDir.lastIndexOf('/');
136
var entrydir = fixturesDir.substr(0, p);
137
var entry = fixturesDir.substr(p+1)+'/cycles/realpath-3a';
138
var expected = fixturesDir+'/cycles/root.js';
137
var p = common.fixturesDir.lastIndexOf('/');
138
var entrydir = common.fixturesDir.substr(0, p);
139
var entry = common.fixturesDir.substr(p+1)+'/cycles/realpath-3a';
140
var expected = common.fixturesDir+'/cycles/root.js';
140
142
[entry, '../cycles/realpath-3b'],
141
[fixturesDir+'/cycles/realpath-3b', '../cycles/realpath-3c'],
142
[fixturesDir+'/cycles/realpath-3c', 'root.js'],
143
[common.fixturesDir+'/cycles/realpath-3b', '../cycles/realpath-3c'],
144
[common.fixturesDir+'/cycles/realpath-3c', 'root.js'],
143
145
].forEach(function(t) {
145
147
if (fn.charAt(0) !== '/') fn = entrydir + '/' + fn;
153
155
asynctest(fs.realpath, [entry], callback, function(err, result){
154
156
process.chdir(origcwd);
155
157
assert.equal(result, expected,
156
'got '+inspect(result)+' expected '+inspect(expected));
158
'got '+common.inspect(result)+' expected '+common.inspect(expected));
161
163
function test_deep_symlink_mix(callback) {
162
// todo: check to see that fixturesDir is not rooted in the
164
// todo: check to see that common.fixturesDir is not rooted in the
163
165
// same directory as our test symlink.
164
166
// obtain our current realpath using bash (so we can test ourselves)
165
bashRealpath(fixturesDir, function(err, fixturesAbsDir) {
167
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
166
168
if (err) return callback(err);
168
170
/tmp/node-test-realpath-f1 -> ../tmp/node-test-realpath-d1/foo
169
171
/tmp/node-test-realpath-d1 -> ../node-test-realpath-d2
170
172
/tmp/node-test-realpath-d2/foo -> ../node-test-realpath-f2
171
/tmp/node-test-realpath-f2
173
/tmp/node-test-realpath-f2
172
174
-> /node/test/fixtures/nested-index/one/realpath-c
173
/node/test/fixtures/nested-index/one/realpath-c
175
/node/test/fixtures/nested-index/one/realpath-c
174
176
-> /node/test/fixtures/nested-index/two/realpath-c
175
177
/node/test/fixtures/nested-index/two/realpath-c -> ../../cycles/root.js
176
178
/node/test/fixtures/cycles/root.js (hard)
188
190
[fixturesAbsDir+'/nested-index/one/realpath-c', fixturesAbsDir+'/nested-index/two/realpath-c'],
189
191
[fixturesAbsDir+'/nested-index/two/realpath-c', '../../cycles/root.js'],
190
192
].forEach(function(t) {
191
//debug('setting up '+t[0]+' -> '+t[1]);
193
//common.debug('setting up '+t[0]+' -> '+t[1]);
192
194
try {fs.unlinkSync(t[0]);}catch(e){}
193
195
fs.symlinkSync(t[1], t[0]);
194
196
unlink.push(t[0]);
200
202
assert.equal(fs.realpathSync(entry), expected);
201
203
asynctest(fs.realpath, [entry], callback, function(err, result){
202
204
assert.equal(result, expected,
203
'got '+inspect(result)+' expected '+inspect(expected));
205
'got '+common.inspect(result)+' expected '+common.inspect(expected));
209
211
function test_non_symlinks(callback) {
210
bashRealpath(fixturesDir, function(err, fixturesAbsDir) {
212
bashRealpath(common.fixturesDir, function(err, fixturesAbsDir) {
211
213
if (err) return callback(err);
212
214
var p = fixturesAbsDir.lastIndexOf('/');
213
215
var entrydir = fixturesAbsDir.substr(0, p);