diff mbox series

[kvm-unit-tests,2/3] scripts: Save rematch before calling out of for_each_unittest

Message ID 20201014191444.136782-3-drjones@redhat.com (mailing list archive)
State New, archived
Headers show
Series A few miscellaneous fixes | expand

Commit Message

Andrew Jones Oct. 14, 2020, 7:14 p.m. UTC
If we don't save BASH_REMATCH before calling another function,
and that other function also uses [[...]], then we'll lose the
test.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 scripts/common.bash | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Thomas Huth Oct. 15, 2020, 8:22 a.m. UTC | #1
On 14/10/2020 21.14, Andrew Jones wrote:
> If we don't save BASH_REMATCH before calling another function,
> and that other function also uses [[...]], then we'll lose the
> test.
> 
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  scripts/common.bash | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/common.bash b/scripts/common.bash
> index a6044b7c6c35..7b983f7d6dd6 100644
> --- a/scripts/common.bash
> +++ b/scripts/common.bash
> @@ -13,15 +13,17 @@ function for_each_unittest()
>  	local check
>  	local accel
>  	local timeout
> +	local rematch
>  
>  	exec {fd}<"$unittests"
>  
>  	while read -r -u $fd line; do
>  		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
> +			rematch=${BASH_REMATCH[1]}
>  			if [ -n "${testname}" ]; then
>  				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
>  			fi
> -			testname=${BASH_REMATCH[1]}
> +			testname=$rematch
>  			smp=1
>  			kernel=""
>  			opts=""
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>
diff mbox series

Patch

diff --git a/scripts/common.bash b/scripts/common.bash
index a6044b7c6c35..7b983f7d6dd6 100644
--- a/scripts/common.bash
+++ b/scripts/common.bash
@@ -13,15 +13,17 @@  function for_each_unittest()
 	local check
 	local accel
 	local timeout
+	local rematch
 
 	exec {fd}<"$unittests"
 
 	while read -r -u $fd line; do
 		if [[ "$line" =~ ^\[(.*)\]$ ]]; then
+			rematch=${BASH_REMATCH[1]}
 			if [ -n "${testname}" ]; then
 				$(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
 			fi
-			testname=${BASH_REMATCH[1]}
+			testname=$rematch
 			smp=1
 			kernel=""
 			opts=""