shelljs/ava-test/cat.js
Nate Fischer 0743004717 test: refactor cat tests to ava (#564)
* test: refactor cat tests to ava

* refactor: only set config.silent once
2016-11-20 13:10:58 -08:00

60 lines
1.4 KiB
JavaScript

import fs from 'fs';
import test from 'ava';
import shell from '..';
shell.config.silent = true;
//
// Invalids
//
test('no paths given', t => {
const result = shell.cat();
t.truthy(shell.error());
t.is(result.code, 1);
t.is(result.stderr, 'cat: no paths given');
});
test('nonexistent file', t => {
t.falsy(fs.existsSync('/asdfasdf')); // sanity check
const result = shell.cat('/asdfasdf'); // file does not exist
t.truthy(shell.error());
t.is(result.code, 1);
t.is(result.stderr, 'cat: no such file or directory: /asdfasdf');
});
//
// Valids
//
test('simple', t => {
const result = shell.cat('resources/cat/file1');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), 'test1\n');
});
test('multiple files', t => {
const result = shell.cat('resources/cat/file2', 'resources/cat/file1');
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), 'test2\ntest1\n');
});
test('multiple files, array syntax', t => {
const result = shell.cat(['resources/cat/file2', 'resources/cat/file1']);
t.falsy(shell.error());
t.is(result.code, 0);
t.is(result.toString(), 'test2\ntest1\n');
});
test('glob', t => {
const result = shell.cat('resources/file*.txt');
t.falsy(shell.error());
t.is(result.code, 0);
t.truthy(result.search('test1') > -1); // file order might be random
t.truthy(result.search('test2') > -1);
});