Repository navigation
Expand file tree
/
Copy pathtest.coffee
More file actions
97 lines (79 loc) · 3.07 KB
/
Copy pathtest.coffee
File metadata and controls
97 lines (79 loc) · 3.07 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
chai = require 'chai'
chai.should()
chai.use require 'chai-as-promised'
exec = require '../lib'
describe 'exec', ->
it 'should accept Node.js style callbacks', (done) ->
exec.quiet 'bash -c "echo 1"', (err, stdout, stderr) ->
stdout.should.eq '1\n'
done()
it 'should expose Promise API', ->
{stdout} = yield exec.quiet 'bash -c "echo 1"'
stdout.should.eq '1\n'
it 'should split commands on multiple lines', ->
{stdout} = yield exec.quiet '''
bash -c "echo 1"
bash -c "echo 2"
bash -c "echo 3"
'''
stdout.should.eq '1\n2\n3\n'
it 'should split commands on multiple lines with spaces', ->
{stdout} = yield exec.quiet '''
bash -c "echo 1"
bash -c "echo 2"
bash -c "echo 3"
'''
stdout.should.eq '1\n2\n3\n'
it 'should buffer all stdout', (done) ->
exec.quiet 'bash -c "echo 1"', (err, stdout, stderr) ->
stdout.should.eq '1\n'
done()
it 'should buffer all stderr', (done) ->
exec.quiet 'bash -c doesnotexist', (err, stdout, stderr) ->
stderr.should.contain 'command not found'
done()
it 'should shell out if necessary', ->
{stdout} = yield exec 'echo foo | cat'
stdout.should.eq 'foo\n'
describe 'promises', ->
it 'should not reject non-zero status', ->
{stdout, stderr, status} = yield exec.quiet 'bash -c doesnotexist'
stdout.should.eq ''
stderr.should.contain 'command not found'
status.should.eq 127
it 'should reject non-zero status with strict enabled', ->
p = exec.quiet 'bash -c doesnotexist', strict: true
yield p.should.be.rejectedWith Error
it 'should continue processing, when strict mode is implicitly disabled, after a non-zero exit code', ->
{stdout, stderr} = yield exec ['bash -c "exit 1"', "echo -n 'It worked'"]
stdout.should.eq 'It worked'
stderr.should.eq ''
it 'should continue processing, when strict mode is explicitly disabled, after a non-zero exit code', ->
{stdout, stderr} = yield exec ['bash -c "exit 1"', "echo -n 'It worked'"], { strict:false }
stdout.should.eq 'It worked'
stderr.should.eq ''
it 'should not continue processing when strict mode is enabled after a non-zero exit code', ->
p = exec ['bash -c "exit 1"', "echo -n 'It worked'"], { strict:true }
yield p.should.be.rejectedWith Error
describe 'interactive', ->
it 'should not buffer output', ->
{stdout, stderr} = yield exec.interactive 'bash -c "echo 1"'
stdout.should.eq ''
stderr.should.eq ''
{stdout, stderr} = yield exec.interactive 'bash -c doesnotexist'
stdout.should.eq ''
stderr.should.eq ''
describe 'sync', ->
it 'should execute command synchronously', ->
{stdout, stderr} = exec.sync 'bash -c "echo 1"'
stdout.should.eq '1\n'
stderr.should.eq ''
describe 'parallel', ->
it 'should execute commands in parallel', ->
{stdout, stderr} = yield exec.parallel '''
bash -c "sleep 1 && echo 1"
bash -c "echo 2"
bash -c "echo 3"
'''
stdout.should.eq '2\n3\n1\n'
stderr.should.eq ''