diff options
author | Guangwen Feng <fenggw-fnst@cn.fujitsu.com> | 2015-12-16 15:01:13 +0800 |
---|---|---|
committer | Cyril Hrubis <chrubis@suse.cz> | 2016-01-05 16:26:37 +0100 |
commit | 7bf1017797f08719dc43c8e762a948078e84af2b (patch) | |
tree | f590f0ba3b82d58c2a11e3e86889f4322c7b9492 /testcases/commands | |
parent | 6bb766ebafa6bab9a9d288889b627fae68b7c34d (diff) |
commands/which: Added new testcase to test which(1).
Test which(1) command with some basic options.
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Diffstat (limited to 'testcases/commands')
-rw-r--r-- | testcases/commands/which/Makefile | 22 | ||||
-rwxr-xr-x | testcases/commands/which/which01.sh | 116 |
2 files changed, 138 insertions, 0 deletions
diff --git a/testcases/commands/which/Makefile b/testcases/commands/which/Makefile new file mode 100644 index 000000000..d9b4d1299 --- /dev/null +++ b/testcases/commands/which/Makefile @@ -0,0 +1,22 @@ +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/env_pre.mk + +INSTALL_TARGETS := which01.sh + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/commands/which/which01.sh b/testcases/commands/which/which01.sh new file mode 100755 index 000000000..5e2841155 --- /dev/null +++ b/testcases/commands/which/which01.sh @@ -0,0 +1,116 @@ +#!/bin/sh +# +# Copyright (c) 2015 Fujitsu Ltd. +# Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# Test which command with some basic options. +# + +TCID=which01 +TST_TOTAL=10 +. test.sh + +setup() +{ + tst_check_cmds which + + tst_tmpdir + + TST_CLEANUP="cleanup" + + touch pname + chmod +x pname + PATH=$PATH:. + + mkdir bin + touch bin/pname + chmod +x bin/pname + PATH=$PATH:./bin + + alias pname='pname -i' +} + +cleanup() +{ + tst_rmdir +} + +which_verify() +{ + until [ -z "$1" ] + do + grep -q "$1" temp + if [ $? -ne 0 ]; then + echo "'$1' not found in:" + cat temp + echo + return 1 + fi + shift + done +} + +which_test() +{ + local which_op=$1 + local prog_name=$2 + + local which_cmd="which $which_op $prog_name" + + if [ "$which_op" = "--read-alias" ] || [ "$which_op" = "-i" ] || \ + [ "$which_op" = "--skip-alias" ]; then + which_cmd="alias | $which_cmd" + fi + + eval ${which_cmd} >temp 2>&1 + if [ $? -ne 0 ]; then + grep -q -E "unknown option|invalid option|Usage" temp + if [ $? -eq 0 ]; then + tst_resm TCONF "'${which_cmd}' not supported." + return + fi + + tst_resm TFAIL "'${which_cmd}' failed." + cat temp + return + fi + + if [ $# -gt 2 ]; then + shift 2 + which_verify "$@" + if [ $? -ne 0 ]; then + tst_resm TFAIL "'${which_cmd}' failed, not expected." + return + fi + fi + + tst_resm TPASS "'${which_cmd}' passed." +} + +setup + +which_test "" "pname" "$PWD/pname" +which_test "--all" "pname" "$PWD/bin/pname" "$PWD/pname" +which_test "-a" "pname" "$PWD/bin/pname" "$PWD/pname" +which_test "--read-alias" "pname" "pname='pname -i'" "$PWD/pname" +which_test "-i" "pname" "pname='pname -i'" "$PWD/pname" + +alias which='which --read-alias' +which_test "--skip-alias" "pname" "$PWD/pname" + +which_test "--version" +which_test "-v" +which_test "-V" +which_test "--help" + +tst_exit |