comparison scripts/test/head.test @ 451:f4cc0a2aa440

Add tests for head This exposed one issue in head.c -- printf was not flushing and file names could appear after file contents instead of before. The issue is fixed by calling xflush after xprintf.
author Timothy Elliott <tle@holymonkey.com>
date Fri, 10 Feb 2012 21:59:57 -0800
parents
children
comparison
equal deleted inserted replaced
450:d8ff3b0980cf 451:f4cc0a2aa440
1 #!/bin/bash
2
3 [ -f testing.sh ] && . testing.sh
4
5 #testing "name" "command" "result" "infile" "stdin"
6
7 testing "head, stdin" "head -n 1 && echo yes" "one\nyes\n" "" "one\ntwo"
8 testing "head, stdin via -" "head -n 1 - && echo yes" "one\nyes\n" "" "one\ntwo"
9 testing "head, file" "head input -n 1 && echo yes" "one\nyes\n" "one\ntwo" ""
10 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"
11
12 echo "foo
13 bar
14 baz" > file1
15 testing "head, multiple files" "head -n 2 input file1" "==> input <==\none\ntwo\n\n==> file1 <==\nfoo\nbar\n" "one\ntwo\nthree\n" ""
16 rm file1
17