UNPKG

1.74 kBJavaScriptView Raw
1var exec = require('child_process').exec;
2var cout, cerr, exit;
3
4function run (args) {
5 beforeEach(function (next) {
6 exec('./bin/hicat ' + args, function (_exit, _cout, _cerr) {
7 exit = _exit;
8 cout = _cout;
9 cerr = _cerr;
10 next();
11 });
12 });
13}
14
15function success () {
16 it('is successful', function () {
17 expect(exit).eql(null);
18 });
19}
20
21describe('--help', function () {
22 run('--help');
23 success();
24
25 it('shows --help', function () {
26 expect(cout).include('-h, --help');
27 expect(cout).include('print usage information');
28 });
29});
30
31describe('--version', function () {
32 run('--version');
33 success();
34
35 it('is successful', function () {
36 expect(exit).eql(null);
37 });
38
39 it('shows version info', function () {
40 expect(cout).include(require('../package.json').version);
41 });
42});
43
44describe('-v', function () {
45 run('-v');
46 success();
47
48 it('is successful', function () {
49 expect(exit).eql(null);
50 });
51
52 it('shows version info', function () {
53 expect(cout).include(require('../package.json').version);
54 });
55});
56
57describe('a ruby example', function () {
58 run('samples/ruby.rb --no-pager');
59 success();
60
61 it('is successful', function () {
62 expect(exit).eql(null);
63 });
64
65 it('highlights', function () {
66 expect(cout).match(/method/);
67 expect(cout).match(/string/);
68 });
69});
70
71describe('not found', function () {
72 run('xxx yyy zzz --no-pager');
73
74 it('fails', function () {
75 expect(exit.code).eql(8);
76 });
77
78 it('does no output', function () {
79 expect(cout).eql('');
80 });
81
82 it('reports errors', function () {
83 expect(cerr).match(/xxx/);
84 expect(cerr).match(/yyy/);
85 expect(cerr).match(/zzz/);
86 expect(cerr).match(/no such file or directory/);
87 });
88});