diff mbox series

[1/1] utils/test-pkg: set the return code for fail

Message ID 20191010085120.32730-1-heiko.thiery@gmail.com
State Changes Requested
Headers show
Series [1/1] utils/test-pkg: set the return code for fail | expand

Commit Message

Heiko Thiery Oct. 10, 2019, 8:51 a.m. UTC
From: Heiko Thiery <heiko.thiery@kontron.com>

Add an option (-e) to exit the script with an error if a build
or the legal-info check fails.

Signed-off-by: Heiko Thiery <heiko.thiery@kontron.com>
---
 utils/test-pkg | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Heiko Thiery Oct. 10, 2019, 8:53 a.m. UTC | #1
> Add an option (-e) to exit the script with an error if a build
> or the legal-info check fails.
>
> Signed-off-by: Heiko Thiery <heiko.thiery@kontron.com>
> ---
>  utils/test-pkg | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/utils/test-pkg b/utils/test-pkg
> index f3b34d5d0d..5e440b12f6 100755
> --- a/utils/test-pkg
> +++ b/utils/test-pkg
> @@ -138,6 +138,10 @@ main() {
>
>      printf "%d builds, %d skipped, %d build failed, %d legal-info failed\n" \
>          ${nb} ${nb_skip} ${nb_fail} ${nb_legal}
> +
> +    if [ ${nb_fail} -ne 0 -o ${nb_legal} -ne 0 ]; then
> +        return 1
> +    fi
>  }
>
>  build_one() {
> @@ -264,4 +268,7 @@ _EOF_
>  }
>
>  my_name="${0##*/}"
> -main "${@}"
> +main "${@}" && ret=0 || ret=${?}
> +if [ ${ret} -ne 0 ]; then
> +    exit 1
> +fi
> --
> 2.20.1
>

forgot the v2 prefix
Yann E. MORIN Oct. 10, 2019, 8:58 a.m. UTC | #2
Heiko, All,

On 2019-10-10 10:51 +0200, heiko.thiery@gmail.com spake thusly:
> From: Heiko Thiery <heiko.thiery@kontron.com>
> 
> Add an option (-e) to exit the script with an error if a build
> or the legal-info check fails.

This commit log should be updated now that the option has been removed.

> Signed-off-by: Heiko Thiery <heiko.thiery@kontron.com>
> ---
>  utils/test-pkg | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/test-pkg b/utils/test-pkg
> index f3b34d5d0d..5e440b12f6 100755
> --- a/utils/test-pkg
> +++ b/utils/test-pkg
> @@ -138,6 +138,10 @@ main() {
>  
>      printf "%d builds, %d skipped, %d build failed, %d legal-info failed\n" \
>          ${nb} ${nb_skip} ${nb_fail} ${nb_legal}
> +
> +    if [ ${nb_fail} -ne 0 -o ${nb_legal} -ne 0 ]; then
> +        return 1
> +    fi

It might be simpler to just return the number of failures:

    return $((nb_fail+nb_legal))

>  }
>  
>  build_one() {
> @@ -264,4 +268,7 @@ _EOF_
>  }
>  
>  my_name="${0##*/}"
> -main "${@}"
> +main "${@}" && ret=0 || ret=${?}
> +if [ ${ret} -ne 0 ]; then
> +    exit 1
> +fi

No need for this gymnastics: the script will return with the same return
code as the last command in the script, which in this case happen to be
the return code of main(), which will be 1 in case of error.
So, you really only need to change the return code of main().

Regards,
Yann E. MORIN.

> -- 
> 2.20.1
> 
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
diff mbox series

Patch

diff --git a/utils/test-pkg b/utils/test-pkg
index f3b34d5d0d..5e440b12f6 100755
--- a/utils/test-pkg
+++ b/utils/test-pkg
@@ -138,6 +138,10 @@  main() {
 
     printf "%d builds, %d skipped, %d build failed, %d legal-info failed\n" \
         ${nb} ${nb_skip} ${nb_fail} ${nb_legal}
+
+    if [ ${nb_fail} -ne 0 -o ${nb_legal} -ne 0 ]; then
+        return 1
+    fi
 }
 
 build_one() {
@@ -264,4 +268,7 @@  _EOF_
 }
 
 my_name="${0##*/}"
-main "${@}"
+main "${@}" && ret=0 || ret=${?}
+if [ ${ret} -ne 0 ]; then
+    exit 1
+fi