-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds two new scripts: test.sh, which is much more amenable and flexible to use than the previous testing logic in the Makefile, and a lint.sh script. Both are used from the merge checks, but they can also be used interactively.
- Loading branch information
Showing
7 changed files
with
176 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ jobs: | |
- uses: mozilla-actions/[email protected] | ||
- run: sudo apt update | ||
- run: sudo apt install pre-commit | ||
- run: make lint | ||
- run: ./lint.sh | ||
|
||
test-individually: | ||
runs-on: ubuntu-latest | ||
|
@@ -42,7 +42,7 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: mozilla-actions/[email protected] | ||
- run: make test-individually | ||
- run: ./test.sh all | ||
|
||
test-workspace: | ||
runs-on: ubuntu-latest | ||
|
@@ -59,4 +59,4 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: mozilla-actions/[email protected] | ||
- run: make test-workspace | ||
- run: ./test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Cargo.lock | ||
config.mk | ||
config.env | ||
target | ||
vscode-target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
Cargo.lock | ||
build.stamp | ||
config.env | ||
perfectschedule | ||
config.mk | ||
target/ | ||
vscode-target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#! /bin/sh | ||
# III-IV | ||
# Copyright 2023 Julio Merino | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy | ||
# of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
set -eu | ||
|
||
pre-commit run -a | ||
cargo clippy -- -D warnings | ||
cargo clippy --features=testutils -- -D warnings | ||
cargo clippy --all-features --all-targets -- -D warnings | ||
cargo fmt -- --check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#! /bin/sh | ||
# III-IV | ||
# Copyright 2023 Julio Merino | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
# use this file except in compliance with the License. You may obtain a copy | ||
# of the License at: | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
|
||
set -eu | ||
|
||
readonly PROGNAME="${0##*/}" | ||
|
||
err() { | ||
echo "${PROGNAME}: E: ${*}" 1>&2 | ||
exit 1 | ||
} | ||
|
||
info() { | ||
echo "${PROGNAME}: I: ${*}" 1>&2 | ||
} | ||
|
||
run_tests() { | ||
local dir="${1}"; shift | ||
local cargo_args="${1}"; shift | ||
local test_args="${1}"; shift | ||
local features="${1}"; shift | ||
|
||
( | ||
if [ -e ./config.env ]; then | ||
info "Loading ./config.env" | ||
. ./config.env | ||
fi | ||
|
||
cd "${dir}" | ||
|
||
for feature in ${features}; do | ||
if [ "${feature}" = default ]; then | ||
info "Testing ${dir} with default features" | ||
cargo test ${cargo_args} -- --include-ignored ${test_args} | ||
else | ||
if grep -q "^{feature} = \[" Cargo.toml; then | ||
info "Testing ${dir} with feature=${feature}" | ||
cargo test --features="${feature}" ${cargo_args} -- --include-ignored ${test_args} | ||
else | ||
info "Skipping ${dir} with feature=${feature}" | ||
fi | ||
fi | ||
done | ||
) | ||
} | ||
|
||
usage() { | ||
cat <<EOF | ||
Usage: ${PROGNAME} [-A cargo_arg] [-a test_arg] [-f feature] [crate1 .. crateN] | ||
If no crates are specified, runs all tests from the root of the workspace. | ||
If one or more crates are specified, runs all tests from the individual crate | ||
directories. The special name "all" can be used to run tests for all crates | ||
individually. | ||
The -A flag specifies extra arguments to "cargo test". This flag can be used | ||
multiple times and the values all accumulate. | ||
The -a flag specifies extra arguments to the test programs. This flag can be | ||
used multiple times and the values all accumulate. | ||
The -f flag specifies the individual features to test. This flag can be used | ||
multiple times and the valus all accumulate. If not specified, all known | ||
features are tested individually. | ||
EOF | ||
} | ||
|
||
main() { | ||
local cargo_args= | ||
local test_args= | ||
local features= | ||
while getopts ':A:a:f:h' arg "${@}"; do | ||
case "${arg}" in | ||
A) | ||
cargo_args="${cargo_args} ${OPTARG}" | ||
;; | ||
|
||
a) | ||
test_args="${test_args} ${OPTARG}" | ||
;; | ||
|
||
f) | ||
features="${features} ${OPTARG}" | ||
;; | ||
|
||
h) | ||
usage | ||
exit 0 | ||
;; | ||
|
||
:) | ||
err "Missing argument to option -${OPTARG} in build" | ||
;; | ||
|
||
\?) | ||
err "Unknown option -${OPTARG} in build" | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND - 1)) | ||
|
||
[ -n "${features}" ] || features="default postgres sqlite testutils" | ||
|
||
[ -e ./.github ] || err "Must be run from the root of the workspace" | ||
|
||
if [ ${#} -eq 0 ]; then | ||
run_tests . "${cargo_args}" "${test_args}" "${features}" | ||
else | ||
local crates= | ||
if [ ${#} -eq 1 -a "${1}" = all ]; then | ||
crates="$(grep '^ *"' Cargo.toml | cut -d '"' -f 2)" | ||
info "Expanded crates to test to $(echo ${crates})" | ||
else | ||
crates="${*}" | ||
fi | ||
|
||
for crate in ${crates}; do | ||
run_tests "${crate}" "${cargo_args}" "${test_args}" "${features}" | ||
done | ||
fi | ||
} | ||
|
||
main "${@}" |