1 |
|
2 |
|
3 | var exec = require('child_process').exec;
|
4 | var bin = './bin/hicat';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | exports.run = function (args) {
|
16 | before(function (next) {
|
17 | exec(bin + ' ' + args, function (_exit, _cout, _cerr) {
|
18 | global.result = {
|
19 | code: _exit && _exit.code || 0,
|
20 | error: _exit,
|
21 | out: _cout,
|
22 | stripped: _cout.replace(/\033\[[^m]*m/g, ''),
|
23 | stderr: _cerr
|
24 | };
|
25 | next();
|
26 | });
|
27 | });
|
28 |
|
29 | after(function () {
|
30 | delete global.result;
|
31 | });
|
32 | };
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | exports.success = function () {
|
44 | it('is successful', function () {
|
45 | expect(global.result.code).eql(0);
|
46 | expect(global.result.error).falsy;
|
47 | });
|
48 | };
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | exports.pipe = function (input, args) {
|
60 | before(function (next) {
|
61 | var spawn = require('child_process').spawn;
|
62 | var child = spawn(bin, args || [], { stdio: 'pipe' });
|
63 | var result = global.result = { out: '', stderr: '' };
|
64 |
|
65 | if (input) {
|
66 | child.stdin.write(input);
|
67 | child.stdin.end();
|
68 | }
|
69 |
|
70 | child.stdout.on('data', function (data) { result.out += data; });
|
71 | child.stderr.on('data', function (data) { result.stderr += data; });
|
72 | child.on('close', function (code) {
|
73 | result.code = code;
|
74 | next();
|
75 | });
|
76 | });
|
77 |
|
78 | after(function () {
|
79 | delete global.result;
|
80 | });
|
81 | };
|