aboutsummaryrefslogtreecommitdiff
path: root/scripts/expandtest.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/expandtest.sh')
-rwxr-xr-xscripts/expandtest.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/scripts/expandtest.sh b/scripts/expandtest.sh
new file mode 100755
index 0000000..844ace6
--- /dev/null
+++ b/scripts/expandtest.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# A script to run expandtest.
+#
+# Usage:
+# bash scripts/expandtest.sh
+#
+# Note: This script requires nightly Rust, rustfmt, and cargo-expand
+
+set -euo pipefail
+
+script_dir="$(cd "$(dirname "${0}")" && pwd)"
+
+if [[ "${1:-none}" == "+"* ]]; then
+ toolchain="${1}"
+elif [[ "${CI:-false}" != "true" ]]; then
+ cargo +nightly -V >/dev/null || exit 1
+ toolchain="+nightly"
+fi
+
+if [[ "${toolchain:-+nightly}" != "+nightly"* ]] || ! rustfmt -V &>/dev/null || ! cargo expand -V &>/dev/null; then
+ echo "error: expandtest.sh requires nightly Rust, rustfmt, and cargo-expand"
+ exit 1
+fi
+
+if [[ "${CI:-false}" != "true" ]]; then
+ # First, check if the compile fails for another reason.
+ cargo ${toolchain} check --tests --manifest-path "${script_dir}"/../tests/expand/Cargo.toml
+
+ # Next, remove the `*.expanded.rs` files to allow updating those files.
+ # Refs: https://docs.rs/macrotest/1/macrotest/#updating-expandedrs
+ rm -rf "${script_dir}"/../tests/expand/tests/expand/*.expanded.rs
+fi
+
+cargo ${toolchain:-} test --manifest-path "${script_dir}"/../tests/expand/Cargo.toml