From e95bb78591590ef4c72fbfbd9247d04473e3d341 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 2 Feb 2023 21:12:27 -0600 Subject: [PATCH] Modernize head tests. --- tests/head.test | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/tests/head.test b/tests/head.test index 4e4c01bd..729dfa7e 100755 --- a/tests/head.test +++ b/tests/head.test @@ -4,30 +4,31 @@ #testing "name" "command" "result" "infile" "stdin" -testing "head, stdin" "head -n 1 && echo yes" "one\nyes\n" "" "one\ntwo" -testing "head, stdin via -" "head -n 1 - && echo yes" "one\nyes\n" "" "one\ntwo" -testing "head, file" "head input -n 1 && echo yes" "one\nyes\n" "one\ntwo" "" -testing "-number" "head -2 input && echo yes" "one\ntwo\nyes\n" \ +testcmd "stdin" "-n 1 && echo yes" "one\nyes\n" "" "one\ntwo" +testcmd "stdin via -" "-n 1 - && echo yes" "one\nyes\n" "" "one\ntwo" +testcmd "file" "input -n 1 && echo yes" "one\nyes\n" "one\ntwo" "" +testcmd "-number" "-2 input && echo yes" "one\ntwo\nyes\n" \ "one\ntwo\nthree\nfour" "" -testing "head, default lines" "head" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12" +testcmd "default lines" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" "" "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12" # coreutils & busybox name stdin as "standard input", toybox uses "-" -testing "-v file" "head -v -n 1 input" "==> input <==\none\n" "one\ntwo\n" "" -testing "-v stdin" "head -v -n 1 | sed 's/==> standard input <==/==> - <==/'" \ +testcmd "-v file" "-v -n 1 input" "==> input <==\none\n" "one\ntwo\n" "" +testcmd "-v stdin" "-v -n 1 | sed 's/standard input/-/'" \ "==> - <==\none\n" "" "one\ntwo\n" -testing "file and stdin" "head -n 1 input - | sed 's/==> standard input <==/==> - <==/'" \ +testcmd "file and stdin" "-n 1 input - | sed 's/standard input/-/'" \ "==> input <==\none\n\n==> - <==\nfoo\n" "one\ntwo\n" "foo\nbar\n" echo "foo bar baz" > file1 -testing "head, multiple files" "head -n 2 input file1" "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" "" -testing "-q, multiple files" "head -q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \ +testcmd "multiple files" "-n 2 input file1" \ + "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" "" +testcmd "-q, multiple files" "-q -n 2 input file1" "one\ntwo\nfoo\nbar\n" \ "one\ntwo\nthree\n" "" rm file1 -testing "-c 3" "head -c 3" "one" "" "one\ntwo" -testing "-c bigger than input" "head -c 3" "a" "" "a" -testing "-c 3 -n 1" "head -c 3 -n 1" "one\n" "" "one\ntwo" -testing "-n 1 -c 3" "head -n 1 -c 3" "one" "" "one\ntwo" +testcmd "-c 3" "-c 3" "one" "" "one\ntwo" +testcmd "-c bigger than input" "-c 3" "a" "" "a" +testcmd "-c 3 -n 1" "-c 3 -n 1" "one\n" "" "one\ntwo" +testcmd "-n 1 -c 3" "-n 1 -c 3" "one" "" "one\ntwo" -- 2.39.2