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,
|
||||
abbr: 's',
|
||||
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(showNonPrintingFlag,
|
||||
negatable: false,
|
||||
abbr: 'v',
|
||||
help: 'use ^ and M- notation, except for LFD and TAB');
|
||||
parser.addFlag(versionFlag,
|
||||
negatable: false, help: 'output version information and exit');
|
||||
|
||||
return parser;
|
||||
}
|
||||
|
|
|
@ -36,8 +36,6 @@ class CatResult {
|
|||
/// The list of errors.
|
||||
final List<CatError> errors = [];
|
||||
|
||||
CatResult();
|
||||
|
||||
/// Returns `true` if the [exitCode] is [exitFailure].
|
||||
bool get isFailure => exitCode == exitFailure;
|
||||
|
||||
|
@ -47,11 +45,7 @@ class CatResult {
|
|||
/// Adds an error [message] and [path].
|
||||
void addError(String message, {String? path}) {
|
||||
exitCode = exitFailure;
|
||||
if (path != null && path.isNotEmpty) {
|
||||
errors.add(CatError(message, path: path));
|
||||
} else {
|
||||
errors.add(CatError(message));
|
||||
}
|
||||
errors.add(CatError(message, path: path));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,11 +141,10 @@ Future<void> _copyStream(
|
|||
squeeze = 0;
|
||||
}
|
||||
}
|
||||
if (showLineNumbers || numberNonBlank) {
|
||||
if (!numberNonBlank || ch != _lineFeed) {
|
||||
buff.addAll('${++lastLine.lineNumber}'.padLeft(6).codeUnits);
|
||||
buff.add(tab);
|
||||
}
|
||||
if ((showLineNumbers || numberNonBlank) &&
|
||||
(!numberNonBlank || ch != _lineFeed)) {
|
||||
buff.addAll('${++lastLine.lineNumber}'.padLeft(6).codeUnits);
|
||||
buff.add(tab);
|
||||
}
|
||||
}
|
||||
lastLine.lastChar = ch;
|
||||
|
|
21
test.sh
21
test.sh
|
@ -5,18 +5,27 @@ TMPDCAT=/tmp/tmp-dcat
|
|||
RED='\033[0;31m'
|
||||
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
|
||||
echo -e "Testing: cat $o"
|
||||
cat $o test/* > $TMPCAT
|
||||
bin/dcat $o test/* > $TMPDCAT
|
||||
if ! $(diff -q $TMPCAT $TMPDCAT);
|
||||
then
|
||||
echo -e "${RED}Test failed: $o" >&2
|
||||
exit
|
||||
fi
|
||||
checkDiff "cat $o"
|
||||
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
|
||||
|
||||
echo -e "${GREEN}All tests passed."
|
||||
|
|
|
@ -16,16 +16,16 @@ void main() {
|
|||
const sourceFile = 'bin/dcat.dart';
|
||||
|
||||
int exitCode;
|
||||
final tempDir = Directory.systemTemp.createTempSync();
|
||||
final tmpDir = Directory.systemTemp.createTempSync();
|
||||
|
||||
Stream<List<int>> mockStdin({String text = sampleText}) async* {
|
||||
yield text.codeUnits;
|
||||
}
|
||||
|
||||
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', () {
|
||||
test('--help', () async {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue