forked from shelljs/shelljs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.js
More file actions
74 lines (60 loc) · 2.02 KB
/
pipe.js
File metadata and controls
74 lines (60 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import test from 'ava';
import shell from '..';
shell.config.silent = true;
//
// Invalids
//
test('commands like `rm` cannot be on the right side of pipes', t => {
t.is(shell.ls('.').rm, undefined);
t.is(shell.cat('resources/file1.txt').rm, undefined);
});
//
// Valids
//
test('piping to cat() should return roughly the same thing', t => {
t.is(
shell.cat('resources/file1.txt').cat().toString(),
shell.cat('resources/file1.txt').toString()
);
});
test('piping ls() into cat() converts to a string-like object', t => {
t.is(shell.ls('resources/').cat().toString(), shell.ls('resources/').stdout);
});
test('grep works in a pipe', t => {
const result = shell.ls('resources/').grep('file1');
t.is(result.toString(), 'file1\nfile1.js\nfile1.txt\n');
});
test('multiple pipes work', t => {
const result = shell.ls('resources/').cat().grep('file1');
t.is(result.toString(), 'file1\nfile1.js\nfile1.txt\n');
});
test('Equivalent to a simple grep() test case', t => {
const result = shell.cat('resources/grep/file').grep(/alpha*beta/);
t.falsy(shell.error());
t.is(result.toString(), 'alphaaaaaaabeta\nalphbeta\n');
});
test('Equivalent to a simple sed() test case', t => {
const result = shell.cat('resources/grep/file').sed(/l*\.js/, '');
t.falsy(shell.error());
t.is(
result.toString(),
'alphaaaaaaabeta\nhowareyou\nalphbeta\nthis line ends in\n\n'
);
});
test('Sort a file by frequency of each line', t => {
const result = shell.sort('resources/uniq/pipe').uniq('-c').sort('-n');
t.falsy(shell.error());
t.is(result.toString(), shell.cat('resources/uniq/pipeSorted').toString());
});
test('Synchronous exec', t => {
const result = shell.cat('resources/grep/file').exec('shx grep "alpha*beta"');
t.falsy(shell.error());
t.is(result.toString(), 'alphaaaaaaabeta\nalphbeta\n');
});
test.cb('Asynchronous exec', t => {
shell.cat('resources/grep/file').exec('shx grep "alpha*beta"', (code, stdout) => {
t.is(code, 0);
t.is(stdout, 'alphaaaaaaabeta\nalphbeta\n');
t.end();
});
});