Skip to content

Commit

Permalink
test: add cwd ENOENT known issue test
Browse files Browse the repository at this point in the history
If the current working directory is removed, Node cannot
start normally because the module system calls uv_cwd().

Refs: nodejs#12022
PR-URL: nodejs#12343
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and Trott committed Sep 29, 2017
1 parent e5b11f8 commit 1f4b70b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/known_issues/test-cwd-enoent-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';
// Refs: https://github.com/nodejs/node/pull/12022
// If the cwd is deleted, Node cannot run files because the module system
// relies on uv_cwd(). The -e and -p flags still work though.
const common = require('../common');
const assert = require('assert');

if (common.isSunOS || common.isWindows || common.isAix) {
// The current working directory cannot be removed on these platforms.
// Change this to common.skip() when this is no longer a known issue test.
assert.fail('cannot rmdir current working directory');
return;
}

const cp = require('child_process');
const fs = require('fs');

if (process.argv[2] === 'child') {
// Do nothing.
} else {
common.refreshTmpDir();
const dir = fs.mkdtempSync(common.tmpDir + '/');
process.chdir(dir);
fs.rmdirSync(dir);
assert.throws(process.cwd,
/^Error: ENOENT: no such file or directory, uv_cwd$/);

const r = cp.spawnSync(process.execPath, [__filename, 'child']);

assert.strictEqual(r.status, 0);
assert.strictEqual(r.signal, null);
assert.strictEqual(r.stdout.toString().trim(), '');
assert.strictEqual(r.stderr.toString().trim(), '');
}

0 comments on commit 1f4b70b

Please sign in to comment.