• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Copyright (c) 2016 Fujitsu Ltd.
4# Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14# the GNU General Public License for more details.
15#
16# Test wc command with some basic options.
17#
18
19TCID=wc01.sh
20TST_TOTAL=12
21. test.sh
22
23setup()
24{
25	tst_check_cmds wc
26
27	tst_tmpdir
28
29	TST_CLEANUP="cleanup"
30
31	echo "hello world" > ltp_wc
32
33	echo "This is a test" >> ltp_wc
34}
35
36cleanup()
37{
38	tst_rmdir
39}
40
41wc_test()
42{
43	local wc_opt=$1
44	local wc_file=$2
45	local std_out=$3
46
47	local wc_cmd="wc $wc_opt $wc_file"
48
49	eval $wc_cmd > temp 2>&1
50	if [ $? -ne 0 ]; then
51		grep -q -E "unknown option|invalid option" temp
52		if [ $? -eq 0 ]; then
53			tst_resm TCONF "$wc_cmd not supported."
54		else
55			tst_resm TFAIL "$wc_cmd failed."
56		fi
57		return
58	fi
59
60	if [ $# -gt 1 ]; then
61		local act_out=`cat temp | awk '{printf $1}'`
62		if [ $act_out -ne $std_out ]; then
63			tst_resm TFAIL "$wc_cmd got mismatched data."
64			return
65		fi
66	fi
67
68	tst_resm TPASS "wc passed with $wc_opt option."
69}
70
71
72setup
73
74wc_test "-c" ltp_wc 27
75wc_test "--bytes" ltp_wc 27
76wc_test "-l" ltp_wc 2
77wc_test "--lines" ltp_wc 2
78wc_test "-L" ltp_wc 14
79wc_test "--max-line-length" ltp_wc 14
80wc_test "-w" ltp_wc 6
81wc_test "--words" ltp_wc 6
82wc_test "-m" ltp_wc 27
83wc_test "--chars" ltp_wc 27
84wc_test "--help"
85wc_test "--version"
86
87tst_exit
88