summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/cat.c6
-rwxr-xr-xtestsuite/cat.tests21
2 files changed, 24 insertions, 3 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c
index 5f02233..fb735f9 100644
--- a/coreutils/cat.c
+++ b/coreutils/cat.c
@@ -112,10 +112,10 @@ static int catv(unsigned opts, char **argv)
int retval = EXIT_SUCCESS;
int fd;
#if ENABLE_FEATURE_CATN
- unsigned lineno = 0;
- unsigned eol_char = (opts & (CAT_OPT_n|CAT_OPT_b)) ? '\n' : 0x100;
+ bool eol_seen = (opts & (CAT_OPT_n|CAT_OPT_b));
+ unsigned eol_char = (eol_seen ? '\n' : 0x100);
unsigned skip_num_on = (opts & CAT_OPT_b) ? '\n' : 0x100;
- bool eol_seen = 1;
+ unsigned lineno = 0;
#endif
BUILD_BUG_ON(CAT_OPT_e != VISIBLE_ENDLINE);
diff --git a/testsuite/cat.tests b/testsuite/cat.tests
new file mode 100755
index 0000000..404ebed
--- /dev/null
+++ b/testsuite/cat.tests
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+# Copyright 2018 by Denys Vlasenko <vda.linux@googlemail.com>
+# Licensed under GPLv2, see file LICENSE in this source tree.
+
+. ./testing.sh
+
+# testing "description" "command" "result" "infile" "stdin"
+testing 'cat -e' \
+ 'cat -e' \
+ 'foo$\n' \
+ '' \
+ 'foo\n'
+
+testing 'cat -v' \
+ 'cat -v' \
+ 'foo\n' \
+ '' \
+ 'foo\n'
+
+exit $FAILCOUNT