From 7e031170a6fc1dc458032f382e35ee0a5166cfce Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 21 Oct 2016 22:57:17 +0200 Subject: [PATCH] test: check that `process.execPath` is a realpath This test is only here to ensure consistent cross-platform behaviour. PR-URL: https://github.com/nodejs/node/pull/9229 Reviewed-By: Evan Lucas Reviewed-By: Ben Noordhuis --- test/parallel/test-process-execpath.js | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 test/parallel/test-process-execpath.js diff --git a/test/parallel/test-process-execpath.js b/test/parallel/test-process-execpath.js new file mode 100644 index 00000000000000..5ac8a3f2238a7c --- /dev/null +++ b/test/parallel/test-process-execpath.js @@ -0,0 +1,28 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const child_process = require('child_process'); +const path = require('path'); +const fs = require('fs'); + +assert.strictEqual(process.execPath, fs.realpathSync(process.execPath)); + +if (common.isWindows) { + common.skip('symlinks are weird on windows'); + return; +} + +if (process.argv[2] === 'child') { + // The console.log() output is part of the test here. + console.log(process.execPath); +} else { + common.refreshTmpDir(); + + const symlinkedNode = path.join(common.tmpDir, 'symlinked-node'); + fs.symlinkSync(process.execPath, symlinkedNode); + + const proc = child_process.spawnSync(symlinkedNode, [__filename, 'child']); + assert.strictEqual(proc.stderr.toString(), ''); + assert.strictEqual(proc.stdout.toString(), `${process.execPath}\n`); + assert.strictEqual(proc.status, 0); +}