diff --git a/.gitignore b/.gitignore index 57fd0ad..741e785 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ /**/.idea/**/workspace.xml /**/.idea/sonarlint* /**/.idea_modules/ +/coverage/ Thumbs.db __pycache__ atlassian-ide-plugin.xml diff --git a/bin/dcat.dart b/bin/dcat.dart index 33dcac0..5a74b40 100644 --- a/bin/dcat.dart +++ b/bin/dcat.dart @@ -63,9 +63,10 @@ Future main(List arguments) async { try { argResults = parser.parse(arguments); } on FormatException catch (e) { - return await printError( + exitCode = await printError( "${e.message}\nTry '$appName --$helpFlag' for more information.", appName: appName); + return exitCode; } if (argResults[helpFlag]) { diff --git a/coverage.sh b/coverage.sh new file mode 100755 index 0000000..d6ec905 --- /dev/null +++ b/coverage.sh @@ -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 diff --git a/test/dcat_test.dart b/test/dcat_test.dart index 1feef14..1c1abc2 100644 --- a/test/dcat_test.dart +++ b/test/dcat_test.dart @@ -1,3 +1,5 @@ +import 'dart:io'; + import 'package:dcat/dcat.dart'; import 'package:test/test.dart'; @@ -21,11 +23,22 @@ void main() { 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 { exitCode = await app.main(['bin']); expect(exitCode, equals(exitFailure)); }); + test('Test binary', () async { + exitCode = await app.main(['test/test.7z']); + expect(exitCode, equals(exitFailure)); + }); + test('Test missing file', () async { exitCode = await app.main(['foo']); expect(exitCode, equals(exitFailure), reason: 'foo not found'); @@ -116,13 +129,13 @@ void main() { test('Test cat -A', () async { await cat(['test/test.txt'], 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 { await cat(['test/test.txt'], 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 { @@ -141,5 +154,18 @@ void main() { } 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"); + }); }); } diff --git a/test/test.7z b/test/test.7z new file mode 100644 index 0000000..816a01a Binary files /dev/null and b/test/test.7z differ diff --git a/test/test.txt b/test/test.txt index 5abf6c3..752fec2 100644 --- a/test/test.txt +++ b/test/test.txt @@ -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. - ✓ + ©€✓ \ No newline at end of file