11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst { spawn } = require('child_process'); 61cb0ef41Sopenharmony_cifor (const args of [[], ['-']]) { 71cb0ef41Sopenharmony_ci const child = spawn(process.execPath, args, { 81cb0ef41Sopenharmony_ci env: { ...process.env, 91cb0ef41Sopenharmony_ci NODE_DEBUG: process.argv[2] } 101cb0ef41Sopenharmony_ci }); 111cb0ef41Sopenharmony_ci const wanted = `${child.pid}\n`; 121cb0ef41Sopenharmony_ci let found = ''; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci child.stdout.setEncoding('utf8'); 151cb0ef41Sopenharmony_ci child.stdout.on('data', function(c) { 161cb0ef41Sopenharmony_ci found += c; 171cb0ef41Sopenharmony_ci }); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci child.stderr.setEncoding('utf8'); 201cb0ef41Sopenharmony_ci child.stderr.on('data', function(c) { 211cb0ef41Sopenharmony_ci console.error(`> ${c.trim().split('\n').join('\n> ')}`); 221cb0ef41Sopenharmony_ci }); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci child.on('close', common.mustCall(function(c) { 251cb0ef41Sopenharmony_ci assert.strictEqual(c, 0); 261cb0ef41Sopenharmony_ci assert.strictEqual(found, wanted); 271cb0ef41Sopenharmony_ci })); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci setTimeout(function() { 301cb0ef41Sopenharmony_ci child.stdin.end('console.log(process.pid)'); 311cb0ef41Sopenharmony_ci }, 1); 321cb0ef41Sopenharmony_ci} 33