#!/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 in ${@:-*.sed}
do

    # 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 same sed script in sed and sedsed -d, results must be equal
    # Using explicit - as input file to avoid having "F" command showing /dev/stdin
    echo "$text" | $sed -f "$file" - > "$sed_output" || failed=1
    echo "$text" | $sedsed -d --_stdout-only -f "$file" - > "$sedsed_output" || failed=1
    diff -U1 "$sed_output" "$sedsed_output" || failed=1
done

tests_git_status
tests_exit
