Skip to content

Commit 360656c

Browse files
committed
[test] Add test that verify correct usage of REQUIRES for Swift features
The test will look for other tests using `RUN:` lines that use experimental or upcoming features and will check that the tests also are checking with the right `REQUIRES:` lines for the used features. This should avoid new tests being introduced without the right `REQUIRES` and should avoid breaking the toolchain in less tested configurations.
1 parent 78aca2c commit 360656c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
# RUN: bash %s '%swift_src_root'
3+
# UNSUPPORTED: OS=windows-msvc
4+
5+
if [[ ${DEBUG-} =~ ^1|yes|true$ ]]; then
6+
set -o xtrace
7+
fi
8+
9+
set -o errexit
10+
set -o nounset
11+
set -o pipefail
12+
set -o errtrace
13+
14+
swift_src_root=$1
15+
# Tests that check for the behaviour of experimental/upcoming features, so
16+
# they cannot automatically be checked.
17+
exceptional_files=(
18+
test/Frontend/experimental-features-no-asserts.swift
19+
test/Frontend/upcoming_feature.swift
20+
)
21+
egrep="grep --extended-regexp"
22+
exit_result=0
23+
24+
# Look for every test file in the test directories with `RUN` lines that
25+
# mention `-enable-experimental-feature` or `-enable-upcoming-feature`.
26+
# Be careful of not using REQUIRES or RUN with a colon after them or Lit will
27+
# pick them up.
28+
for f in $(${egrep} --recursive -e 'RUN[:].*-enable-(experimental|upcoming)-feature' --files-with-matches "${swift_src_root}/test" "${swift_src_root}/validation-test"); do
29+
# First lets check this is not one of the exceptional files
30+
relative_f=${f#"${swift_src_root}"/}
31+
for ef in "${exceptional_files[@]}"; do
32+
if [ "${ef}" == "${relative_f}" ]; then
33+
continue 2
34+
fi
35+
done
36+
37+
features=$(${egrep} --no-filename -e 'RUN[:]' "${f}" | ${egrep} --only-matching -e '-enable-(experimental|upcoming)-feature (-Xfrontend )?[A-Za-z0-9]*' | rev | cut -d' ' -f1 | rev | sort -u)
38+
for feature in ${features}; do
39+
# No warning if the necessary `REQUIRES` is already there
40+
if ${egrep} --quiet -e "REQUIRES[:] swift_feature_${feature}" "${f}"; then
41+
continue
42+
fi
43+
44+
# Some tests check for the errors themselves, so we can skip them as well
45+
if rg --quiet -e "requires '-enable-(experimental|upcoming)-feature ${feature}'" "${f}"; then
46+
continue
47+
fi
48+
49+
# For everything else, print a warning and for an invalid exit code
50+
printf "error: %s: Missing '%s: swift_feature_%s'\n" "${f}" "REQUIRES" "${feature}"
51+
exit_result=1
52+
done
53+
done
54+
55+
exit $exit_result

0 commit comments

Comments
 (0)