@@ -1056,6 +1056,77 @@ hello.c')
10561056 expect_contains frandom_seed_user_passthrough " $_out " ' -frandom-seed=custom'
10571057}
10581058
1059+ # ---------------------------------------------------------------------------
1060+ # -Werror handling
1061+ # ---------------------------------------------------------------------------
1062+
1063+ # _werror_set_mode MODE -> exports KEEP/REPLACE for one of three modes:
1064+ # all keep every -Werror* flag
1065+ # specific keep -Werror-* and -Werror=*, rewrite bare -Werror to -Wno-error
1066+ # none rewrite all -Werror* to -Wno-error*
1067+ _werror_set_mode () {
1068+ case " $1 " in
1069+ all)
1070+ SPACK_COMPILER_FLAGS_KEEP=' -Werror*'
1071+ SPACK_COMPILER_FLAGS_REPLACE=' '
1072+ ;;
1073+ specific)
1074+ SPACK_COMPILER_FLAGS_KEEP=' -Werror-*|-Werror=*'
1075+ SPACK_COMPILER_FLAGS_REPLACE=' -Werror-|-Wno-error= -Werror|-Wno-error'
1076+ ;;
1077+ none)
1078+ SPACK_COMPILER_FLAGS_KEEP=' '
1079+ SPACK_COMPILER_FLAGS_REPLACE=' -Werror-|-Wno-error= -Werror|-Wno-error'
1080+ ;;
1081+ esac
1082+ export SPACK_COMPILER_FLAGS_KEEP SPACK_COMPILER_FLAGS_REPLACE
1083+ }
1084+
1085+ test_werror_handling () {
1086+ wrapper_environment
1087+
1088+ # Family 1: -Werror / -Werror=specific
1089+ _in1=' -Werror
1090+ -Werror=specific'
1091+
1092+ _werror_set_mode all
1093+ _out=$( dump_args cc " $_in1 " )
1094+ expect_contains werror_all1 " $_out " ' -Werror'
1095+
1096+ _werror_set_mode specific
1097+ _out=$( dump_args cc " $_in1 " )
1098+ expect_contains werror_spec1 " $_out " ' -Wno-error'
1099+ expect_not_contains werror_spec1 " $_out " ' -Werror'
1100+
1101+ _werror_set_mode none
1102+ _out=$( dump_args cc " $_in1 " )
1103+ expect_contains werror_none1 " $_out " ' -Wno-error'
1104+ expect_contains werror_none1 " $_out " ' -Wno-error=specific'
1105+ expect_not_contains werror_none1 " $_out " ' -Werror'
1106+ expect_not_contains werror_none1 " $_out " ' -Werror=specific'
1107+
1108+ # Family 2: -Werror-implicit-function-declaration (non-standard dash form)
1109+ _in2=' -Werror
1110+ -Werror-implicit-function-declaration'
1111+
1112+ _werror_set_mode all
1113+ _out=$( dump_args cc " $_in2 " )
1114+ expect_contains werror_all2 " $_out " ' -Werror'
1115+
1116+ _werror_set_mode specific
1117+ _out=$( dump_args cc " $_in2 " )
1118+ expect_contains werror_spec2 " $_out " ' -Wno-error'
1119+ expect_contains werror_spec2 " $_out " ' -Werror-implicit-function-declaration'
1120+ expect_not_contains werror_spec2 " $_out " ' -Werror'
1121+
1122+ _werror_set_mode none
1123+ _out=$( dump_args cc " $_in2 " )
1124+ expect_contains werror_none2 " $_out " ' -Wno-error'
1125+ expect_contains werror_none2 " $_out " ' -Wno-error=implicit-function-declaration'
1126+ expect_not_contains werror_none2 " $_out " ' -Werror'
1127+ expect_not_contains werror_none2 " $_out " ' -Werror-implicit-function-declaration'
1128+ }
1129+
10591130# ---------------------------------------------------------------------------
10601131# Runner
10611132# ---------------------------------------------------------------------------
@@ -1076,6 +1147,7 @@ test_linker_strips_loopopt
10761147test_spack_managed_dirs_are_prioritized
10771148test_frandom_seed_not_added_without_env
10781149test_frandom_seed_filters_args
1150+ test_werror_handling
10791151'
10801152
10811153if [ $# -gt 0 ]; then
0 commit comments