-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathio-redirects.js
76 lines (70 loc) · 1.76 KB
/
io-redirects.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var test = require('tape')
var parse = require('../parser')
test('redirecting I/O', function (t) {
var cmd = parse('transform < fromfile > tofile', 'command')
t.deepEqual(cmd, {
type: 'command',
command: { type: 'literal', value: 'transform' },
args: [],
redirects: [
{ type: 'redirectFd',
fd: 0,
op: '<',
filename: { type: 'literal', value: 'fromfile' } },
{ type: 'redirectFd',
fd: 1,
op: '>',
filename: { type: 'literal', value: 'tofile' } }
],
env: {},
control: ';',
next: null
}, "can redirect stdin and stdout in same command")
t.deepEqual(parse('cmd 6> /dev/null', 'command'), {
type: 'command',
command: { type: 'literal', value: 'cmd' },
args: [],
redirects: [
{ type: 'redirectFd',
fd: 6,
op: '>',
filename: { type: 'literal', value: '/dev/null' } }
],
env: {},
control: ';',
next: null
}, "can redirect arbitrary fd's")
t.deepEqual(parse("> /dev/null cmd", 'command'), {
type: 'command',
command: { type: 'literal', value: 'cmd' },
args: [],
redirects: [
{ type: 'redirectFd',
fd: 1,
op: '>',
filename: { type: 'literal', value: '/dev/null' } }
],
env: {},
control: ';',
next: null
}, 'Can start commands with redirects')
t.deepEqual(parse('cmd 2>&1 >/dev/null', 'command'), {
type: 'command',
command: { type: 'literal', value: 'cmd' },
args: [],
redirects: [
{ type: 'duplicateFd',
srcFd: 2,
op: '>&',
destFd: 1 },
{ type: 'redirectFd',
fd: 1,
op: '>',
filename: { type: 'literal', value: '/dev/null' } }
],
env: {},
control: ';',
next: null
})
t.end()
})