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 19TST_CNT=12 20TST_SETUP=setup 21TST_TESTFUNC=do_test 22TST_NEEDS_TMPDIR=1 23TST_NEEDS_CMDS="wc" 24. tst_test.sh 25 26setup() 27{ 28 echo "hello world" > ltp_wc 29 30 echo "This is a test" >> ltp_wc 31} 32 33wc_test() 34{ 35 local wc_opt=$1 36 local wc_file=$2 37 local std_out=$3 38 39 local wc_cmd="wc $wc_opt $wc_file" 40 41 eval $wc_cmd > temp 2>&1 42 if [ $? -ne 0 ]; then 43 grep -q -E "unknown option|invalid option|unrecognized option" temp 44 if [ $? -eq 0 ]; then 45 tst_res TCONF "$wc_cmd not supported." 46 else 47 tst_res TFAIL "$wc_cmd failed." 48 fi 49 return 50 fi 51 52 if [ $# -gt 1 ]; then 53 local act_out=`cat temp | awk '{printf $1}'` 54 if [ $act_out -ne $std_out ]; then 55 tst_res TFAIL "$wc_cmd got mismatched data." 56 return 57 fi 58 fi 59 60 tst_res TPASS "wc passed with $wc_opt option." 61} 62 63do_test() 64{ 65 case $1 in 66 1) wc_test "-c" ltp_wc 27;; 67 2) wc_test "--bytes" ltp_wc 27;; 68 3) wc_test "-l" ltp_wc 2;; 69 4) wc_test "--lines" ltp_wc 2;; 70 5) wc_test "-L" ltp_wc 14;; 71 6) wc_test "--max-line-length" ltp_wc 14;; 72 7) wc_test "-w" ltp_wc 6;; 73 8) wc_test "--words" ltp_wc 6;; 74 9) wc_test "-m" ltp_wc 27;; 75 10) wc_test "--chars" ltp_wc 27;; 76 11) wc_test "--help";; 77 12) wc_test "--version";; 78 esac 79} 80 81tst_run 82