Skip to content

Commit 15de721

Browse files
committed
test: make realpath tests case-insensitive on win
process.cwd(), which is used in lots of the tests, may return a different value than what realpath will return even though they are the same path when compared case-insensitive.
1 parent d77f490 commit 15de721

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

test/simple/test-fs-realpath.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@ var exec = require('child_process').exec;
2727
var async_completed = 0, async_expected = 0, unlink = [];
2828
var isWindows = process.platform === 'win32';
2929
var skipSymlinks = false;
30+
var assertPathEqual = assert.equal; // non-win32
3031

3132
var root = '/';
3233
if (isWindows) {
34+
assertPathEqual = function (actual, expected, msg) {
35+
assert.equal(actual.toLowerCase(), expected.toLowerCase(), msg);
36+
};
37+
3338
// something like "C:\\"
3439
root = process.cwd().substr(0, 3);
3540

@@ -111,11 +116,11 @@ function test_simple_relative_symlink(callback) {
111116
unlink.push(t[0]);
112117
});
113118
var result = fs.realpathSync(entry);
114-
assert.equal(result, path.resolve(expected),
119+
assertPathEqual(result, path.resolve(expected),
115120
'got ' + common.inspect(result) + ' expected ' +
116121
common.inspect(expected));
117122
asynctest(fs.realpath, [entry], callback, function(err, result) {
118-
assert.equal(result, path.resolve(expected),
123+
assertPathEqual(result, path.resolve(expected),
119124
'got ' +
120125
common.inspect(result) +
121126
' expected ' +
@@ -143,13 +148,13 @@ function test_simple_absolute_symlink(callback) {
143148
unlink.push(t[0]);
144149
});
145150
var result = fs.realpathSync(entry);
146-
assert.equal(result, path.resolve(expected),
151+
assertPathEqual(result, path.resolve(expected),
147152
'got ' +
148153
common.inspect(result) +
149154
' expected ' +
150155
common.inspect(expected));
151156
asynctest(fs.realpath, [entry], callback, function(err, result) {
152-
assert.equal(result, path.resolve(expected),
157+
assertPathEqual(result, path.resolve(expected),
153158
'got ' +
154159
common.inspect(result) +
155160
' expected ' +
@@ -179,9 +184,9 @@ function test_deep_relative_file_symlink(callback) {
179184
unlink.push(linkPath1);
180185
unlink.push(entry);
181186

182-
assert.equal(fs.realpathSync(entry), path.resolve(expected));
187+
assertPathEqual(fs.realpathSync(entry), path.resolve(expected));
183188
asynctest(fs.realpath, [entry], callback, function(err, result) {
184-
assert.equal(result, path.resolve(expected),
189+
assertPathEqual(result, path.resolve(expected),
185190
'got ' +
186191
common.inspect(result) +
187192
' expected ' +
@@ -210,10 +215,10 @@ function test_deep_relative_dir_symlink(callback) {
210215
unlink.push(linkPath1b);
211216
unlink.push(entry);
212217

213-
assert.equal(fs.realpathSync(entry), path.resolve(expected));
218+
assertPathEqual(fs.realpathSync(entry), path.resolve(expected));
214219

215220
asynctest(fs.realpath, [entry], callback, function(err, result) {
216-
assert.equal(result, path.resolve(expected),
221+
assertPathEqual(result, path.resolve(expected),
217222
'got ' +
218223
common.inspect(result) +
219224
' expected ' +
@@ -259,9 +264,9 @@ function test_cyclic_link_overprotection(callback) {
259264
try {fs.unlinkSync(link)} catch (ex) {}
260265
fs.symlinkSync(cycles, link, 'dir');
261266
unlink.push(link);
262-
assert.equal(fs.realpathSync(testPath), path.resolve(expected));
267+
assertPathEqual(fs.realpathSync(testPath), path.resolve(expected));
263268
asynctest(fs.realpath, [testPath], callback, function(er, res) {
264-
assert.equal(res, path.resolve(expected));
269+
assertPathEqual(res, path.resolve(expected));
265270
});
266271
}
267272

@@ -295,10 +300,10 @@ function test_relative_input_cwd(callback) {
295300

296301
var origcwd = process.cwd();
297302
process.chdir(entrydir);
298-
assert.equal(fs.realpathSync(entry), path.resolve(expected));
303+
assertPathEqual(fs.realpathSync(entry), path.resolve(expected));
299304
asynctest(fs.realpath, [entry], callback, function(err, result) {
300305
process.chdir(origcwd);
301-
assert.equal(result, path.resolve(expected),
306+
assertPathEqual(result, path.resolve(expected),
302307
'got ' +
303308
common.inspect(result) +
304309
' expected ' +
@@ -354,9 +359,9 @@ function test_deep_symlink_mix(callback) {
354359
unlink.push(tmp('node-test-realpath-d2'));
355360
}
356361
var expected = tmpAbsDir + '/cycles/root.js';
357-
assert.equal(fs.realpathSync(entry), path.resolve(expected));
362+
assertPathEqual(fs.realpathSync(entry), path.resolve(expected));
358363
asynctest(fs.realpath, [entry], callback, function(err, result) {
359-
assert.equal(result, path.resolve(expected),
364+
assertPathEqual(result, path.resolve(expected),
360365
'got ' +
361366
common.inspect(result) +
362367
' expected ' +
@@ -372,10 +377,10 @@ function test_non_symlinks(callback) {
372377
var expected = tmpAbsDir + '/cycles/root.js';
373378
var origcwd = process.cwd();
374379
process.chdir(entrydir);
375-
assert.equal(fs.realpathSync(entry), path.resolve(expected));
380+
assertPathEqual(fs.realpathSync(entry), path.resolve(expected));
376381
asynctest(fs.realpath, [entry], callback, function(err, result) {
377382
process.chdir(origcwd);
378-
assert.equal(result, path.resolve(expected),
383+
assertPathEqual(result, path.resolve(expected),
379384
'got ' +
380385
common.inspect(result) +
381386
' expected ' +
@@ -388,12 +393,12 @@ var upone = path.join(process.cwd(), '..');
388393
function test_escape_cwd(cb) {
389394
console.log('test_escape_cwd');
390395
asynctest(fs.realpath, ['..'], cb, function(er, uponeActual) {
391-
assert.equal(upone, uponeActual,
396+
assertPathEqual(upone, uponeActual,
392397
'realpath("..") expected: ' + path.resolve(upone) + ' actual:' + uponeActual);
393398
});
394399
}
395400
var uponeActual = fs.realpathSync('..');
396-
assert.equal(upone, uponeActual,
401+
assertPathEqual(upone, uponeActual,
397402
'realpathSync("..") expected: ' + path.resolve(upone) + ' actual:' + uponeActual);
398403

399404

@@ -434,14 +439,14 @@ function test_up_multiple(cb) {
434439
var abedabeda = tmp('abedabeda'.split('').join('/'));
435440
var abedabeda_real = tmp('a');
436441

437-
assert.equal(fs.realpathSync(abedabeda), abedabeda_real);
438-
assert.equal(fs.realpathSync(abedabed), abedabed_real);
442+
assertPathEqual(fs.realpathSync(abedabeda), abedabeda_real);
443+
assertPathEqual(fs.realpathSync(abedabed), abedabed_real);
439444
fs.realpath(abedabeda, function (er, real) {
440445
if (er) throw er;
441-
assert.equal(abedabeda_real, real);
446+
assertPathEqual(abedabeda_real, real);
442447
fs.realpath(abedabed, function (er, real) {
443448
if (er) throw er;
444-
assert.equal(abedabed_real, real);
449+
assertPathEqual(abedabed_real, real);
445450
cb();
446451
cleanup();
447452
});
@@ -499,10 +504,10 @@ function test_abs_with_kids(cb) {
499504
var expectPath = root + '/a/b/c/x.txt';
500505
var actual = fs.realpathSync(linkPath);
501506
// console.log({link:linkPath,expect:expectPath,actual:actual},'sync');
502-
assert.equal(actual, path.resolve(expectPath));
507+
assertPathEqual(actual, path.resolve(expectPath));
503508
asynctest(fs.realpath, [linkPath], cb, function(er, actual) {
504509
// console.log({link:linkPath,expect:expectPath,actual:actual},'async');
505-
assert.equal(actual, path.resolve(expectPath));
510+
assertPathEqual(actual, path.resolve(expectPath));
506511
cleanup();
507512
});
508513
}
@@ -529,22 +534,22 @@ function test_lying_cache_liar(cb) {
529534

530535
var bluff = path.resolve('/foo/bar/baz/bluff');
531536
var rps = fs.realpathSync(bluff, cache);
532-
assert.equal(cache[bluff], rps);
537+
assertPathEqual(cache[bluff], rps);
533538
var nums = path.resolve('/1/2/3/4/5/6/7');
534539
var called = false; // no sync cb calling!
535540
fs.realpath(nums, cache, function(er, rp) {
536541
called = true;
537-
assert.equal(cache[nums], rp);
542+
assertPathEqual(cache[nums], rp);
538543
if (--n === 0) cb();
539544
});
540545
assert(called === false);
541546

542547
var test = path.resolve('/a/b/c/d'),
543548
expect = path.resolve('/a/b/d');
544549
var actual = fs.realpathSync(test, cache);
545-
assert.equal(expect, actual);
550+
assertPathEqual(expect, actual);
546551
fs.realpath(test, cache, function(er, actual) {
547-
assert.equal(expect, actual);
552+
assertPathEqual(expect, actual);
548553
if (--n === 0) cb();
549554
});
550555
}
@@ -577,14 +582,15 @@ function runNextTest(err) {
577582
' subtests completed OK for fs.realpath');
578583
}
579584
testsRun++;
585+
console.log('Running test %d: %s', numtests - tests.length, test.name);
580586
test(runNextTest);
581587
}
582588

583589

584-
assert.equal(root, fs.realpathSync('/'));
590+
assertPathEqual(root, fs.realpathSync('/'));
585591
fs.realpath('/', function(err, result) {
586592
assert.equal(null, err);
587-
assert.equal(root, result);
593+
assertPathEqual(root, result);
588594
});
589595

590596

0 commit comments

Comments
 (0)