From 7b39420de37f64c5efc80a6711a86c67dcea38b3 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 18 May 2020 10:48:47 -0700 Subject: [PATCH] Make it easy to build with address sanitizer in test script --- script/test | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/script/test b/script/test index 5fda7cb2..bcc88e24 100755 --- a/script/test +++ b/script/test @@ -37,12 +37,26 @@ export RUST_BACKTRACE=full mode=normal -while getopts "dDghl:e:s:t:" option; do +# Specify a `--target` explicitly. For some reason, this is required for +# address sanitizer support. +toolchain=$(rustup show active-toolchain) +toolchain_regex='(stable|beta|nightly)-([_a-z0-9-]+).*' +if [[ $toolchain =~ $toolchain_regex ]]; then + release=${BASH_REMATCH[1]} + current_target=${BASH_REMATCH[2]} +else + echo "Failed to parse toolchain '${toolchain}'" +fi + +while getopts "adDghl:e:s:t:" option; do case ${option} in h) usage exit ;; + a) + export RUSTFLAGS="-Z sanitizer=address" + ;; l) export TREE_SITTER_TEST_LANGUAGE_FILTER=${OPTARG} ;; @@ -82,5 +96,5 @@ if [[ "${mode}" == "debug" ]]; then ) lldb "${test_binary}" -- $top_level_filter else - cargo test -p tree-sitter-cli --jobs 1 $top_level_filter -- --nocapture + cargo test --target=${current_target} -p tree-sitter-cli --jobs 1 $top_level_filter -- --nocapture fi