@@ -1270,6 +1270,77 @@ test_lsep_prepend_pattern() {
12701270 expect_eq prepend_pattern_last " $3 " ' -O2'
12711271}
12721272
1273+ # ---------------------------------------------------------------------------
1274+ # -Werror handling
1275+ # ---------------------------------------------------------------------------
1276+
1277+ # _werror_set_mode MODE -> exports KEEP/REPLACE for one of three modes:
1278+ # all keep every -Werror* flag
1279+ # specific keep -Werror-* and -Werror=*, rewrite bare -Werror to -Wno-error
1280+ # none rewrite all -Werror* to -Wno-error*
1281+ _werror_set_mode () {
1282+ case " $1 " in
1283+ all)
1284+ SPACK_COMPILER_FLAGS_KEEP=' -Werror*'
1285+ SPACK_COMPILER_FLAGS_REPLACE=' '
1286+ ;;
1287+ specific)
1288+ SPACK_COMPILER_FLAGS_KEEP=' -Werror-*|-Werror=*'
1289+ SPACK_COMPILER_FLAGS_REPLACE=' -Werror-|-Wno-error= -Werror|-Wno-error'
1290+ ;;
1291+ none)
1292+ SPACK_COMPILER_FLAGS_KEEP=' '
1293+ SPACK_COMPILER_FLAGS_REPLACE=' -Werror-|-Wno-error= -Werror|-Wno-error'
1294+ ;;
1295+ esac
1296+ export SPACK_COMPILER_FLAGS_KEEP SPACK_COMPILER_FLAGS_REPLACE
1297+ }
1298+
1299+ test_werror_handling () {
1300+ wrapper_environment
1301+
1302+ # Family 1: -Werror / -Werror=specific
1303+ _in1=' -Werror
1304+ -Werror=specific'
1305+
1306+ _werror_set_mode all
1307+ _out=$( dump_args cc " $_in1 " )
1308+ expect_contains werror_all1 " $_out " ' -Werror'
1309+
1310+ _werror_set_mode specific
1311+ _out=$( dump_args cc " $_in1 " )
1312+ expect_contains werror_spec1 " $_out " ' -Wno-error'
1313+ expect_not_contains werror_spec1 " $_out " ' -Werror'
1314+
1315+ _werror_set_mode none
1316+ _out=$( dump_args cc " $_in1 " )
1317+ expect_contains werror_none1 " $_out " ' -Wno-error'
1318+ expect_contains werror_none1 " $_out " ' -Wno-error=specific'
1319+ expect_not_contains werror_none1 " $_out " ' -Werror'
1320+ expect_not_contains werror_none1 " $_out " ' -Werror=specific'
1321+
1322+ # Family 2: -Werror-implicit-function-declaration (non-standard dash form)
1323+ _in2=' -Werror
1324+ -Werror-implicit-function-declaration'
1325+
1326+ _werror_set_mode all
1327+ _out=$( dump_args cc " $_in2 " )
1328+ expect_contains werror_all2 " $_out " ' -Werror'
1329+
1330+ _werror_set_mode specific
1331+ _out=$( dump_args cc " $_in2 " )
1332+ expect_contains werror_spec2 " $_out " ' -Wno-error'
1333+ expect_contains werror_spec2 " $_out " ' -Werror-implicit-function-declaration'
1334+ expect_not_contains werror_spec2 " $_out " ' -Werror'
1335+
1336+ _werror_set_mode none
1337+ _out=$( dump_args cc " $_in2 " )
1338+ expect_contains werror_none2 " $_out " ' -Wno-error'
1339+ expect_contains werror_none2 " $_out " ' -Wno-error=implicit-function-declaration'
1340+ expect_not_contains werror_none2 " $_out " ' -Werror'
1341+ expect_not_contains werror_none2 " $_out " ' -Werror-implicit-function-declaration'
1342+ }
1343+
12731344# ---------------------------------------------------------------------------
12741345# Runner
12751346# ---------------------------------------------------------------------------
@@ -1319,6 +1390,7 @@ test_linker_strips_loopopt
13191390test_spack_managed_dirs_are_prioritized
13201391test_frandom_seed_not_added_without_env
13211392test_frandom_seed_filters_args
1393+ test_werror_handling
13221394'
13231395
13241396all_tests=" $wrapper_tests $list_ops_tests "
0 commit comments