#!/bin/bash

# Always run the tests from this script's folder
cd "$(dirname "$0")" || exit 1

# Read default configuration
# shellcheck source=test/_include.sh
source ../_include.sh

# Test files user supplied files ($@) otherwise test everything
# shellcheck disable=SC2068
for file_path in ${@:-../parsing/*.sed}
do

    file=$(basename "$file_path")
    output_file=$file.txt

    # Only test *.gnu.sed files when using GNU sed
    test "${file%.gnu.sed}" != "$file" && test "$sed" != 'gsed' && continue

    # The L command was removed in GNU sed 4.3
    test "$file" = "l^.gnu.sed" && continue

    test_message "Testing ${file%.sed}"

    # Run the debugger and save the results
    echo "$text" | $sedsed --debug -f "$file_path" > "$output_file" || failed=1
done

tests_git_status
tests_exit
