public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] commands/which: Added new testcase to test which(1).
@ 2015-11-26 11:55 Guangwen Feng
  2015-12-03 13:33 ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Guangwen Feng @ 2015-11-26 11:55 UTC (permalink / raw)
  To: ltp

Test which(1) command with some basic options.

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/commands                    |   1 +
 testcases/commands/which/Makefile   |  22 ++++++
 testcases/commands/which/which01.sh | 142 ++++++++++++++++++++++++++++++++++++
 3 files changed, 165 insertions(+)
 create mode 100644 testcases/commands/which/Makefile
 create mode 100755 testcases/commands/which/which01.sh

diff --git a/runtest/commands b/runtest/commands
index ab600dc..b05ae7b 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -39,3 +39,4 @@ mkfs01_msdos mkfs01.sh -f msdos
 mkfs01_vfat mkfs01.sh -f vfat
 mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
+which01 which01.sh
diff --git a/testcases/commands/which/Makefile b/testcases/commands/which/Makefile
new file mode 100644
index 0000000..d9b4d12
--- /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 0000000..1b6a44c
--- /dev/null
+++ b/testcases/commands/which/which01.sh
@@ -0,0 +1,142 @@
+#!/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_require_root
+
+	tst_check_cmds which
+
+	tst_tmpdir
+
+	TST_CLEANUP="cleanup"
+
+	touch programname
+	chmod +x programname
+	PATH=$PATH:.
+
+	mkdir bin
+	touch bin/programname
+	chmod +x bin/programname
+	PATH=$PATH:./bin
+
+	alias programname='programname -i'
+}
+
+cleanup()
+{
+	tst_rmdir
+}
+
+which_verify()
+{
+	local which_op=$1
+	local prog_name=$2
+
+	if [ -z "$which_op" ]; then
+		grep -q `pwd`/"$prog_name" temp
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+	elif [ "$which_op" = "--all" ] || [ "$which_op" = "-a" ]; then
+		grep -q `pwd`/"$prog_name" temp
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+		grep -q `pwd`/bin/"$prog_name" temp
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+	elif [ "$which_op" = "--read-alias" ] || [ "$which_op" = "-i" ]; then
+		grep -q "programname='programname -i'" temp
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+		grep -q `pwd`/"$prog_name" temp
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+	elif [ "$which_op" = "--skip-alias" ]; then
+		grep -q "programname='programname -i'" temp
+		if [ $? -eq 0 ]; then
+			return 1
+		fi
+		grep -q `pwd`/"$prog_name" temp
+		if [ $? -ne 0 ]; then
+			return 1
+		fi
+	fi
+}
+
+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 [ -n "$prog_name" ]; then
+		which_verify "$which_op" "$prog_name"
+		if [ $? -ne 0 ]; then
+			tst_resm TFAIL "'${which_cmd}' failed, not expected."
+			return
+		fi
+	fi
+
+	tst_resm TPASS "'${which_cmd}' passed."
+}
+
+setup
+
+which_test "" "programname"
+which_test "--all" "programname"
+which_test "-a" "programname"
+which_test "--read-alias" "programname"
+which_test "-i" "programname"
+
+alias which='which --read-alias'
+which_test "--skip-alias" "programname"
+
+which_test "--version"
+which_test "-v"
+which_test "-V"
+which_test "--help"
+
+tst_exit
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] commands/which: Added new testcase to test which(1).
  2015-11-26 11:55 [LTP] [PATCH] commands/which: Added new testcase to test which(1) Guangwen Feng
@ 2015-12-03 13:33 ` Cyril Hrubis
  2015-12-04  7:50   ` Guangwen Feng
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2015-12-03 13:33 UTC (permalink / raw)
  To: ltp

