'use strict';

const common = require('../common');
const assert = require('assert');
const { isMainThread } = require('worker_threads');

if (!isMainThread) {
  common.skip('process.execve is not available in Workers');
} else if (common.isWindows || common.isIBMi) {
  common.skip('process.execve is not available in Windows or IBM i');
}

assert.throws(
  () => {
    process.execve(
      `${process.execPath}_non_existing`,
      [process.execPath, 'arg'],
    );
  },
  (err) => {
    assert.ok(err instanceof Error);
    assert.strictEqual(err.code, 'ENOENT');
    assert.strictEqual(err.syscall, 'execve');
    assert.strictEqual(typeof err.errno, 'number');
    assert.ok(err.errno > 0, `expected positive errno, got ${err.errno}`);
    assert.match(err.path, /_non_existing$/);
    return true;
  },
);

assert.strictEqual(process.stdout.writable, true);
assert.strictEqual(process.stderr.writable, true);
assert.strictEqual(typeof process.pid, 'number');

let tickFired = false;
process.nextTick(common.mustCall(() => { tickFired = true; }));
setImmediate(common.mustCall(() => {
  assert.strictEqual(tickFired, true);
}));
