Reorder tests.
This commit is contained in:
parent
0ad6ff7d10
commit
7b77066980
1 changed files with 145 additions and 136 deletions
|
@ -47,119 +47,40 @@ void main() {
|
||||||
expect(exitCode, exitFailure);
|
expect(exitCode, exitFailure);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('no directories', () async {
|
|
||||||
exitCode = await app.main(['bin']);
|
|
||||||
expect(exitCode, exitFailure);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('missing file', () async {
|
test('missing file', () async {
|
||||||
exitCode = await app.main(['foo']);
|
exitCode = await app.main(['foo']);
|
||||||
expect(exitCode, exitFailure, reason: 'foo not found');
|
expect(exitCode, exitFailure, reason: 'foo not found');
|
||||||
exitCode = await app.main([sourceFile, 'foo']);
|
exitCode = await app.main([sourceFile, 'foo']);
|
||||||
expect(exitCode, exitFailure, reason: 'one missing file');
|
expect(exitCode, exitFailure, reason: 'one missing file');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('no directories', () async {
|
||||||
|
exitCode = await app.main(['bin']);
|
||||||
|
expect(exitCode, exitFailure);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('lib', () {
|
group('lib', () {
|
||||||
test('CatResult defaults', () async {
|
test('CatResult defaults', () async {
|
||||||
final result = CatResult();
|
final result = CatResult();
|
||||||
expect(result.isSuccess, true, reason: 'success by default');
|
expect(result.isSuccess, true, reason: 'success by default');
|
||||||
result.addMessage(exitFailure, sampleText);
|
expect(result.messages.isEmpty, true, reason: 'empty by default');
|
||||||
|
result.addMessage(sampleText);
|
||||||
expect(result.isFailure, true, reason: 'is failure');
|
expect(result.isFailure, true, reason: 'is failure');
|
||||||
expect(result.messages.first, equals(sampleText),
|
expect(result.messages.first, equals(sampleText),
|
||||||
reason: 'message is sample');
|
reason: 'message is sample');
|
||||||
|
final path = 'foo/bar';
|
||||||
|
result.addMessage(sampleText, path: path);
|
||||||
|
expect(result.messages.last, equals("$path: $sampleText"), reason: 'message has path');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cat source', () async {
|
test('cat -', () async {
|
||||||
final tmp = makeTmpFile();
|
var tmp = makeTmpFile();
|
||||||
await cat([sourceFile], tmp.openWrite());
|
final result = await cat(['-'], tmp.openWrite(), input: mockStdin());
|
||||||
final lines = await tmp.readAsLines();
|
expect(result.exitCode, exitSuccess, reason: 'result code is successful');
|
||||||
expect(lines.isEmpty, false, reason: 'log is empty');
|
expect(result.messages.length, 0, reason: 'no message');
|
||||||
expect(lines.first, startsWith('// Copyright (c)'),
|
tmp = makeTmpFile();
|
||||||
reason: 'has copyright');
|
expect(await tmp.exists(), false, reason: 'tmp file does not exists');
|
||||||
expect(lines.last, equals('}'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cat -n source', () async {
|
|
||||||
final tmp = makeTmpFile();
|
|
||||||
final result =
|
|
||||||
await cat([sourceFile], tmp.openWrite(), showLineNumbers: true);
|
|
||||||
expect(result.exitCode, 0, reason: 'result code is 0');
|
|
||||||
final lines = await tmp.readAsLines();
|
|
||||||
expect(lines.first, startsWith(' 1\t// Copyright (c)'),
|
|
||||||
reason: 'has copyright');
|
|
||||||
expect(lines.last, endsWith('\t}'), reason: 'last line');
|
|
||||||
for (final line in lines) {
|
|
||||||
expect(line, matches('^ +\\d+\t.*'), reason: 'has line number');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cat source, test', () async {
|
|
||||||
final tmp = makeTmpFile();
|
|
||||||
await cat([sourceFile, sampleFile], tmp.openWrite());
|
|
||||||
final lines = await tmp.readAsLines();
|
|
||||||
expect(lines.length, greaterThan(10), reason: 'more than 10 lines');
|
|
||||||
expect(lines.first, startsWith('// Copyright'),
|
|
||||||
reason: 'start with copyright');
|
|
||||||
expect(lines.last, endsWith('✓'), reason: 'end with checkmark');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cat -E', () async {
|
|
||||||
final tmp = makeTmpFile();
|
|
||||||
await cat([sampleFile], tmp.openWrite(), showEnds: true);
|
|
||||||
var hasBlank = false;
|
|
||||||
final lines = await tmp.readAsLines();
|
|
||||||
for (var i = 0; i < lines.length - 1; i++) {
|
|
||||||
expect(lines[i], endsWith('\$'));
|
|
||||||
if (lines[i] == '\$') {
|
|
||||||
hasBlank = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(hasBlank, true, reason: 'has blank line');
|
|
||||||
expect(lines.last, endsWith('✓'), reason: 'has unicode');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cat -bE', () async {
|
|
||||||
final tmp = makeTmpFile();
|
|
||||||
await cat([sampleFile], tmp.openWrite(),
|
|
||||||
numberNonBlank: true, showEnds: true);
|
|
||||||
final lines = await tmp.readAsLines();
|
|
||||||
for (var i = 0; i < lines.length - 1; i++) {
|
|
||||||
expect(lines[i], endsWith('\$'), reason: '${lines[i]} ends with \$');
|
|
||||||
if (lines[i] != '\$') {
|
|
||||||
expect(lines[i], contains(RegExp(r'^ +\d+\t.*\$$')),
|
|
||||||
reason: '${lines[i]} is valid');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cat -T', () async {
|
|
||||||
final tmp = makeTmpFile();
|
|
||||||
await cat([sampleFile], tmp.openWrite(), showTabs: true);
|
|
||||||
var hasTab = false;
|
|
||||||
final lines = await tmp.readAsLines();
|
|
||||||
for (final String line in lines) {
|
|
||||||
if (line.startsWith('^I')) {
|
|
||||||
hasTab = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(hasTab, true, reason: 'has tab');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cat -s', () async {
|
|
||||||
final tmp = makeTmpFile();
|
|
||||||
await cat([sampleFile], tmp.openWrite(), squeezeBlank: true);
|
|
||||||
var hasSqueeze = true;
|
|
||||||
var prevLine = 'foo';
|
|
||||||
final lines = await tmp.readAsLines();
|
|
||||||
for (final String line in lines) {
|
|
||||||
if (line == prevLine) {
|
|
||||||
hasSqueeze = false;
|
|
||||||
}
|
|
||||||
prevLine = line;
|
|
||||||
}
|
|
||||||
expect(hasSqueeze, true, reason: 'has squeeze');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cat -A', () async {
|
test('cat -A', () async {
|
||||||
|
@ -172,14 +93,6 @@ void main() {
|
||||||
reason: "no last linefeed");
|
reason: "no last linefeed");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cat -t', () async {
|
|
||||||
final tmp = makeTmpFile();
|
|
||||||
await cat([sampleFile], tmp.openWrite(),
|
|
||||||
showNonPrinting: true, showTabs: true);
|
|
||||||
final lines = await tmp.readAsLines();
|
|
||||||
expect(lines.last, equals('^I^A^B^C^DM-BM-)^?M-BM-^@M-bM-^\\M-^S'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cat -Abs', () async {
|
test('cat -Abs', () async {
|
||||||
final tmp = makeTmpFile();
|
final tmp = makeTmpFile();
|
||||||
await cat([sampleFile], tmp.openWrite(),
|
await cat([sampleFile], tmp.openWrite(),
|
||||||
|
@ -198,6 +111,94 @@ void main() {
|
||||||
expect(blankLines, 2, reason: 'only 2 blank lines.');
|
expect(blankLines, 2, reason: 'only 2 blank lines.');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('cat -E', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
await cat([sampleFile], tmp.openWrite(), showEnds: true);
|
||||||
|
var hasBlank = false;
|
||||||
|
final lines = await tmp.readAsLines();
|
||||||
|
for (var i = 0; i < lines.length - 1; i++) {
|
||||||
|
expect(lines[i], endsWith('\$'));
|
||||||
|
if (lines[i] == '\$') {
|
||||||
|
hasBlank = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(hasBlank, true, reason: 'has blank line');
|
||||||
|
expect(lines.last, endsWith('✓'), reason: 'has unicode');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cat -T', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
await cat([sampleFile], tmp.openWrite(), showTabs: true);
|
||||||
|
var hasTab = false;
|
||||||
|
final lines = await tmp.readAsLines();
|
||||||
|
for (final String line in lines) {
|
||||||
|
if (line.startsWith('^I')) {
|
||||||
|
hasTab = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(hasTab, true, reason: 'has tab');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cat -bE', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
await cat([sampleFile], tmp.openWrite(),
|
||||||
|
numberNonBlank: true, showEnds: true);
|
||||||
|
final lines = await tmp.readAsLines();
|
||||||
|
for (var i = 0; i < lines.length - 1; i++) {
|
||||||
|
expect(lines[i], endsWith('\$'), reason: '${lines[i]} ends with \$');
|
||||||
|
if (lines[i] != '\$') {
|
||||||
|
expect(lines[i], contains(RegExp(r'^ +\d+\t.*\$$')),
|
||||||
|
reason: '${lines[i]} is valid');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cat -n source', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
final result =
|
||||||
|
await cat([sourceFile], tmp.openWrite(), showLineNumbers: true);
|
||||||
|
expect(result.exitCode, 0, reason: 'result code is 0');
|
||||||
|
final lines = await tmp.readAsLines();
|
||||||
|
expect(lines.first, startsWith(' 1\t// Copyright (c)'),
|
||||||
|
reason: 'has copyright');
|
||||||
|
expect(lines.last, endsWith('\t}'), reason: 'last line');
|
||||||
|
for (final line in lines) {
|
||||||
|
expect(line, matches('^ +\\d+\t.*'), reason: 'has line number');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cat -s', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
await cat([sampleFile], tmp.openWrite(), squeezeBlank: true);
|
||||||
|
var hasSqueeze = true;
|
||||||
|
var prevLine = 'foo';
|
||||||
|
final lines = await tmp.readAsLines();
|
||||||
|
for (final String line in lines) {
|
||||||
|
if (line == prevLine) {
|
||||||
|
hasSqueeze = false;
|
||||||
|
}
|
||||||
|
prevLine = line;
|
||||||
|
}
|
||||||
|
expect(hasSqueeze, true, reason: 'has squeeze');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cat -t', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
await cat([sampleFile], tmp.openWrite(),
|
||||||
|
showNonPrinting: true, showTabs: true);
|
||||||
|
final lines = await tmp.readAsLines();
|
||||||
|
expect(lines.last, equals('^I^A^B^C^DM-BM-)^?M-BM-^@M-bM-^\\M-^S'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cat -v binary, file', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
await cat([sampleBinary, sampleFile], tmp.openWrite(),
|
||||||
|
showNonPrinting: true);
|
||||||
|
var lines = await tmp.readAsLines();
|
||||||
|
expect(lines.first, startsWith('7z'));
|
||||||
|
});
|
||||||
|
|
||||||
test('cat -v', () async {
|
test('cat -v', () async {
|
||||||
final tmp = makeTmpFile();
|
final tmp = makeTmpFile();
|
||||||
await cat([sampleFile], tmp.openWrite(), showNonPrinting: true);
|
await cat([sampleFile], tmp.openWrite(), showNonPrinting: true);
|
||||||
|
@ -227,38 +228,38 @@ void main() {
|
||||||
expect(lines.last, endsWith('✓'), reason: 'end with checkmark');
|
expect(lines.last, endsWith('✓'), reason: 'end with checkmark');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cat -v binary, file', () async {
|
|
||||||
final tmp = makeTmpFile();
|
|
||||||
await cat([sampleBinary, sampleFile], tmp.openWrite(),
|
|
||||||
showNonPrinting: true);
|
|
||||||
var lines = await tmp.readAsLines();
|
|
||||||
expect(lines.first, startsWith('7z'));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('cat binary', () async {
|
test('cat binary', () async {
|
||||||
final tmp = makeTmpFile();
|
final tmp = makeTmpFile();
|
||||||
await cat([sampleBinary], tmp.openWrite());
|
await cat([sampleBinary], tmp.openWrite());
|
||||||
expect(tmp.readAsLines(), throwsException);
|
expect(tmp.readAsLines(), throwsException);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('empty stdin', () async {
|
test('cat file -', () async {
|
||||||
final tmp = makeTmpFile();
|
var tmp = makeTmpFile();
|
||||||
var result = await cat([], tmp.openWrite(), input: Stream.empty());
|
await cat([sampleFile, '-'], tmp.openWrite(),
|
||||||
expect(result.exitCode, exitSuccess, reason: 'cat() is successful');
|
input: mockStdin(text: '\n$sampleText'));
|
||||||
expect(result.messages.length, 0, reason: 'cat() has no message');
|
var lines = await tmp.readAsLines();
|
||||||
|
expect(lines.last, equals(sampleText));
|
||||||
result = await cat(['-'], tmp.openWrite(), input: Stream.empty());
|
|
||||||
expect(result.exitCode, exitSuccess, reason: 'cat(-) is successful');
|
|
||||||
expect(result.messages.length, 0, reason: 'cat(-) no message');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cat -', () async {
|
test('cat source', () async {
|
||||||
var tmp = makeTmpFile();
|
final tmp = makeTmpFile();
|
||||||
final result = await cat(['-'], tmp.openWrite(), input: mockStdin());
|
await cat([sourceFile], tmp.openWrite());
|
||||||
expect(result.exitCode, exitSuccess, reason: 'result code is successful');
|
final lines = await tmp.readAsLines();
|
||||||
expect(result.messages.length, 0, reason: 'no message');
|
expect(lines.isEmpty, false, reason: 'log is empty');
|
||||||
tmp = makeTmpFile();
|
expect(lines.first, startsWith('// Copyright (c)'),
|
||||||
expect(await tmp.exists(), false, reason: 'tmp file does not exists');
|
reason: 'has copyright');
|
||||||
|
expect(lines.last, equals('}'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('cat source, test', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
await cat([sourceFile, sampleFile], tmp.openWrite());
|
||||||
|
final lines = await tmp.readAsLines();
|
||||||
|
expect(lines.length, greaterThan(10), reason: 'more than 10 lines');
|
||||||
|
expect(lines.first, startsWith('// Copyright'),
|
||||||
|
reason: 'start with copyright');
|
||||||
|
expect(lines.last, endsWith('✓'), reason: 'end with checkmark');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cat()', () async {
|
test('cat()', () async {
|
||||||
|
@ -272,14 +273,6 @@ void main() {
|
||||||
expect(lines.length, 2, reason: "two lines");
|
expect(lines.length, 2, reason: "two lines");
|
||||||
});
|
});
|
||||||
|
|
||||||
test('cat file -', () async {
|
|
||||||
var tmp = makeTmpFile();
|
|
||||||
await cat([sampleFile, '-'], tmp.openWrite(),
|
|
||||||
input: mockStdin(text: '\n$sampleText'));
|
|
||||||
var lines = await tmp.readAsLines();
|
|
||||||
expect(lines.last, equals(sampleText));
|
|
||||||
});
|
|
||||||
|
|
||||||
test('closed stdout', () async {
|
test('closed stdout', () async {
|
||||||
final tmp = makeTmpFile();
|
final tmp = makeTmpFile();
|
||||||
final stream = tmp.openWrite();
|
final stream = tmp.openWrite();
|
||||||
|
@ -287,5 +280,21 @@ void main() {
|
||||||
final result = await cat([sampleFile], stream);
|
final result = await cat([sampleFile], stream);
|
||||||
expect(result.messages.first, contains("closed"));
|
expect(result.messages.first, contains("closed"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('empty stdin', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
var result = await cat([], tmp.openWrite(), input: Stream.empty());
|
||||||
|
expect(result.exitCode, exitSuccess, reason: 'cat() is successful');
|
||||||
|
expect(result.messages.length, 0, reason: 'cat() has no message');
|
||||||
|
result = await cat(['-'], tmp.openWrite(), input: Stream.empty());
|
||||||
|
expect(result.exitCode, exitSuccess, reason: 'cat(-) is successful');
|
||||||
|
expect(result.messages.length, 0, reason: 'cat(-) no message');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('invalid stdin', () async {
|
||||||
|
final tmp = makeTmpFile();
|
||||||
|
final result = await cat([], tmp.openWrite(), input: null);
|
||||||
|
expect(result.exitCode, exitSuccess);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue