Felix Janda | add77b1 | 2012-10-29 16:55:08 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | [ -f testing.sh ] && . testing.sh |
| 4 | |
| 5 | #testing "name" "command" "result" "infile" "stdin" |
| 6 | |
| 7 | cat >file1 <<EOF |
| 8 | some words . |
| 9 | |
| 10 | some |
| 11 | lines |
| 12 | EOF |
| 13 | |
| 14 | testing "wc" "wc >/dev/null && echo yes" "yes\n" "" "" |
Rob Landley | 20f67f1 | 2016-06-30 10:39:41 -0500 | [diff] [blame] | 15 | testing "empty file" "wc" " 0 0 0\n" "" "" |
| 16 | testing "standard input" "wc" " 1 3 5\n" "" "a b\nc" |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 17 | testing "-c" "wc -c file1" "26 file1\n" "" "" |
| 18 | testing "-l" "wc -l file1" "4 file1\n" "" "" |
| 19 | testing "-w" "wc -w file1" "5 file1\n" "" "" |
Rob Landley | 20f67f1 | 2016-06-30 10:39:41 -0500 | [diff] [blame] | 20 | NOSPACE=1 testing "format" "wc file1" " 4 5 26 file1\n" "" "" |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 21 | testing "multiple files" "wc input - file1" \ |
Rob Landley | 20f67f1 | 2016-06-30 10:39:41 -0500 | [diff] [blame] | 22 | " 1 2 3 input\n 0 2 3 -\n 4 5 26 file1\n 5 9 32 total\n" "a\nb" "a b" |
Felix Janda | 250e005 | 2012-11-21 20:38:29 +0100 | [diff] [blame] | 23 | |
Felix Janda | abb8ca2 | 2012-11-08 11:19:07 -0600 | [diff] [blame] | 24 | #Tests for wc -m |
| 25 | if printf "%s" "$LANG" | grep -q UTF-8 |
| 26 | then |
| 27 | |
| 28 | printf " " > file1 |
| 29 | for i in $(seq 1 8192) |
| 30 | do |
| 31 | printf "ü" >> file1 |
| 32 | done |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 33 | testing "-m" "wc -m file1" "8193 file1\n" "" "" |
Rob Landley | 20f67f1 | 2016-06-30 10:39:41 -0500 | [diff] [blame] | 34 | testing "-m 2" 'cat "$FILES/utf8/test2.txt" | wc -m' "169\n" "" "" |
Felix Janda | abb8ca2 | 2012-11-08 11:19:07 -0600 | [diff] [blame] | 35 | printf " " > file1 |
| 36 | for i in $(seq 1 8192) |
| 37 | do |
| 38 | printf "ü" >> file1 |
| 39 | done |
Rob Landley | 336c44a | 2016-03-02 15:20:04 -0600 | [diff] [blame] | 40 | testing "-m (invalid chars)" "wc -m file1" "8193 file1\n" "" "" |
Rob Landley | 20f67f1 | 2016-06-30 10:39:41 -0500 | [diff] [blame] | 41 | NOSPACE=1 testing "-mlw" "wc -mlw input" " 1 2 11 input\n" "hello, 世界!\n" "" |
Felix Janda | abb8ca2 | 2012-11-08 11:19:07 -0600 | [diff] [blame] | 42 | |
| 43 | else |
| 44 | printf "skipping tests for wc -m" |
| 45 | fi |
| 46 | |
Felix Janda | add77b1 | 2012-10-29 16:55:08 -0500 | [diff] [blame] | 47 | rm file1 |