From dfb0d4b41e92e72236011a2c0ffbcbb82882fda7 Mon Sep 17 00:00:00 2001 From: Julio Merino Date: Sat, 2 Dec 2023 06:42:42 -0800 Subject: [PATCH] Replace the Makefile with scripts 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. --- .github/workflows/test.yml | 6 +- .gitignore | 2 +- Makefile | 76 ----------------- config.mk.tmpl => config.env.tmpl | 19 +++-- example/.gitignore | 3 +- lint.sh | 23 +++++ test.sh | 137 ++++++++++++++++++++++++++++++ 7 files changed, 176 insertions(+), 90 deletions(-) delete mode 100644 Makefile rename config.mk.tmpl => config.env.tmpl (64%) create mode 100755 lint.sh create mode 100755 test.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc74738..1f35350 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,7 +25,7 @@ jobs: - uses: mozilla-actions/sccache-action@v0.0.3 - 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/sccache-action@v0.0.3 - - 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/sccache-action@v0.0.3 - - run: make test-workspace + - run: ./test.sh diff --git a/.gitignore b/.gitignore index 8148e53..27cdcab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ Cargo.lock -config.mk +config.env target vscode-target diff --git a/Makefile b/Makefile deleted file mode 100644 index a2b9a7f..0000000 --- a/Makefile +++ /dev/null @@ -1,76 +0,0 @@ -# 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. - -sinclude config.mk - -TEST_ENV += AZURE_MAPS_KEY="$(AZURE_MAPS_KEY)" -TEST_ENV += PGSQL_TEST_HOST="$(PGSQL_TEST_HOST)" -TEST_ENV += PGSQL_TEST_PORT="$(PGSQL_TEST_PORT)" -TEST_ENV += PGSQL_TEST_DATABASE="$(PGSQL_TEST_DATABASE)" -TEST_ENV += PGSQL_TEST_USERNAME="$(PGSQL_TEST_USERNAME)" -TEST_ENV += PGSQL_TEST_PASSWORD="$(PGSQL_TEST_PASSWORD)" -TEST_ENV += RUST_LOG=debug - -TEST_FEATURES = postgres sqlite testutils - -.PHONY: build -build: - cargo build - cargo build --features=testutils - -.PHONY: test -test: test-individually test-workspace - -.PHONY: test-individually -test-individually: - @set -e; \ - crates="$$(grep '^ *"' Cargo.toml | cut -d '"' -f 2)"; \ - if [ -n "$(TEST_CRATES)" ]; then crates="$(TEST_CRATES)"; fi; \ - for crate in $${crates}; do \ - cd $$crate; \ - echo "cd $${crate} && cargo test $(TEST_ARGS) -- --include-ignored"; \ - $(TEST_ENV) cargo test $(TEST_ARGS) -- --include-ignored; \ - for feature in $(TEST_FEATURES); do \ - if grep -q ^$${feature} Cargo.toml; then \ - echo "cd $${crate} && cargo test $(TEST_ARGS) --features=$${feature} -- --include-ignored"; \ - $(TEST_ENV) cargo test --features=$${feature} $(TEST_ARGS) -- --include-ignored; \ - fi; \ - done; \ - cd -; \ - done - -.PHONY: test-workspace -test-workspace: - @echo cargo test -- --include-ignored - @$(TEST_ENV) cargo test $(TEST_ARGS) -- --include-ignored - @for feature in $(TEST_FEATURES); do \ - echo cargo test --features=$${feature} -- --include-ignored; \ - $(TEST_ENV) cargo test --features=$${feature} $(TEST_ARGS) -- --include-ignored; \ - done - -.PHONY: lint -lint: - 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 - -.PHONY: clean -clean: - cargo clean - -.PHONY: cleandir -distclean: clean diff --git a/config.mk.tmpl b/config.env.tmpl similarity index 64% rename from config.mk.tmpl rename to config.env.tmpl index 67576bf..663585c 100644 --- a/config.mk.tmpl +++ b/config.env.tmpl @@ -15,15 +15,18 @@ # User-configurable settings to run tests. # -# To modify this file, first copy it to config.mk and then edit that local copy. This file -# (config.mk.tmpl) must not contain secrets and the config.mk file must never be checked in. +# To modify this file, first copy it to config.env and then edit that local copy. This file +# (config.env.tmpl) must not contain secrets and the config.env file must never be checked in. # Azure Maps key to use to geolocate IPs. -AZURE_MAPS_KEY= +export AZURE_MAPS_KEY= # Settings to connect to the test database. -PGSQL_TEST_HOST= -PGSQL_TEST_PORT=5432 -PGSQL_TEST_DATABASE=iii-iv-test -PGSQL_TEST_USERNAME= -PGSQL_TEST_PASSWORD= +export PGSQL_TEST_HOST= +export PGSQL_TEST_PORT=5432 +export PGSQL_TEST_DATABASE=iii-iv-test +export PGSQL_TEST_USERNAME= +export PGSQL_TEST_PASSWORD= + +# Debugging. +export RUST_LOG=debug diff --git a/example/.gitignore b/example/.gitignore index 1c61cf1..06d5a34 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,6 +1,5 @@ Cargo.lock build.stamp -config.env -perfectschedule +config.mk target/ vscode-target/ diff --git a/lint.sh b/lint.sh new file mode 100755 index 0000000..849ad13 --- /dev/null +++ b/lint.sh @@ -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 diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..a07b557 --- /dev/null +++ b/test.sh @@ -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 <