Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 502263a

Browse files
committed
Merge branch 'topic/capturing-stderr'
2 parents 37dafab + a8fce48 commit 502263a

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

Fixture1.purs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Fixture1 where
2+
3+
fixture = "fixture"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module Fixture where
1+
module Fixture2 w
22

33
fixture = "fixture"

index.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,18 @@ function psc(opts) {
8383
return acc(function(files, cb){
8484
var args = files.concat(options(OPTIONS.psc, opts$prime))
8585
, cmd = cp.spawn('psc', args)
86-
, buffer = new Buffer(0)
86+
, buffero = new Buffer(0)
87+
, buffere = new Buffer(0)
8788
, that = this
8889
;
89-
cmd.stdout.on('data', function(stdout){buffer = Buffer.concat([buffer, new Buffer(stdout)]);});
90-
cmd.stderr.on('data', function(stderr){
91-
gutil.log('Stderr from \'' + gutil.colors.cyan('psc') + '\'\n' + gutil.colors.magenta(stderr));
92-
});
90+
cmd.stdout.on('data', function(stdout){buffero = Buffer.concat([buffero, new Buffer(stdout)]);});
91+
cmd.stderr.on('data', function(stderr){buffere = Buffer.concat([buffere, new Buffer(stderr)]);});
9392
cmd.on('close', function(code){
94-
if (!!code) that.emit('error', new gutil.PluginError(PLUGIN, buffer.toString()));
93+
if (!!code) that.emit('error', new gutil.PluginError(PLUGIN, buffere.toString()));
9594
else {
9695
that.push(new gutil.File({
9796
path: output,
98-
contents: buffer
97+
contents: buffero
9998
}));
10099
}
101100
cb();
@@ -126,21 +125,18 @@ function docgen(opts) {
126125
return acc(function(files, cb){
127126
var args = options(OPTIONS.docgen, opts).concat(files)
128127
, cmd = cp.spawn('docgen', args)
129-
, buffer = new Buffer(0)
128+
, buffero = new Buffer(0)
129+
, buffere = new Buffer(0)
130130
, that = this
131131
;
132-
cmd.stdout.on('data', function(stdout){
133-
buffer = Buffer.concat([buffer, new Buffer(stdout)]);
134-
});
135-
cmd.stderr.on('data', function(stderr){
136-
gutil.log('Stderr from \'' + gutil.colors.cyan('docgen') + '\'\n' + gutil.colors.magenta(stderr));
137-
});
132+
cmd.stdout.on('data', function(stdout){buffero = Buffer.concat([buffero, new Buffer(stdout)]);});
133+
cmd.stderr.on('data', function(stderr){buffere = Buffer.concat([buffere, new Buffer(stderr)]);});
138134
cmd.on('close', function(code){
139-
if (!!code) that.emit('error', new gutil.PluginError(PLUGIN, buffer.toString()));
135+
if (!!code) that.emit('error', new gutil.PluginError(PLUGIN, buffere.toString()));
140136
else {
141137
that.push(new gutil.File({
142138
path: '.',
143-
contents: buffer
139+
contents: buffero
144140
}));
145141
}
146142
cb();

test.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var gutil = require('gulp-util')
88

99
it('should compile purescript', function(cb){
1010
var stream = purescript.psc({noPrelude: true})
11-
, fixture = 'Fixture.purs.hs'
11+
, fixture = 'Fixture1.purs'
1212
;
1313

1414
stream.on('data', function(file){
@@ -33,7 +33,7 @@ it('should compile purescript', function(cb){
3333
});
3434

3535
it('should compile purescript to specified output, without creating file', function(cb){
36-
var fixture = 'Fixture.purs.hs'
36+
var fixture = 'Fixture1.purs'
3737
, output = 'output.js'
3838
, stream = purescript.psc({noPrelude: true, output: output})
3939
;
@@ -58,3 +58,29 @@ it('should compile purescript to specified output, without creating file', funct
5858
}
5959
});
6060
});
61+
62+
it('should fail to compile with an error message', function(cb){
63+
var stream = purescript.psc({noPrelude: true})
64+
, fixture = 'Fixture2.purs'
65+
;
66+
67+
stream.on('error', function(e){
68+
assert("Error" === e.name);
69+
assert(/expecting "where"/.test(e.message));
70+
cb();
71+
});
72+
73+
fs.readFile(fixture, function(e, buffer){
74+
if (e) cb(assert(false));
75+
else {
76+
stream.write(new gutil.File({
77+
cwd: __dirname,
78+
base: __dirname,
79+
path: __dirname + '/' + fixture,
80+
contents: buffer,
81+
stat: {mtime: new Date()}
82+
}));
83+
stream.end();
84+
}
85+
});
86+
});

0 commit comments

Comments
 (0)