#!/usr/bin/env bash
#
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

samples_dir=$(readlink -f "$DIR/../org_mode_samples")

function get_test_names {
    for test_file in "$@"
    do
        if [ -e "$test_file" ]; then
            test_file_full_path=$(readlink -f "$test_file")
            relative_to_samples=$(realpath --relative-to "$samples_dir" "$test_file_full_path")
            without_extension="${relative_to_samples%.org}"
            echo "${without_extension/\//_}"
        else
            echo "$test_file"
        fi
    done
}

get_test_names "$@" | while read test; do
    (cd "$DIR/../" && cargo test --no-fail-fast --test test_loader "$test" -- --show-output)
done