Hi!
> +setup()
> +{
> +	tst_require_root

Do we really need root for the test?

> +	tst_check_cmds which
> +
> +	tst_tmpdir
> +
> +	TST_CLEANUP="cleanup"
> +
> +	touch programname
> +	chmod +x programname
> +	PATH=$PATH:.
> +
> +	mkdir bin
> +	touch bin/programname
> +	chmod +x bin/programname
> +	PATH=$PATH:./bin
> +
> +	alias programname='programname -i'
> +}
> +
> +cleanup()
> +{
> +	tst_rmdir
> +}
> +
> +which_verify()
> +{
> +	local which_op=$1
> +	local prog_name=$2
> +
> +	if [ -z "$which_op" ]; then
> +		grep -q `pwd`/"$prog_name" temp
> +		if [ $? -ne 0 ]; then
> +			return 1
> +		fi
> +	elif [ "$which_op" = "--all" ] || [ "$which_op" = "-a" ]; then
> +		grep -q `pwd`/"$prog_name" temp
> +		if [ $? -ne 0 ]; then
> +			return 1
> +		fi
> +		grep -q `pwd`/bin/"$prog_name" temp
> +		if [ $? -ne 0 ]; then
> +			return 1
> +		fi
> +	elif [ "$which_op" = "--read-alias" ] || [ "$which_op" = "-i" ]; then
> +		grep -q "programname='programname -i'" temp
> +		if [ $? -ne 0 ]; then
> +			return 1
> +		fi
> +		grep -q `pwd`/"$prog_name" temp
> +		if [ $? -ne 0 ]; then
> +			return 1
> +		fi
> +	elif [ "$which_op" = "--skip-alias" ]; then
> +		grep -q "programname='programname -i'" temp
> +		if [ $? -eq 0 ]; then
> +			return 1
> +		fi
> +		grep -q `pwd`/"$prog_name" temp
> +		if [ $? -ne 0 ]; then
> +			return 1
> +		fi
> +	fi

Again, why don't we rather pass the expected paths as the parameters to
the which_test function? For example:

which_test "-a" "programname" "$PWD/programname" $PWD/bin/programname"

Then we will do shift twice in the which_test() and loop over the rest
of the $@ doing grep in the temp for each iteration.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH] commands/which: Added new testcase to test which(1).
  2015-12-03 13:33 ` Cyril Hrubis
@ 2015-12-04  7:50   ` Guangwen Feng
  2015-12-04  9:12     ` [LTP] [PATCH v2] " Guangwen Feng
  0 siblings, 1 reply; 7+ messages in thread
From: Guangwen Feng @ 2015-12-04  7:50 UTC (permalink / raw)
  To: ltp

Hi!
Thanks for your review!

On 2015/12/03 21:33, Cyril Hrubis wrote:
> Hi!
>> +setup()
>> +{
>> +	tst_require_root
> 
> Do we really need root for the test?
> 

It's not necessary indeed, I'll drop it.

>> +	tst_check_cmds which
>> +
>> +	tst_tmpdir
>> +
>> +	TST_CLEANUP="cleanup"
>> +
>> +	touch programname
>> +	chmod +x programname
>> +	PATH=$PATH:.
>> +
>> +	mkdir bin
>> +	touch bin/programname
>> +	chmod +x bin/programname
>> +	PATH=$PATH:./bin
>> +
>> +	alias programname='programname -i'
>> +}
>> +
>> +cleanup()
>> +{
>> +	tst_rmdir
>> +}
>> +
>> +which_verify()
>> +{
>> +	local which_op=$1
>> +	local prog_name=$2
>> +
>> +	if [ -z "$which_op" ]; then
>> +		grep -q `pwd`/"$prog_name" temp
>> +		if [ $? -ne 0 ]; then
>> +			return 1
>> +		fi
>> +	elif [ "$which_op" = "--all" ] || [ "$which_op" = "-a" ]; then
>> +		grep -q `pwd`/"$prog_name" temp
>> +		if [ $? -ne 0 ]; then
>> +			return 1
>> +		fi
>> +		grep -q `pwd`/bin/"$prog_name" temp
>> +		if [ $? -ne 0 ]; then
>> +			return 1
>> +		fi
>> +	elif [ "$which_op" = "--read-alias" ] || [ "$which_op" = "-i" ]; then
>> +		grep -q "programname='programname -i'" temp
>> +		if [ $? -ne 0 ]; then
>> +			return 1
>> +		fi
>> +		grep -q `pwd`/"$prog_name" temp
>> +		if [ $? -ne 0 ]; then
>> +			return 1
>> +		fi
>> +	elif [ "$which_op" = "--skip-alias" ]; then
>> +		grep -q "programname='programname -i'" temp
>> +		if [ $? -eq 0 ]; then
>> +			return 1
>> +		fi
>> +		grep -q `pwd`/"$prog_name" temp
>> +		if [ $? -ne 0 ]; then
>> +			return 1
>> +		fi
>> +	fi
> 
> Again, why don't we rather pass the expected paths as the parameters to
> the which_test function? For example:
> 
> which_test "-a" "programname" "$PWD/programname" $PWD/bin/programname"
> 
> Then we will do shift twice in the which_test() and loop over the rest
> of the $@ doing grep in the temp for each iteration.
> 

Yeah, it sounds better, I'll rewrite this according to your suggestion.

Best Regards,
Guangwen Feng



^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2] commands/which: Added new testcase to test which(1).
  2015-12-04  7:50   ` Guangwen Feng
