-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If the symlink portion of the test was being skipped due to a combination of OS support and user privileges, then an assertion would always fail. This fixes that problem, improves assertion error reporting and splits the test to make it clear that it is a test for links and symlinks. Fixes: #3311 PR-URL: #3418 Reviewed-By: Johan Bergström <[email protected]>
- Loading branch information
Showing
2 changed files
with
55 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
common.refreshTmpDir(); | ||
|
||
// test creating and reading hard link | ||
const srcPath = path.join(common.fixturesDir, 'cycles', 'root.js'); | ||
const dstPath = path.join(common.tmpDir, 'link1.js'); | ||
|
||
const callback = function(err) { | ||
if (err) throw err; | ||
const srcContent = fs.readFileSync(srcPath, 'utf8'); | ||
const dstContent = fs.readFileSync(dstPath, 'utf8'); | ||
assert.strictEqual(srcContent, dstContent); | ||
}; | ||
|
||
fs.link(srcPath, dstPath, common.mustCall(callback)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,50 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var path = require('path'); | ||
var fs = require('fs'); | ||
var exec = require('child_process').exec; | ||
var completed = 0; | ||
var expected_async = 4; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const exec = require('child_process').exec; | ||
|
||
var linkTime; | ||
var fileTime; | ||
|
||
common.refreshTmpDir(); | ||
|
||
var runtest = function(skip_symlinks) { | ||
if (!skip_symlinks) { | ||
// test creating and reading symbolic link | ||
var linkData = path.join(common.fixturesDir, '/cycles/root.js'); | ||
var linkPath = path.join(common.tmpDir, 'symlink1.js'); | ||
|
||
fs.symlink(linkData, linkPath, function(err) { | ||
if (err) throw err; | ||
console.log('symlink done'); | ||
|
||
fs.lstat(linkPath, function(err, stats) { | ||
if (err) throw err; | ||
linkTime = stats.mtime.getTime(); | ||
completed++; | ||
}); | ||
|
||
fs.stat(linkPath, function(err, stats) { | ||
if (err) throw err; | ||
fileTime = stats.mtime.getTime(); | ||
completed++; | ||
}); | ||
|
||
fs.readlink(linkPath, function(err, destination) { | ||
if (err) throw err; | ||
assert.equal(destination, linkData); | ||
completed++; | ||
}); | ||
}); | ||
} | ||
|
||
// test creating and reading hard link | ||
var srcPath = path.join(common.fixturesDir, 'cycles', 'root.js'); | ||
var dstPath = path.join(common.tmpDir, 'link1.js'); | ||
|
||
fs.link(srcPath, dstPath, function(err) { | ||
if (err) throw err; | ||
console.log('hard link done'); | ||
var srcContent = fs.readFileSync(srcPath, 'utf8'); | ||
var dstContent = fs.readFileSync(dstPath, 'utf8'); | ||
assert.equal(srcContent, dstContent); | ||
completed++; | ||
}); | ||
}; | ||
|
||
if (common.isWindows) { | ||
// On Windows, creating symlinks requires admin privileges. | ||
// We'll only try to run symlink test if we have enough privileges. | ||
exec('whoami /priv', function(err, o) { | ||
if (err || o.indexOf('SeCreateSymbolicLinkPrivilege') == -1) { | ||
expected_async = 1; | ||
runtest(true); | ||
} else { | ||
runtest(false); | ||
console.log('1..0 # Skipped: insufficient privileges'); | ||
return; | ||
} | ||
}); | ||
} else { | ||
runtest(false); | ||
} | ||
|
||
process.on('exit', function() { | ||
assert.equal(completed, expected_async); | ||
assert(linkTime !== fileTime); | ||
common.refreshTmpDir(); | ||
|
||
// test creating and reading symbolic link | ||
const linkData = path.join(common.fixturesDir, '/cycles/root.js'); | ||
const linkPath = path.join(common.tmpDir, 'symlink1.js'); | ||
|
||
fs.symlink(linkData, linkPath, function(err) { | ||
if (err) throw err; | ||
|
||
fs.lstat(linkPath, common.mustCall(function(err, stats) { | ||
if (err) throw err; | ||
linkTime = stats.mtime.getTime(); | ||
})); | ||
|
||
fs.stat(linkPath, common.mustCall(function(err, stats) { | ||
if (err) throw err; | ||
fileTime = stats.mtime.getTime(); | ||
})); | ||
|
||
fs.readlink(linkPath, common.mustCall(function(err, destination) { | ||
if (err) throw err; | ||
assert.equal(destination, linkData); | ||
})); | ||
}); | ||
|
||
|
||
process.on('exit', function() { | ||
assert.notStrictEqual(linkTime, fileTime); | ||
}); |