From 7240dcecc6fd94ee9b6301de9925f072a8adf9cb Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Fri, 15 May 2026 11:35:30 +0200 Subject: [PATCH 1/2] SPACK_ADD_DEBUG_FLAGS: simplify + test Signed-off-by: Harmen Stoppels --- cc.sh | 22 ++++------------------ test/run.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/cc.sh b/cc.sh index b888427..6567e44 100755 --- a/cc.sh +++ b/cc.sh @@ -281,24 +281,10 @@ append_path_lists() { esac } -# Check if optional parameters are defined -# If we aren't asking for debug flags, don't add them -if [ -z "${SPACK_ADD_DEBUG_FLAGS:-}" ]; then - SPACK_ADD_DEBUG_FLAGS="false" -fi - -# SPACK_ADD_DEBUG_FLAGS must be true/false/custom -is_valid="false" -for param in "true" "false" "custom"; do - if [ "$param" = "$SPACK_ADD_DEBUG_FLAGS" ]; then - is_valid="true" - fi -done - -# Exit with error if we are given an incorrect value -if [ "$is_valid" = "false" ]; then - die "SPACK_ADD_DEBUG_FLAGS, if defined, must be one of 'true', 'false', or 'custom'." -fi +case "${SPACK_ADD_DEBUG_FLAGS:-false}" in + true|false|custom) ;; + *) die "SPACK_ADD_DEBUG_FLAGS must be true, false, or custom" ;; +esac # Figure out the type of compiler, the language, and the mode so that # the compiler script knows what to do. diff --git a/test/run.sh b/test/run.sh index 8127170..bab1a53 100755 --- a/test/run.sh +++ b/test/run.sh @@ -1270,6 +1270,45 @@ test_lsep_prepend_pattern() { expect_eq prepend_pattern_last "$3" '-O2' } +# --------------------------------------------------------------------------- +# SPACK_ADD_DEBUG_FLAGS validation +# --------------------------------------------------------------------------- + +test_add_debug_flags_validation() { + wrapper_environment + SPACK_TEST_COMMAND=dump-mode; export SPACK_TEST_COMMAND + + # Unset and accepted values: wrapper should exit 0. + unset SPACK_ADD_DEBUG_FLAGS + _out=$("$WRAPPER_DIR/cc" -E 2>&1) + _rc=$? + if [ "$_rc" -ne 0 ]; then + fail "add_debug_flags_unset: unexpected exit $_rc, output: $_out" + fi + + for _v in true false custom; do + SPACK_ADD_DEBUG_FLAGS=$_v; export SPACK_ADD_DEBUG_FLAGS + _out=$("$WRAPPER_DIR/cc" -E 2>&1) + _rc=$? + if [ "$_rc" -ne 0 ]; then + fail "add_debug_flags_${_v}: unexpected exit $_rc, output: $_out" + fi + done + + # Invalid value: wrapper must die with a message mentioning the var. + SPACK_ADD_DEBUG_FLAGS=bogus; export SPACK_ADD_DEBUG_FLAGS + _out=$("$WRAPPER_DIR/cc" -E 2>&1) + _rc=$? + if [ "$_rc" -eq 0 ]; then + fail "add_debug_flags_invalid: expected non-zero exit, got 0" + fi + case "$_out" in + *SPACK_ADD_DEBUG_FLAGS*) ;; + *) fail "add_debug_flags_invalid: expected 'SPACK_ADD_DEBUG_FLAGS' in: $_out" ;; + esac + unset SPACK_ADD_DEBUG_FLAGS +} + # --------------------------------------------------------------------------- # Runner # --------------------------------------------------------------------------- @@ -1319,6 +1358,7 @@ test_linker_strips_loopopt test_spack_managed_dirs_are_prioritized test_frandom_seed_not_added_without_env test_frandom_seed_filters_args +test_add_debug_flags_validation ' all_tests="$wrapper_tests $list_ops_tests" From e9b7de6ee0e31a4740f2fe37d07e614c132c6420 Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Wed, 20 May 2026 10:23:10 +0200 Subject: [PATCH 2/2] Tighten validation-error assertion Signed-off-by: Harmen Stoppels --- test/run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run.sh b/test/run.sh index bab1a53..28cc2e0 100755 --- a/test/run.sh +++ b/test/run.sh @@ -1303,8 +1303,8 @@ test_add_debug_flags_validation() { fail "add_debug_flags_invalid: expected non-zero exit, got 0" fi case "$_out" in - *SPACK_ADD_DEBUG_FLAGS*) ;; - *) fail "add_debug_flags_invalid: expected 'SPACK_ADD_DEBUG_FLAGS' in: $_out" ;; + *"SPACK_ADD_DEBUG_FLAGS must be"*) ;; + *) fail "add_debug_flags_invalid: expected 'SPACK_ADD_DEBUG_FLAGS must be' in: $_out" ;; esac unset SPACK_ADD_DEBUG_FLAGS }