Added more test coverage.

This commit is contained in:
Erik C. Thauvin 2021-10-11 02:44:02 -07:00
parent 9397ebaa37
commit c43f8f5b27
6 changed files with 36 additions and 4 deletions

1
.gitignore vendored
View file

@ -51,6 +51,7 @@
/**/.idea/**/workspace.xml /**/.idea/**/workspace.xml
/**/.idea/sonarlint* /**/.idea/sonarlint*
/**/.idea_modules/ /**/.idea_modules/
/coverage/
Thumbs.db Thumbs.db
__pycache__ __pycache__
atlassian-ide-plugin.xml atlassian-ide-plugin.xml

View file

@ -63,9 +63,10 @@ Future<int> main(List<String> arguments) async {
try { try {
argResults = parser.parse(arguments); argResults = parser.parse(arguments);
} on FormatException catch (e) { } on FormatException catch (e) {
return await printError( exitCode = await printError(
"${e.message}\nTry '$appName --$helpFlag' for more information.", "${e.message}\nTry '$appName --$helpFlag' for more information.",
appName: appName); appName: appName);
return exitCode;
} }
if (argResults[helpFlag]) { if (argResults[helpFlag]) {

4
coverage.sh Executable file
View file

@ -0,0 +1,4 @@
dart run test --coverage=coverage
dart run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --packages=.packages --report-on=lib,bin
genhtml -o coverage coverage/lcov.info
open coverage/index.html 2> /dev/null

View file

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:dcat/dcat.dart'; import 'package:dcat/dcat.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
@ -21,11 +23,22 @@ void main() {
expect(exitCode, equals(exitSuccess)); expect(exitCode, equals(exitSuccess));
}); });
test('Test -a', () async {
expect(app.main(['-a']), completion(equals(1)));
exitCode = await app.main(['-a']);
expect(exitCode, equals(exitFailure));
});
test('Test directory', () async { test('Test directory', () async {
exitCode = await app.main(['bin']); exitCode = await app.main(['bin']);
expect(exitCode, equals(exitFailure)); expect(exitCode, equals(exitFailure));
}); });
test('Test binary', () async {
exitCode = await app.main(['test/test.7z']);
expect(exitCode, equals(exitFailure));
});
test('Test missing file', () async { test('Test missing file', () async {
exitCode = await app.main(['foo']); exitCode = await app.main(['foo']);
expect(exitCode, equals(exitFailure), reason: 'foo not found'); expect(exitCode, equals(exitFailure), reason: 'foo not found');
@ -116,13 +129,13 @@ void main() {
test('Test cat -A', () async { test('Test cat -A', () async {
await cat(['test/test.txt'], await cat(['test/test.txt'],
log: log, showNonPrinting: true, showEnds: true, showTabs: true); log: log, showNonPrinting: true, showEnds: true, showTabs: true);
expect(log.last, equals('^I^A^B^C^DM-^?\$')); expect(log.last, equals('^I^A^B^C^DM-)^?M-^@M-^?\$'));
}); });
test('Test cat -t', () async { test('Test cat -t', () async {
await cat(['test/test.txt'], await cat(['test/test.txt'],
log: log, showNonPrinting: true, showTabs: true); log: log, showNonPrinting: true, showTabs: true);
expect(log.last, equals('^I^A^B^C^DM-^?')); expect(log.last, equals('^I^A^B^C^DM-)^?M-^@M-^?'));
}); });
test('Test cat-Abs', () async { test('Test cat-Abs', () async {
@ -141,5 +154,18 @@ void main() {
} }
expect(blankLines, 2, reason: 'only 2 blank lines.'); expect(blankLines, 2, reason: 'only 2 blank lines.');
}); });
test('Test cat -v', () async {
await cat(['test/test.txt'],
log: log, showNonPrinting: true);
var hasTab = false;
for (final String line in log) {
if (line.contains('\t')) {
hasTab = true;
break;
}
}
expect(hasTab, true, reason: "has real tab");
});
}); });
} }

BIN
test/test.7z Normal file

Binary file not shown.

View file

@ -7,4 +7,4 @@ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor i
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
 ©€