11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst cp = require('child_process');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci// This test spawns itself with an argument to indicate when it is a child to
71cb0ef41Sopenharmony_ci// easily and portably print the value of argv[0]
81cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') {
91cb0ef41Sopenharmony_ci  console.log(process.argv0);
101cb0ef41Sopenharmony_ci  return;
111cb0ef41Sopenharmony_ci}
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ciconst noArgv0 = cp.spawnSync(process.execPath, [__filename, 'child']);
141cb0ef41Sopenharmony_ciassert.strictEqual(noArgv0.stdout.toString().trim(), process.execPath);
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_ciconst withArgv0 = cp.spawnSync(process.execPath, [__filename, 'child'],
171cb0ef41Sopenharmony_ci                               { argv0: 'withArgv0' });
181cb0ef41Sopenharmony_ciassert.strictEqual(withArgv0.stdout.toString().trim(), 'withArgv0');
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciassert.throws(() => {
211cb0ef41Sopenharmony_ci  cp.spawnSync(process.execPath, [__filename, 'child'], { argv0: [] });
221cb0ef41Sopenharmony_ci}, {
231cb0ef41Sopenharmony_ci  code: 'ERR_INVALID_ARG_TYPE',
241cb0ef41Sopenharmony_ci  name: 'TypeError',
251cb0ef41Sopenharmony_ci  message: 'The "options.argv0" property must be of type string.' +
261cb0ef41Sopenharmony_ci           common.invalidArgTypeHelper([])
271cb0ef41Sopenharmony_ci});
28