diff --git a/cc.sh b/cc.sh index 4156eed..a72aaa9 100755 --- a/cc.sh +++ b/cc.sh @@ -261,24 +261,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 a59b0a9..bdacae3 100644 --- a/test/run.sh +++ b/test/run.sh @@ -1056,6 +1056,45 @@ hello.c') expect_contains frandom_seed_user_passthrough "$_out" '-frandom-seed=custom' } +# --------------------------------------------------------------------------- +# 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 # --------------------------------------------------------------------------- @@ -1076,6 +1115,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 ' if [ $# -gt 0 ]; then