11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/pull/12022 31cb0ef41Sopenharmony_ci// If the cwd is deleted, Node cannot run files because the module system 41cb0ef41Sopenharmony_ci// relies on uv_cwd(). The -e and -p flags still work though. 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciif (common.isSunOS || common.isWindows || common.isAIX || common.isIBMi) { 91cb0ef41Sopenharmony_ci // The current working directory cannot be removed on these platforms. 101cb0ef41Sopenharmony_ci // Change this to common.skip() when this is no longer a known issue test. 111cb0ef41Sopenharmony_ci assert.fail('cannot rmdir current working directory'); 121cb0ef41Sopenharmony_ci} 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst cp = require('child_process'); 151cb0ef41Sopenharmony_ciconst fs = require('fs'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') { 181cb0ef41Sopenharmony_ci // Do nothing. 191cb0ef41Sopenharmony_ci} else { 201cb0ef41Sopenharmony_ci const tmpdir = require('../common/tmpdir'); 211cb0ef41Sopenharmony_ci tmpdir.refresh(); 221cb0ef41Sopenharmony_ci const dir = fs.mkdtempSync(`${tmpdir.path}/`); 231cb0ef41Sopenharmony_ci process.chdir(dir); 241cb0ef41Sopenharmony_ci fs.rmdirSync(dir); 251cb0ef41Sopenharmony_ci assert.throws(process.cwd, 261cb0ef41Sopenharmony_ci /^Error: ENOENT: no such file or directory, uv_cwd$/); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci const r = cp.spawnSync(process.execPath, [__filename, 'child']); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci assert.strictEqual(r.status, 0); 311cb0ef41Sopenharmony_ci assert.strictEqual(r.signal, null); 321cb0ef41Sopenharmony_ci assert.strictEqual(r.stdout.toString().trim(), ''); 331cb0ef41Sopenharmony_ci assert.strictEqual(r.stderr.toString().trim(), ''); 341cb0ef41Sopenharmony_ci} 35