11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciif (common.isWindows || common.isAIX || common.isIBMi)
61cb0ef41Sopenharmony_ci  common.skip(`No /dev/stdin on ${process.platform}.`);
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst assert = require('assert');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process');
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifor (const code of [
131cb0ef41Sopenharmony_ci  `require('fs').realpath('/dev/stdin', (err, resolvedPath) => {
141cb0ef41Sopenharmony_ci    if (err) {
151cb0ef41Sopenharmony_ci      console.error(err);
161cb0ef41Sopenharmony_ci      process.exit(1);
171cb0ef41Sopenharmony_ci    }
181cb0ef41Sopenharmony_ci    if (resolvedPath) {
191cb0ef41Sopenharmony_ci      process.exit(2);
201cb0ef41Sopenharmony_ci    }
211cb0ef41Sopenharmony_ci  });`,
221cb0ef41Sopenharmony_ci  `try {
231cb0ef41Sopenharmony_ci    if (require('fs').realpathSync('/dev/stdin')) {
241cb0ef41Sopenharmony_ci      process.exit(2);
251cb0ef41Sopenharmony_ci    }
261cb0ef41Sopenharmony_ci  } catch (e) {
271cb0ef41Sopenharmony_ci    console.error(e);
281cb0ef41Sopenharmony_ci    process.exit(1);
291cb0ef41Sopenharmony_ci  }`,
301cb0ef41Sopenharmony_ci]) {
311cb0ef41Sopenharmony_ci  const child = spawnSync(process.execPath, ['-e', code], {
321cb0ef41Sopenharmony_ci    stdio: 'pipe'
331cb0ef41Sopenharmony_ci  });
341cb0ef41Sopenharmony_ci  if (child.status !== 2) {
351cb0ef41Sopenharmony_ci    console.log(code);
361cb0ef41Sopenharmony_ci    console.log(child.stderr.toString());
371cb0ef41Sopenharmony_ci  }
381cb0ef41Sopenharmony_ci  assert.strictEqual(child.status, 2);
391cb0ef41Sopenharmony_ci}
40