Skip to content

Commit

Permalink
tools/test: Simplify handling of suites list
Browse files Browse the repository at this point in the history
This makes for a bit less duplication in the code; fewer places
to have to update when adding a new suite.  The CLI-parsing logic
also gets a bit simpler.

I think this also makes the usage message a bit simpler to understand.
Like the existing version, it's a bit awkward as long as there are no
non-default suites; but we'll be adding one of those shortly.
  • Loading branch information
gnprice committed Jan 25, 2023
1 parent e785388 commit e0009b5
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions tools/test
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,23 @@ this_dir=${BASH_SOURCE[0]%/*}

## CLI PARSING

default_suites=(native flow lint jest prettier deps tsflower)
extra_suites=()

usage() {
cat >&2 <<EOF
usage: tools/test [OPTION]... [SUITE]...
Run our tests.
By default, run all suites except any noted under "Suites:" below, but only
on files changed in this branch as found by
By default, run only on files changed in this branch as found by
\`tools/git changed-files \$(tools/git base)\`.
By default, run ${#default_suites[@]} suite(s):
${default_suites[*]}
and skip ${#extra_suites[@]} suite(s):
${extra_suites[*]}
What tests to run:
--all-files
Run on all files, not only changed files.
Expand All @@ -57,32 +64,15 @@ Extra things to do:
--coverage Collect test-coverage information. Only meaningful
with --all.
--fix Fix issues found, where possible.
Suites:
native
flow
lint
jest
prettier
deps
tsflower
EOF
exit 2
}

# The complete list of suites.
all_suites=(native flow lint jest prettier deps tsflower)

opt_coverage=
opt_files=branch
opt_platform=sloppy
opt_all=
opt_fix=

# The suites to run if none are given as arguments. Unless --all is
# specified, this doesn't have to be the complete list; just be sure to
# document in the usage message when a suite gets skipped.
opt_default_suites=(native flow lint jest prettier deps tsflower)

opt_suites=()
while (( $# )); do
case "$1" in
Expand All @@ -97,7 +87,7 @@ while (( $# )); do
esac
shift
;;
--all) opt_files=all; opt_platform=both; opt_default_suites=( "${all_suites[@]}" ); shift;;
--all) opt_files=all; opt_platform=both; opt_all=1; shift;;
--fix) opt_fix=1; shift;;
native|flow|lint|jest|prettier|deps|tsflower)
opt_suites+=("$1"); shift;;
Expand All @@ -106,7 +96,11 @@ while (( $# )); do
done

if [ -z "$opt_suites" ]; then
opt_suites=( "${opt_default_suites[@]}" )
if [ -n "${opt_all}" ]; then
opt_suites=( "${default_suites[@]}" "${extra_suites[@]}" )
else
opt_suites=( "${default_suites[@]}" )
fi
fi

files_base_commit=
Expand Down

0 comments on commit e0009b5

Please sign in to comment.