1 | var exec = require('child_process').exec,
|
2 | t = require('tap')
|
3 |
|
4 | var fixture = require.resolve('./fixtures/change-code.js')
|
5 | var expect = require('./fixtures/change-code-expect.json')
|
6 |
|
7 |
|
8 |
|
9 | function isZero10 () {
|
10 | return /^v0\.10\..+$/.test(process.version)
|
11 | }
|
12 |
|
13 |
|
14 | var types = [ 'explicit', 'normal' ]
|
15 | if (!isZero10()) types.push('code')
|
16 |
|
17 |
|
18 |
|
19 | var codes = [ 0, 2, 'null' ]
|
20 |
|
21 |
|
22 |
|
23 | var changes = [ 'nochange', 'change', 'twice']
|
24 | if (!isZero10()) changes.push('code', 'twicecode')
|
25 |
|
26 |
|
27 | var handlers = [ 'sigexit', 'nosigexit' ]
|
28 |
|
29 | var opts = []
|
30 | types.forEach(function (type) {
|
31 | var testCodes = type === 'normal' ? [0] : codes
|
32 | testCodes.forEach(function (code) {
|
33 | changes.forEach(function (change) {
|
34 | handlers.forEach(function (handler) {
|
35 | opts.push([type, code, change, handler].join(' '))
|
36 | })
|
37 | })
|
38 | })
|
39 | })
|
40 |
|
41 | opts.forEach(function (opt) {
|
42 | t.test(opt, function (t) {
|
43 | var cmd = process.execPath + ' ' + fixture + ' ' + opt
|
44 | exec(cmd, function (err, stdout, stderr) {
|
45 | var res = JSON.parse(stdout)
|
46 | if (err) {
|
47 | res.actualCode = err.code
|
48 | res.actualSignal = err.signal
|
49 | } else {
|
50 | res.actualCode = 0
|
51 | res.actualSignal = null
|
52 | }
|
53 | res.stderr = stderr.trim().split('\n')
|
54 | t.same(res, expect[opt])
|
55 | t.end()
|
56 | })
|
57 | })
|
58 | })
|