Skip to content

Commit e7c0602

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 28a539d commit e7c0602

File tree

1 file changed

+54
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)