MIRROR: javascript for 馃悳's, a tiny runtime with big ambitions
1import { test, summary } from './helpers.js';
2import { $ } from 'ant:shell';
3
4console.log('Shell Tests\n');
5
6const result = $`echo hello`;
7test('shell returns object', typeof result, 'object');
8test('shell has exitCode', typeof result.exitCode, 'number');
9test('shell exitCode success', result.exitCode, 0);
10test('shell has text method', typeof result.text, 'function');
11test('shell has lines method', typeof result.lines, 'function');
12
13test('shell text returns string', typeof result.text(), 'string');
14test('shell text content', result.text(), 'hello');
15
16const lines = result.lines();
17test('shell lines returns array', Array.isArray(lines), true);
18test('shell lines content', lines[0], 'hello');
19
20const multiResult = $`printf "line1\nline2\nline3"`;
21const multiLines = multiResult.lines();
22test('shell multi-line count', multiLines.length, 3);
23test('shell multi-line first', multiLines[0], 'line1');
24test('shell multi-line last', multiLines[2], 'line3');
25
26const name = 'world';
27const interpResult = $`echo hello ${name}`;
28test('shell interpolation', interpResult.text(), 'hello world');
29
30const failResult = $`exit 1`;
31test('shell exit code failure', failResult.exitCode, 1);
32
33const strResult = $('echo string arg');
34test('shell string arg', strResult.text(), 'string arg');
35
36summary();