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