From 004f49cb492962f3a64147ffc2cf8db55c1e0a1c Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Thu, 17 Jul 2025 14:36:09 -0400 Subject: [PATCH 1/2] odov3 optional parameters for stack directories Signed-off-by: Michael Valdron Signed-off-by: Lucas Yoon --- tests/check_non_terminating.sh | 38 +++++++++++++++++++++++++++++-- tests/check_odov3.sh | 38 +++++++++++++++++++++++++++++-- tests/common_args.sh | 29 +++++++++++++++++++++++ tests/get_paths.sh | 29 +++++++++++++++++++++++ tests/validate_devfile_schemas.sh | 29 ++++++++++++++++++++--- 5 files changed, 156 insertions(+), 7 deletions(-) create mode 100644 tests/common_args.sh create mode 100644 tests/get_paths.sh diff --git a/tests/check_non_terminating.sh b/tests/check_non_terminating.sh index 3297888e..4eac6d88 100755 --- a/tests/check_non_terminating.sh +++ b/tests/check_non_terminating.sh @@ -2,10 +2,44 @@ set -o nounset set -o errexit -DEVFILES_DIR="$(pwd)/stacks" +# Source shared utilities +source "$(dirname "$0")/get_paths.sh" + +POSITIONAL_ARGS=() + +while [[ $# -gt 0 ]]; do + case $1 in + --stackDirs) + stackDirs=$2 + shift # past argument + shift + ;; + --stacksPath) + stacksPath=$2 + shift # past argument + shift + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + POSITIONAL_ARGS+=("$1") # save positional arg + shift # past argument + ;; + esac +done + +# Restore positional parameters +restore_positional_args POSITIONAL_ARGS + +# Set defaults for stack arguments +set_stack_defaults + +DEVFILES_DIR="$stacksPath" # The stacks to test as a string separated by spaces -STACKS=$(bash "$(pwd)/tests/get_stacks.sh") +STACKS="$stackDirs" # Path to the check_non_terminating go package BIN_NAME=${BIN_NAME:-"flatten-parent"} diff --git a/tests/check_odov3.sh b/tests/check_odov3.sh index 2cc47f7b..817f0753 100755 --- a/tests/check_odov3.sh +++ b/tests/check_odov3.sh @@ -2,7 +2,41 @@ set -x -stackDirs=$(bash "$(pwd)/tests/get_stacks.sh") +# Source shared utilities +source "$(dirname "$0")/get_paths.sh" + +POSITIONAL_ARGS=() +VERBOSE="false" + +while [[ $# -gt 0 ]]; do + case $1 in + --stackDirs) + stackDirs=$2 + shift # past argument + shift + ;; + --stacksPath) + stacksPath=$2 + shift # past argument + shift + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + POSITIONAL_ARGS+=("$1") # save positional arg + shift # past argument + ;; + esac +done + +# Restore positional parameters +restore_positional_args POSITIONAL_ARGS + +# Set defaults for stack arguments +set_stack_defaults + args="" if [ ! -z "${1}" ]; then @@ -63,4 +97,4 @@ ginkgo run --mod=readonly --procs 2 \ --skip="stack: ollama" \ --slow-spec-threshold 120s \ --timeout 3h \ - tests/odov3 -- -stacksPath "$(pwd)"/stacks -stackDirs "$stackDirs" ${args} + tests/odov3 -- -stacksPath "$stacksPath" -stackDirs "$stackDirs" ${args} diff --git a/tests/common_args.sh b/tests/common_args.sh new file mode 100644 index 00000000..ce3aa71a --- /dev/null +++ b/tests/common_args.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Shared utilities for devfile registry test scripts +# Usage: source this file and call set_stack_defaults() after parsing arguments + +# Common variables used by all scripts +stackDirs='' +stacksPath='' + +# Function to set default values for stack arguments +set_stack_defaults() { + if [ -z "$stackDirs" ]; then + stackDirs=$(bash "$(pwd)/tests/get_stacks.sh") + fi + + if [ -z "$stacksPath" ]; then + stacksPath="$(pwd)/stacks" + fi +} + +# Helper function to restore positional parameters +restore_positional_args() { + local -n args_array=$1 + if [ ${#args_array[@]} -gt 0 ]; then + set -- "${args_array[@]}" + else + set -- + fi +} \ No newline at end of file diff --git a/tests/get_paths.sh b/tests/get_paths.sh new file mode 100644 index 00000000..ce3aa71a --- /dev/null +++ b/tests/get_paths.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +# Shared utilities for devfile registry test scripts +# Usage: source this file and call set_stack_defaults() after parsing arguments + +# Common variables used by all scripts +stackDirs='' +stacksPath='' + +# Function to set default values for stack arguments +set_stack_defaults() { + if [ -z "$stackDirs" ]; then + stackDirs=$(bash "$(pwd)/tests/get_stacks.sh") + fi + + if [ -z "$stacksPath" ]; then + stacksPath="$(pwd)/stacks" + fi +} + +# Helper function to restore positional parameters +restore_positional_args() { + local -n args_array=$1 + if [ ${#args_array[@]} -gt 0 ]; then + set -- "${args_array[@]}" + else + set -- + fi +} \ No newline at end of file diff --git a/tests/validate_devfile_schemas.sh b/tests/validate_devfile_schemas.sh index 25f45497..b35f310b 100755 --- a/tests/validate_devfile_schemas.sh +++ b/tests/validate_devfile_schemas.sh @@ -1,5 +1,8 @@ #!/usr/bin/env bash +# Source shared utilities +source "$(dirname "$0")/get_paths.sh" + POSITIONAL_ARGS=() SAMPLES="false" VERBOSE="false" @@ -14,6 +17,16 @@ while [[ $# -gt 0 ]]; do VERBOSE="true" shift # past argument ;; + --stackDirs) + stackDirs=$2 + shift # past argument + shift + ;; + --stacksPath) + stacksPath=$2 + shift # past argument + shift + ;; -*|--*) echo "Unknown option $1" exit 1 @@ -25,11 +38,21 @@ while [[ $# -gt 0 ]]; do esac done -set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters +# Restore positional parameters +restore_positional_args POSITIONAL_ARGS + set -x -stacksDir=${STACKS_DIR:-stacks} -stackDirs=${STACKS:-"$(bash "$(pwd)/tests/get_stacks.sh")"} +# Set defaults for stack arguments, with backward compatibility for environment variables +if [ -z "$stacksPath" ]; then + stacksPath=${STACKS_DIR:-stacks} +fi + +if [ -z "$stackDirs" ]; then + stackDirs=${STACKS:-"$(bash "$(pwd)/tests/get_stacks.sh")"} +fi + +stacksDir="$stacksPath" # Use pwd if relative path if [[ ! ${stacksDir} = /* ]]; then From c65ea41c481b08e3a336abc35ce9c8746fc01897 Mon Sep 17 00:00:00 2001 From: Lucas Yoon Date: Fri, 18 Jul 2025 11:55:35 -0400 Subject: [PATCH 2/2] modularizing parsing arguments for tests Signed-off-by: Lucas Yoon --- tests/check_non_terminating.sh | 32 +++------------- tests/check_odov3.sh | 31 ++------------- tests/common_args.sh | 29 -------------- tests/get_paths.sh | 29 -------------- tests/paths_util.sh | 64 +++++++++++++++++++++++++++++++ tests/validate_devfile_schemas.sh | 56 +++++++++++---------------- 6 files changed, 96 insertions(+), 145 deletions(-) delete mode 100644 tests/common_args.sh delete mode 100644 tests/get_paths.sh create mode 100644 tests/paths_util.sh diff --git a/tests/check_non_terminating.sh b/tests/check_non_terminating.sh index 4eac6d88..09429cab 100755 --- a/tests/check_non_terminating.sh +++ b/tests/check_non_terminating.sh @@ -3,35 +3,13 @@ set -o nounset set -o errexit # Source shared utilities -source "$(dirname "$0")/get_paths.sh" - -POSITIONAL_ARGS=() - -while [[ $# -gt 0 ]]; do - case $1 in - --stackDirs) - stackDirs=$2 - shift # past argument - shift - ;; - --stacksPath) - stacksPath=$2 - shift # past argument - shift - ;; - -*|--*) - echo "Unknown option $1" - exit 1 - ;; - *) - POSITIONAL_ARGS+=("$1") # save positional arg - shift # past argument - ;; - esac -done +source "$(dirname "$0")/paths_util.sh" + +# Parse all arguments +parse_arguments "$@" # Restore positional parameters -restore_positional_args POSITIONAL_ARGS +set -- "${POSITIONAL_ARGS[@]}" # Set defaults for stack arguments set_stack_defaults diff --git a/tests/check_odov3.sh b/tests/check_odov3.sh index 817f0753..f39220c8 100755 --- a/tests/check_odov3.sh +++ b/tests/check_odov3.sh @@ -3,36 +3,13 @@ set -x # Source shared utilities -source "$(dirname "$0")/get_paths.sh" +source "$(dirname "$0")/paths_util.sh" -POSITIONAL_ARGS=() -VERBOSE="false" - -while [[ $# -gt 0 ]]; do - case $1 in - --stackDirs) - stackDirs=$2 - shift # past argument - shift - ;; - --stacksPath) - stacksPath=$2 - shift # past argument - shift - ;; - -*|--*) - echo "Unknown option $1" - exit 1 - ;; - *) - POSITIONAL_ARGS+=("$1") # save positional arg - shift # past argument - ;; - esac -done +# Parse all arguments +parse_arguments "$@" # Restore positional parameters -restore_positional_args POSITIONAL_ARGS +set -- "${POSITIONAL_ARGS[@]}" # Set defaults for stack arguments set_stack_defaults diff --git a/tests/common_args.sh b/tests/common_args.sh deleted file mode 100644 index ce3aa71a..00000000 --- a/tests/common_args.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -# Shared utilities for devfile registry test scripts -# Usage: source this file and call set_stack_defaults() after parsing arguments - -# Common variables used by all scripts -stackDirs='' -stacksPath='' - -# Function to set default values for stack arguments -set_stack_defaults() { - if [ -z "$stackDirs" ]; then - stackDirs=$(bash "$(pwd)/tests/get_stacks.sh") - fi - - if [ -z "$stacksPath" ]; then - stacksPath="$(pwd)/stacks" - fi -} - -# Helper function to restore positional parameters -restore_positional_args() { - local -n args_array=$1 - if [ ${#args_array[@]} -gt 0 ]; then - set -- "${args_array[@]}" - else - set -- - fi -} \ No newline at end of file diff --git a/tests/get_paths.sh b/tests/get_paths.sh deleted file mode 100644 index ce3aa71a..00000000 --- a/tests/get_paths.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -# Shared utilities for devfile registry test scripts -# Usage: source this file and call set_stack_defaults() after parsing arguments - -# Common variables used by all scripts -stackDirs='' -stacksPath='' - -# Function to set default values for stack arguments -set_stack_defaults() { - if [ -z "$stackDirs" ]; then - stackDirs=$(bash "$(pwd)/tests/get_stacks.sh") - fi - - if [ -z "$stacksPath" ]; then - stacksPath="$(pwd)/stacks" - fi -} - -# Helper function to restore positional parameters -restore_positional_args() { - local -n args_array=$1 - if [ ${#args_array[@]} -gt 0 ]; then - set -- "${args_array[@]}" - else - set -- - fi -} \ No newline at end of file diff --git a/tests/paths_util.sh b/tests/paths_util.sh new file mode 100644 index 00000000..0ae47aed --- /dev/null +++ b/tests/paths_util.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# Common variables used by all scripts +stackDirs='' +stacksPath='' +POSITIONAL_ARGS=() + +# Function to parse all arguments +parse_arguments() { + while [[ $# -gt 0 ]]; do + case $1 in + --stackDirs) + if [ -z "${stackDirs}" ]; then + stackDirs=$2 + else + stackDirs="${stackDirs} $2" + fi + shift # past argument + shift + ;; + --stacksPath) + stacksPath=$2 + shift # past argument + shift + ;; + -*|--*) + # Try script-specific handler if it exists + local consumed=0 + local errno=1 + if declare -f handle_additional_args > /dev/null 2>&1; then + consumed=$(handle_additional_args "$@") + errno=$? + fi + + if [ $errno -eq 0 ] && [ $consumed -gt 0 ]; then + # Script handler consumed some arguments + for ((i=0; i