Code cleanup.
This commit is contained in:
parent
7854faaa9c
commit
93fad0cb72
4 changed files with 25 additions and 23 deletions
|
@ -113,13 +113,13 @@ Future<ArgParser> setupArgsParser() async {
|
||||||
negatable: false,
|
negatable: false,
|
||||||
abbr: 's',
|
abbr: 's',
|
||||||
help: 'suppress repeated empty output lines');
|
help: 'suppress repeated empty output lines');
|
||||||
parser.addFlag(versionFlag,
|
|
||||||
negatable: false, help: 'output version information and exit');
|
|
||||||
parser.addFlag('ignored', negatable: false, hide: true, abbr: 'u');
|
parser.addFlag('ignored', negatable: false, hide: true, abbr: 'u');
|
||||||
parser.addFlag(showNonPrintingFlag,
|
parser.addFlag(showNonPrintingFlag,
|
||||||
negatable: false,
|
negatable: false,
|
||||||
abbr: 'v',
|
abbr: 'v',
|
||||||
help: 'use ^ and M- notation, except for LFD and TAB');
|
help: 'use ^ and M- notation, except for LFD and TAB');
|
||||||
|
parser.addFlag(versionFlag,
|
||||||
|
negatable: false, help: 'output version information and exit');
|
||||||
|
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,6 @@ class CatResult {
|
||||||
/// The list of errors.
|
/// The list of errors.
|
||||||
final List<CatError> errors = [];
|
final List<CatError> errors = [];
|
||||||
|
|
||||||
CatResult();
|
|
||||||
|
|
||||||
/// Returns `true` if the [exitCode] is [exitFailure].
|
/// Returns `true` if the [exitCode] is [exitFailure].
|
||||||
bool get isFailure => exitCode == exitFailure;
|
bool get isFailure => exitCode == exitFailure;
|
||||||
|
|
||||||
|
@ -47,11 +45,7 @@ class CatResult {
|
||||||
/// Adds an error [message] and [path].
|
/// Adds an error [message] and [path].
|
||||||
void addError(String message, {String? path}) {
|
void addError(String message, {String? path}) {
|
||||||
exitCode = exitFailure;
|
exitCode = exitFailure;
|
||||||
if (path != null && path.isNotEmpty) {
|
errors.add(CatError(message, path: path));
|
||||||
errors.add(CatError(message, path: path));
|
|
||||||
} else {
|
|
||||||
errors.add(CatError(message));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,11 +141,10 @@ Future<void> _copyStream(
|
||||||
squeeze = 0;
|
squeeze = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (showLineNumbers || numberNonBlank) {
|
if ((showLineNumbers || numberNonBlank) &&
|
||||||
if (!numberNonBlank || ch != _lineFeed) {
|
(!numberNonBlank || ch != _lineFeed)) {
|
||||||
buff.addAll('${++lastLine.lineNumber}'.padLeft(6).codeUnits);
|
buff.addAll('${++lastLine.lineNumber}'.padLeft(6).codeUnits);
|
||||||
buff.add(tab);
|
buff.add(tab);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastLine.lastChar = ch;
|
lastLine.lastChar = ch;
|
||||||
|
|
21
test.sh
21
test.sh
|
@ -5,18 +5,27 @@ TMPDCAT=/tmp/tmp-dcat
|
||||||
RED='\033[0;31m'
|
RED='\033[0;31m'
|
||||||
GREEN='\033[0;32m'
|
GREEN='\033[0;32m'
|
||||||
|
|
||||||
for o in -A -b -e -E -n -s -t -T -v
|
checkDiff () {
|
||||||
|
if ! $(cmp -s $TMPCAT $TMPDCAT);
|
||||||
|
then
|
||||||
|
echo -e "${RED}Test failed: $1" >&2
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
for o in '' -A -b -e -E -n -s -t -T -v '-Abs'
|
||||||
do
|
do
|
||||||
echo -e "Testing: cat $o"
|
echo -e "Testing: cat $o"
|
||||||
cat $o test/* > $TMPCAT
|
cat $o test/* > $TMPCAT
|
||||||
bin/dcat $o test/* > $TMPDCAT
|
bin/dcat $o test/* > $TMPDCAT
|
||||||
if ! $(diff -q $TMPCAT $TMPDCAT);
|
checkDiff "cat $o"
|
||||||
then
|
|
||||||
echo -e "${RED}Test failed: $o" >&2
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo -e "Testing: cat -"
|
||||||
|
echo "This is a test" | cat - test/* > $TMPCAT
|
||||||
|
echo "This is a test" | bin/dcat - test/* > $TMPDCAT
|
||||||
|
checkDiff "cat -"
|
||||||
|
|
||||||
rm -rf $TMPCAT $TMPDCAT
|
rm -rf $TMPCAT $TMPDCAT
|
||||||
|
|
||||||
echo -e "${GREEN}All tests passed."
|
echo -e "${GREEN}All tests passed."
|
||||||
|
|
|
@ -16,16 +16,16 @@ void main() {
|
||||||
const sourceFile = 'bin/dcat.dart';
|
const sourceFile = 'bin/dcat.dart';
|
||||||
|
|
||||||
int exitCode;
|
int exitCode;
|
||||||
final tempDir = Directory.systemTemp.createTempSync();
|
final tmpDir = Directory.systemTemp.createTempSync();
|
||||||
|
|
||||||
Stream<List<int>> mockStdin({String text = sampleText}) async* {
|
Stream<List<int>> mockStdin({String text = sampleText}) async* {
|
||||||
yield text.codeUnits;
|
yield text.codeUnits;
|
||||||
}
|
}
|
||||||
|
|
||||||
File makeTmpFile() =>
|
File makeTmpFile() =>
|
||||||
File("${tempDir.path}/tmp-${DateTime.now().millisecondsSinceEpoch}.txt");
|
File("${tmpDir.path}/${DateTime.now().millisecondsSinceEpoch}.txt");
|
||||||
|
|
||||||
tearDownAll(() => tempDir.delete(recursive: true));
|
tearDownAll(() => tmpDir.delete(recursive: true));
|
||||||
|
|
||||||
group('app', () {
|
group('app', () {
|
||||||
test('--help', () async {
|
test('--help', () async {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue