2023-08-14 16:18:55 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
2023-08-14 19:50:05 +00:00
|
|
|
cd "$DIR/../"
|
2023-08-14 16:18:55 +00:00
|
|
|
REALPATH=$(command -v uu-realpath || command -v realpath)
|
2023-08-14 19:50:05 +00:00
|
|
|
MAKE=$(command -v gmake || command -v make)
|
2023-08-14 16:18:55 +00:00
|
|
|
|
2023-08-14 19:50:05 +00:00
|
|
|
function main {
|
|
|
|
local test_names=$(get_test_names "${@}")
|
|
|
|
build_container
|
|
|
|
|
|
|
|
local test
|
|
|
|
while read test; do
|
|
|
|
launch_container "$test"
|
|
|
|
done<<<"$test_names"
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_container {
|
|
|
|
$MAKE -C "$DIR/../docker/organic_test"
|
|
|
|
}
|
2023-08-14 16:18:55 +00:00
|
|
|
|
|
|
|
function get_test_names {
|
2023-08-14 19:50:05 +00:00
|
|
|
local test_file
|
|
|
|
local samples_dir=$($REALPATH "$DIR/../org_mode_samples")
|
2023-08-14 16:18:55 +00:00
|
|
|
for test_file in "$@"
|
|
|
|
do
|
|
|
|
if [ -e "$test_file" ]; then
|
2023-08-14 19:50:05 +00:00
|
|
|
local test_file_full_path=$($REALPATH "$test_file")
|
|
|
|
local relative_to_samples=$($REALPATH --relative-to "$samples_dir" "$test_file_full_path")
|
|
|
|
local without_extension="${relative_to_samples%.org}"
|
2023-08-14 16:18:55 +00:00
|
|
|
echo "${without_extension/\//_}" | tr '[:upper:]' '[:lower:]'
|
|
|
|
else
|
|
|
|
echo "$test_file" | tr '[:upper:]' '[:lower:]'
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2023-08-14 19:50:05 +00:00
|
|
|
function launch_container {
|
|
|
|
local test="$1"
|
|
|
|
local additional_args=()
|
|
|
|
|
|
|
|
local init_script=$(cat <<EOF
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=\$'\n\t'
|
|
|
|
|
|
|
|
cargo test --no-fail-fast --lib --test test_loader "$test" -- --show-output
|
|
|
|
EOF
|
|
|
|
)
|
|
|
|
|
2023-08-14 20:11:28 +00:00
|
|
|
docker run --rm -v "$($REALPATH ./):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test sh -c "$init_script"
|
2023-08-14 19:50:05 +00:00
|
|
|
}
|
|
|
|
|
2023-08-14 19:30:13 +00:00
|
|
|
|
2023-08-14 19:50:05 +00:00
|
|
|
main "${@}"
|