-
-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
290 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
var t = require('../') | ||
|
||
if (process.platform === 'win32') { | ||
t.plan(0, 'shebangs and exe bits are unix only') | ||
process.exit(0) | ||
} | ||
|
||
var spawn = require('child_process').spawn | ||
var path = require('path') | ||
var fs = require('fs') | ||
var fixdir = path.resolve(__dirname, 'executable-scripts') | ||
var executed = path.resolve(fixdir, 'executed.sh') | ||
var notExecuted = path.resolve(fixdir, 'not-executed.sh') | ||
var run = require.resolve('../bin/run.js') | ||
var node = process.execPath | ||
|
||
function cleanup () { | ||
try { fs.unlinkSync(executed) } catch (e) {} | ||
try { fs.unlinkSync(notExecuted) } catch (e) {} | ||
try { fs.rmdirSync(fixdir) } catch (e) {} | ||
} | ||
|
||
t.test('setup', function (t) { | ||
cleanup() | ||
fs.mkdirSync(fixdir, '0755') | ||
fs.writeFileSync( | ||
executed, | ||
'#!/bin/sh\n' + | ||
'echo 1..1\n' + | ||
'echo ok 1 File with executable bit should be executed\n' | ||
) | ||
fs.chmodSync(executed, '0755') | ||
fs.writeFileSync( | ||
notExecuted, | ||
'#!/bin/sh\n' + | ||
'echo 1..1\n' + | ||
'echo not ok 1 File without executable bit should not be run\n' + | ||
'exit 1\n' | ||
) | ||
fs.chmodSync(notExecuted, '0644') | ||
t.end() | ||
}) | ||
|
||
t.test('run tap bin on shell scripts', function (t) { | ||
var args = [run, fixdir, '--bail', '--no-color', '-Rtap'] | ||
var child = spawn(node, args) | ||
var output = '' | ||
child.stdout.on('data', function (c) { | ||
output += c | ||
}) | ||
|
||
child.on('close', function (code, signal) { | ||
t.equal(code, 0, 'exit 0') | ||
t.equal(signal, null, 'no signal exit') | ||
t.notMatch(output, /not-executed\.sh/, 'not-executed.sh not seen') | ||
t.match(output, /executed\.sh/, 'executed.sh was seen') | ||
t.end() | ||
}) | ||
}) | ||
|
||
t.tearDown(cleanup) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var cp = require('child_process') | ||
var spawn = cp.spawn | ||
cp.spawn = hijackedSpawn | ||
|
||
var throwNow = false | ||
var throwLater = false | ||
function hijackedSpawn (cmd, args, options) { | ||
if (throwNow) { | ||
throw throwNow | ||
} | ||
var child = spawn.call(cp, cmd, args, options) | ||
if (throwLater) { | ||
setTimeout(function () { | ||
child.emit('error', throwLater) | ||
}) | ||
} | ||
return child | ||
} | ||
|
||
var t = require('../') | ||
var Test = t.Test | ||
var ok = require.resolve('./test/ok.js') | ||
|
||
t.test('handle throws from spawn()', function (t) { | ||
throwNow = new Error('now is fine') | ||
|
||
var output = '' | ||
var tt = new Test() | ||
tt.on('data', function (c) { | ||
output += c | ||
}) | ||
t.doesNotThrow(function spawn_throw_now () { | ||
tt.spawn(process.execPath, [ok]) | ||
}) | ||
tt.end() | ||
throwNow = false | ||
|
||
t.comment(output) | ||
t.notOk(tt.passing(), 'a failed spawn should fail the test') | ||
t.end() | ||
}) | ||
|
||
t.test('handle child process error event', function (t) { | ||
throwLater = new Error('later is fine') | ||
|
||
var output = '' | ||
var tt = new Test() | ||
tt.on('data', function (c) { | ||
output += c | ||
}) | ||
t.doesNotThrow(function spawn_throw_later () { | ||
tt.spawn(process.execPath, [ok]) | ||
}) | ||
tt.end() | ||
|
||
setTimeout(function () { | ||
throwLater = false | ||
t.comment(output) | ||
t.notOk(tt.passing(), 'a failed spawn should fail the test') | ||
t.end() | ||
}, 100) | ||
}) |
Oops, something went wrong.