@ 2015-12-04  9:12     ` Guangwen Feng
  2015-12-15 13:47       ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Guangwen Feng @ 2015-12-04  9:12 UTC (permalink / raw)
  To: ltp

Test which(1) command with some basic options.

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/commands                    |   1 +
 testcases/commands/which/Makefile   |  22 +++++++
 testcases/commands/which/which01.sh | 121 ++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 testcases/commands/which/Makefile
 create mode 100755 testcases/commands/which/which01.sh

diff --git a/runtest/commands b/runtest/commands
index ab600dc..b05ae7b 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -39,3 +39,4 @@ mkfs01_msdos mkfs01.sh -f msdos
 mkfs01_vfat mkfs01.sh -f vfat
 mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
+which01 which01.sh
diff --git a/testcases/commands/which/Makefile b/testcases/commands/which/Makefile
new file mode 100644
index 0000000..d9b4d12
--- /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 0000000..9c8b7af
--- /dev/null
+++ b/testcases/commands/which/which01.sh
@@ -0,0 +1,121 @@
+#!/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()
+{
+	local which_op=$1
+
+	shift
+	until [ -z "$1" ]
+	do
+		grep -q "$1" temp
+		if [ $? -ne 0 ]; then
+			if [ "$which_op" = "--skip-alias" ] && \
+				[ "$1" = "pname='pname -i'" ]; then
+				shift
+				continue
+			fi
+			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 [ -n "$prog_name" ]; then
+		shift 2
+		which_verify "$which_op" "$@"
+		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" "pname='pname -i'" "$PWD/pname"
+
+which_test "--version"
+which_test "-v"
+which_test "-V"
+which_test "--help"
+
+tst_exit
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v2] commands/which: Added new testcase to test which(1).
  2015-12-04  9:12     ` [LTP] [PATCH v2] " Guangwen Feng
@ 2015-12-15 13:47       ` Cyril Hrubis
  2015-12-16  7:01         ` [LTP] [PATCH v3] " Guangwen Feng
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2015-12-15 13:47 UTC (permalink / raw)
  To: ltp

Hi!
> +		grep -q "$1" temp
> +		if [ $? -ne 0 ]; then
> +			if [ "$which_op" = "--skip-alias" ] && \
> +				[ "$1" = "pname='pname -i'" ]; then
> +				shift
> +				continue
> +			fi

                              Hmm why don't we remove the
			      "pname='pname -i'" from the parameters?

			      If we silently ignore the failure it's the
			      same as if we haven't checked it in the
			      first place...

Also it would be good to be a bit more verbose here. I.e. do:

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 [ -n "$prog_name" ]; then

I would rather do 'if [ $# -gt 2 ]; then' but that is very minor.

> +		shift 2
> +		which_verify "$which_op" "$@"
> +		if [ $? -ne 0 ]; then
> +			tst_resm TFAIL "'${which_cmd}' failed, not expected."
> +			return
> +		fi
> +	fi
> +
> +	tst_resm TPASS "'${which_cmd}' passed."
> +}

The rest looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v3] commands/which: Added new testcase to test which(1).
  2015-12-15 13:47       ` Cyril Hrubis
@ 2015-12-16  7:01         ` Guangwen Feng
  2016-01-05 15:27           ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Guangwen Feng @ 2015-12-16  7:01 UTC (permalink / raw)
  To: ltp

Test which(1) command with some basic options.

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/commands                    |   1 +
 testcases/commands/which/Makefile   |  22 +++++++
 testcases/commands/which/which01.sh | 119 ++++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+)
 create mode 100644 testcases/commands/which/Makefile
 create mode 100755 testcases/commands/which/which01.sh

diff --git a/runtest/commands b/runtest/commands
index ab600dc..b05ae7b 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -39,3 +39,4 @@ mkfs01_msdos mkfs01.sh -f msdos
 mkfs01_vfat mkfs01.sh -f vfat
 mkfs01_ntfs mkfs01.sh -f ntfs
 mkswap01 mkswap01.sh
+which01 which01.sh
diff --git a/testcases/commands/which/Makefile b/testcases/commands/which/Makefile
new file mode 100644
index 0000000..d9b4d12
--- /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 0000000..a47b74a
--- /dev/null
+++ b/testcases/commands/which/which01.sh
@@ -0,0 +1,119 @@
+#!/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()
+{
+	local which_op=$1
+
+	shift
+	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 "$which_op" "$@"
+		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
-- 
1.8.4.2




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [LTP] [PATCH v3] commands/which: Added new testcase to test which(1).
  2015-12-16  7:01         ` [LTP] [PATCH v3] " Guangwen Feng
@ 2016-01-05 15:27           ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2016-01-05 15:27 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with this change:

@@ -47,9 +47,6 @@ cleanup()
 
 which_verify()
 {
-       local which_op=$1
-
-       shift
        until [ -z "$1" ]
        do
                grep -q "$1" temp
@@ -90,7 +87,7 @@ which_test()
 
        if [ $# -gt 2 ]; then
                shift 2
-               which_verify "$which_op" "$@"
+               which_verify "$@"
                if [ $? -ne 0 ]; then
                        tst_resm TFAIL "'${which_cmd}' failed, not expected."
                        return

Since the $which_op was unused in the fucntion.

Thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-01-05 15:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-26 11:55 [LTP] [PATCH] commands/which: Added new testcase to test which(1) Guangwen Feng
2015-12-03 13:33 ` Cyril Hrubis
2015-12-04  7:50   ` Guangwen Feng
2015-12-04  9:12     ` [LTP] [PATCH v2] " Guangwen Feng
2015-12-15 13:47       ` Cyril Hrubis
2015-12-16  7:01         ` [LTP] [PATCH v3] " Guangwen Feng
2016-01-05 15:27           ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox