<commit_before>var sw = require('../')
var isWindows = require('../lib/is-windows.js')()
var winNoShebang = isWindows && 'no shebang execution on windows'

var onExit = require('signal-exit')
var cp = require('child_process')
var fixture = require.resolve('./fixtures/script.js')
var fs = require('fs')
var path = require('path')

if (process.argv[2] === 'parent') {
  // hang up once
  process.once('SIGHUP', function onHup () {
    console.log('SIGHUP')
  })
  // handle sigints forever
  process.on('SIGINT', function onInt () {
    console.log('SIGINT')
  })
  onExit(function (code, signal) {
    console.log('EXIT %j', [code, signal])
  })
  var argv = process.argv.slice(3).map(function (arg) {
    if (arg === fixture) {
      return '{{FIXTURE}}'
    }
    return arg
  })
  console.log('WRAP %j', process.execArgv.concat(argv))
  sw.runMain()
  return
}

var t = require('tap')
var unwrap = sw([__filename, 'parent'])

var expect = 'WRAP ["{{FIXTURE}}","xyz"]\n' +
  '[]\n' +
  '["xyz"]\n' +
  'EXIT [0,null]\n'

t.test('spawn execPath', function (t) {
  var child = cp.spawn(process.execPath, [fixture, 'xyz'])

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })
  child.on('close', function (code, signal) {
    t.equal(code, 0)
    t.equal(signal, null)
    t.equal(out, expect)
    t.end()
  })
})

t.test('exec execPath', function (t) {
  var opt = isWindows ? null : { shell: '/bin/bash' }
  var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', opt)

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })
  child.on('close', function (code, signal) {
    t.equal(code, 0)
    t.equal(signal, null)
    t.equal(out, expect)
    t.end()
  })
})

t.test('exec execPath SIGINT', function (t) {
  var opt = isWindows ? null : { shell: '/bin/bash' }
  var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', opt)

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })
  child.stdout.once('data', function () {
    child.kill('SIGINT')
  })
  child.stderr.on('data', function (t) {
    console.error(t)
  })
  child.on('close', function (code, signal) {
    t.equal(code, 0)
    t.equal(signal, null)
    t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' +
      '[]\n' +
      '["xyz"]\n' +
      'SIGINT\n' +
      'EXIT [0,null]\n')
    t.end()
  })
})

t.test('exec execPath SIGHUP', function (t) {
  var opt = isWindows ? null : { shell: '/bin/bash' }
  var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', opt)

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
    child.kill('SIGHUP')
  })
  child.on('close', function (code, signal) {
    t.equal(signal, 'SIGHUP')
    t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' +
      '[]\n' +
      '["xyz"]\n' +
      'SIGHUP\n' +
      'EXIT [null,"SIGHUP"]\n')
    t.end()
  })
})

t.test('exec shebang', { skip: winNoShebang }, function (t) {
  var child = cp.exec(fixture + ' xyz', { shell: '/bin/bash' })

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })<commit_msg>no signals pass through cmd.exe<commit_after>var sw = require('../')
var isWindows = require('../lib/is-windows.js')()
var winNoShebang = isWindows && 'no shebang execution on windows'
var winNoSig = isWindows && 'no signals get through cmd'

var onExit = require('signal-exit')
var cp = require('child_process')
var fixture = require.resolve('./fixtures/script.js')
var fs = require('fs')
var path = require('path')

if (process.argv[2] === 'parent') {
  // hang up once
  process.once('SIGHUP', function onHup () {
    console.log('SIGHUP')
  })
  // handle sigints forever
  process.on('SIGINT', function onInt () {
    console.log('SIGINT')
  })
  onExit(function (code, signal) {
    console.log('EXIT %j', [code, signal])
  })
  var argv = process.argv.slice(3).map(function (arg) {
    if (arg === fixture) {
      return '{{FIXTURE}}'
    }
    return arg
  })
  console.log('WRAP %j', process.execArgv.concat(argv))
  sw.runMain()
  return
}

var t = require('tap')
var unwrap = sw([__filename, 'parent'])

var expect = 'WRAP ["{{FIXTURE}}","xyz"]\n' +
  '[]\n' +
  '["xyz"]\n' +
  'EXIT [0,null]\n'

t.test('spawn execPath', function (t) {
  var child = cp.spawn(process.execPath, [fixture, 'xyz'])

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })
  child.on('close', function (code, signal) {
    t.equal(code, 0)
    t.equal(signal, null)
    t.equal(out, expect)
    t.end()
  })
})

t.test('exec execPath', function (t) {
  var opt = isWindows ? null : { shell: '/bin/bash' }
  var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', opt)

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })
  child.on('close', function (code, signal) {
    t.equal(code, 0)
    t.equal(signal, null)
    t.equal(out, expect)
    t.end()
  })
})

t.test('exec execPath SIGINT', { skip: winNoSig }, function (t) {
  var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', { shell: '/bin/bash' })

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })
  child.stdout.once('data', function () {
    child.kill('SIGINT')
  })
  child.stderr.on('data', function (t) {
    console.error(t)
  })
  child.on('close', function (code, signal) {
    t.equal(code, 0)
    t.equal(signal, null)
    t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' +
      '[]\n' +
      '["xyz"]\n' +
      'SIGINT\n' +
      'EXIT [0,null]\n')
    t.end()
  })
})

t.test('exec execPath SIGHUP', { skip: winNoSig }, function (t) {
  var child = cp.exec(process.execPath + ' ' + fixture + ' xyz', { shell: '/bin/bash' })

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
    child.kill('SIGHUP')
  })
  child.on('close', function (code, signal) {
    t.equal(signal, 'SIGHUP')
    t.equal(out, 'WRAP ["{{FIXTURE}}","xyz"]\n' +
      '[]\n' +
      '["xyz"]\n' +
      'SIGHUP\n' +
      'EXIT [null,"SIGHUP"]\n')
    t.end()
  })
})

t.test('exec shebang', { skip: winNoShebang }, function (t) {
  var child = cp.exec(fixture + ' xyz', { shell: '/bin/bash' })

  var out = ''
  child.stdout.on('data', function (c) {
    out += c
  })
{'fraction_non_alphanumeric': 0.2141348497156783, 'fraction_numerical': 0.002274573517465475, 'mean_word_length': 2.966494845360825, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4687884', 'n_tokens_mistral': 2410, 'n_tokens_neox': 2364, 'n_words': 510}