blob: d227b9c0b46ed01e22f464de7dd6050feb51cdbe [file] [log] [blame]
Felix Jandaadd77b12012-10-29 16:55:08 -05001#!/bin/bash
2
3[ -f testing.sh ] && . testing.sh
4
5#testing "name" "command" "result" "infile" "stdin"
6
7cat >file1 <<EOF
8some words .
9
10some
11lines
12EOF
13
14testing "wc" "wc >/dev/null && echo yes" "yes\n" "" ""
Rob Landley20f67f12016-06-30 10:39:41 -050015testing "empty file" "wc" " 0 0 0\n" "" ""
16testing "standard input" "wc" " 1 3 5\n" "" "a b\nc"
Rob Landley336c44a2016-03-02 15:20:04 -060017testing "-c" "wc -c file1" "26 file1\n" "" ""
18testing "-l" "wc -l file1" "4 file1\n" "" ""
19testing "-w" "wc -w file1" "5 file1\n" "" ""
Rob Landley20f67f12016-06-30 10:39:41 -050020NOSPACE=1 testing "format" "wc file1" " 4 5 26 file1\n" "" ""
Rob Landley336c44a2016-03-02 15:20:04 -060021testing "multiple files" "wc input - file1" \
Rob Landley20f67f12016-06-30 10:39:41 -050022 " 1 2 3 input\n 0 2 3 -\n 4 5 26 file1\n 5 9 32 total\n" "a\nb" "a b"
Felix Janda250e0052012-11-21 20:38:29 +010023
Felix Jandaabb8ca22012-11-08 11:19:07 -060024#Tests for wc -m
25if printf "%s" "$LANG" | grep -q UTF-8
26then
27
28printf " " > file1
29for i in $(seq 1 8192)
30do
31 printf "ü" >> file1
32done
Rob Landley336c44a2016-03-02 15:20:04 -060033testing "-m" "wc -m file1" "8193 file1\n" "" ""
Rob Landley20f67f12016-06-30 10:39:41 -050034testing "-m 2" 'cat "$FILES/utf8/test2.txt" | wc -m' "169\n" "" ""
Felix Jandaabb8ca22012-11-08 11:19:07 -060035printf " " > file1
36for i in $(seq 1 8192)
37do
38 printf "ü" >> file1
39done
Rob Landley336c44a2016-03-02 15:20:04 -060040testing "-m (invalid chars)" "wc -m file1" "8193 file1\n" "" ""
Rob Landley20f67f12016-06-30 10:39:41 -050041NOSPACE=1 testing "-mlw" "wc -mlw input" " 1 2 11 input\n" "hello, 世界!\n" ""
Felix Jandaabb8ca22012-11-08 11:19:07 -060042
43else
44printf "skipping tests for wc -m"
45fi
46
Felix Jandaadd77b12012-10-29 16:55:08 -050047rm file1