-
-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] stdio option handling #36
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
var util = require('util'); | ||
|
||
var alias = ['stdin', 'stdout', 'stderr']; | ||
|
||
module.exports = function (opts) { | ||
if (!opts) { | ||
return null; | ||
} | ||
|
||
if (typeof opts.stdio === 'string') { | ||
return opts.stdio; | ||
} | ||
|
||
var stdio = opts.stdio || []; | ||
|
||
if (!Array.isArray(stdio)) { | ||
throw new TypeError('Incorrect value of stdio option: ' + util.inspect(stdio)); | ||
} | ||
|
||
var result = []; | ||
var len = Math.max(stdio.length, alias.length); | ||
|
||
for (var i = 0; i < len; i++) { | ||
result[i] = stdio[i] || opts[alias[i]] || null; | ||
} | ||
|
||
return result; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ import path from 'path'; | |
import stream from 'stream'; | ||
import test from 'ava'; | ||
import getStream from 'get-stream'; | ||
import m from './'; | ||
import m from '../'; | ||
|
||
process.env.PATH = path.join(__dirname, 'fixtures') + path.delimiter + process.env.PATH; | ||
process.env.PATH = path.join(__dirname, '..', 'fixtures') + path.delimiter + process.env.PATH; | ||
|
||
test('execa()', async t => { | ||
const {stdout} = await m('noop', ['foo']); | ||
|
@@ -34,12 +34,12 @@ test('stdout/stderr available on errors', async t => { | |
}); | ||
|
||
test('include stdout in errors for improved debugging', async t => { | ||
const err = await t.throws(m('fixtures/error-message.js')); | ||
const err = await t.throws(m('../fixtures/error-message.js')); | ||
t.regex(err.message, /stdout/); | ||
}); | ||
|
||
test('execa.shell()', async t => { | ||
const {stdout} = await m.shell('node fixtures/noop foo'); | ||
const {stdout} = await m.shell('node ../fixtures/noop foo'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Required because: avajs/ava#32 (comment) |
||
t.is(stdout, 'foo'); | ||
}); | ||
|
||
|
@@ -54,7 +54,7 @@ test('execa.sync()', t => { | |
}); | ||
|
||
test('execa.shellSync()', t => { | ||
const {stdout} = m.shellSync('node fixtures/noop foo'); | ||
const {stdout} = m.shellSync('node ../fixtures/noop foo'); | ||
t.is(stdout, 'foo'); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import util from 'util'; | ||
import test from 'ava'; | ||
import stdio from '../lib/stdio'; | ||
|
||
util.inspect.styles.name = 'magenta'; | ||
|
||
function t(input, expected) { | ||
test(util.inspect(input, {colors: true}), t => { | ||
const result = stdio(input); | ||
|
||
if (typeof expected === 'object' && expected !== null) { | ||
t.deepEqual(result, expected); | ||
} else { | ||
t.is(result, expected); | ||
} | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We really need test macros. |
||
|
||
t(undefined, null); | ||
t(null, null); | ||
|
||
t({stdio: 'inherit'}, 'inherit'); | ||
t({stdio: 'pipe'}, 'pipe'); | ||
t({stdio: 'ignore'}, 'ignore'); | ||
|
||
t({}, [null, null, null]); | ||
t({stdio: []}, [null, null, null]); | ||
t({stdin: 'pipe'}, ['pipe', null, null]); | ||
t({stdout: 'ignore'}, [null, 'ignore', null]); | ||
t({stderr: 'inherit'}, [null, null, 'inherit']); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also do one with |
||
|
||
// precedence | ||
t({stdin: 'inherit', stdio: 'pipe'}, 'pipe'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't we just throw if they're used together? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that's probably the way to go. |
||
t({stdin: 'inherit', stdio: ['pipe']}, ['pipe', null, null]); | ||
t({stdin: 'inherit', stdio: [undefined, 'pipe']}, ['inherit', 'pipe', null]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.