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