Skip to content

Commit dc7cda1

Browse files
authored
Merge pull request #14338 from ethereum/cmdline-tests-exclude-option
Add `--exclude` option to `cmdlineTests.sh`
2 parents 3ecf968 + 399457d commit dc7cda1

File tree

2 files changed

+39
-21
lines changed

2 files changed

+39
-21
lines changed

Diff for: docs/contributing.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ one per subdirectory, and can be executed using the ``cmdlineTests.sh`` script.
280280
By default the script runs all available tests.
281281
You can also provide one or more `file name patterns <https://www.gnu.org/software/bash/manual/bash.html#Filename-Expansion>`_,
282282
in which case only the tests matching at least one pattern will be executed.
283+
It is also possible to exclude files matching a specific pattern by prefixing it with ``--exclude``.
283284

284285
By default the script assumes that a ``solc`` binary is available inside the ``build/`` subdirectory
285286
inside the working copy.
@@ -291,10 +292,11 @@ Example:
291292
.. code-block:: bash
292293
293294
export SOLIDITY_BUILD_DIR=~/solidity/build/
294-
test/cmdlineTests.sh "standard_*" "*_yul_*"
295+
test/cmdlineTests.sh "standard_*" "*_yul_*" --exclude "standard_yul_*"
295296
296297
The commands above will run tests from directories starting with ``test/cmdlineTests/standard_`` and
297-
subdirectories of ``test/cmdlineTests/`` that have ``_yul_`` somewhere in the name.
298+
subdirectories of ``test/cmdlineTests/`` that have ``_yul_`` somewhere in the name,
299+
but no test whose name starts with ``standard_yul_`` will be executed.
298300
It will also assume that the file ``solidity/build/solc/solc`` inside your home directory is the
299301
compiler binary (unless you are on Windows -- then ``solidity/build/solc/Release/solc.exe``).
300302

Diff for: test/cmdlineTests.sh

+35-19
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ source "${REPO_ROOT}/scripts/common_cmdline.sh"
4242
pushd "${REPO_ROOT}/test/cmdlineTests" > /dev/null
4343
autoupdate=false
4444
no_smt=false
45-
declare -a selected_tests
46-
declare -a patterns_with_no_matches
45+
declare -a included_test_patterns
46+
declare -a excluded_test_patterns
4747
while [[ $# -gt 0 ]]
4848
do
4949
case "$1" in
@@ -55,31 +55,47 @@ do
5555
no_smt=true
5656
shift
5757
;;
58+
--exclude)
59+
[[ $2 != '' ]] || fail "No pattern given to --exclude option or the pattern is empty."
60+
excluded_test_patterns+=("$2")
61+
shift
62+
shift
63+
;;
5864
*)
59-
matching_tests=$(find . -mindepth 1 -maxdepth 1 -type d -name "$1" | cut -c 3- | LC_COLLATE=C sort)
60-
61-
if [[ $matching_tests == "" ]]
62-
then
63-
patterns_with_no_matches+=("$1")
64-
printWarning "No tests matching pattern '$1' found."
65-
else
66-
# shellcheck disable=SC2206 # We do not support test names containing spaces.
67-
selected_tests+=($matching_tests)
68-
fi
69-
65+
included_test_patterns+=("$1")
7066
shift
7167
;;
7268
esac
7369
done
7470

75-
if (( ${#selected_tests[@]} == 0 && ${#patterns_with_no_matches[@]} == 0 ))
71+
(( ${#included_test_patterns[@]} > 0 )) || included_test_patterns+=('*')
72+
73+
test_name_filter=('(' -name "${included_test_patterns[0]}")
74+
for pattern in "${included_test_patterns[@]:1}"
75+
do
76+
test_name_filter+=(-or -name "$pattern")
77+
done
78+
test_name_filter+=(')')
79+
80+
for pattern in "${excluded_test_patterns[@]}"
81+
do
82+
test_name_filter+=(-and -not -name "$pattern")
83+
done
84+
85+
# NOTE: We want leading symbols in names to affect the sort order but without
86+
# LC_COLLATE=C sort seems to ignore them.
87+
# shellcheck disable=SC2207 # We do not support test names containing spaces.
88+
selected_tests=($(find . -mindepth 1 -maxdepth 1 -type d "${test_name_filter[@]}" | cut -c 3- | LC_COLLATE=C sort))
89+
90+
if (( ${#selected_tests[@]} == 0 ))
7691
then
77-
# NOTE: We want leading symbols in names to affect the sort order but without
78-
# LC_COLLATE=C sort seems to ignore them.
79-
all_tests=$(echo * | tr '[:space:]' '\n' | LC_COLLATE=C sort)
80-
# shellcheck disable=SC2206 # We do not support test names containing spaces.
81-
selected_tests=($all_tests)
92+
printWarning "The pattern '${test_name_filter[*]}' did not match any tests."
93+
exit 0;
94+
else
95+
test_count=$(find . -mindepth 1 -maxdepth 1 -type d | wc -l)
96+
printLog "Selected ${#selected_tests[@]} out of ${test_count} tests."
8297
fi
98+
8399
popd > /dev/null
84100

85101
case "$OSTYPE" in

0 commit comments

Comments
 (0)