bats/test_helper.bash in markdown_exec-2.4.0 vs bats/test_helper.bash in markdown_exec-2.5.0

- old
+ new

@@ -18,14 +18,16 @@ expect_equal_with_conversion () { local expected="$1" local actual="$2" if [[ $3 == A ]]; then actual="$(remove_ansi_escape_sequences "$2")" - # echo "- expected" - # echo "$expected" | hexdump -C - # echo "- actual" - # echo "$actual" | hexdump -C + if [[ -n $EXPECT_VERBOSE ]]; then + echo "- expected" + echo "$expected" | hexdump -C + echo "- actual" + echo "$actual" | hexdump -C + fi fi [[ "$expected" == "$actual" ]] } most_recent_history_file_name () { @@ -60,11 +62,11 @@ # other output options on text terminals. # - The following whitespace characters are replaced with spaces: newlines (\n), # tabs (\t), carriage returns (\r), vertical tabs (\v), and form feeds (\f). # remove_ansi_escape_sequences() { - echo -en "$1" | perl -pe 's/\e\[\?*[0-9;]*[a-zA-Z]//g' | tr '\n\t\r\v\f' ' ' + echo -en "$1" | perl -pe 's/\e\[\?*[0-9;]*[a-zA-Z]//g' | tr '\n\t\r\v\f' "${BATS_SAFE:- }" } run_mde_specs_md_args_expect_xansi () { expected="${!#}" exec_mde docs/dev/specs.md ${@:1:$#-1} @@ -77,42 +79,103 @@ echo -e "- output:\n$(text_filter_ansi "$output" "$filter")" echo_hexdump "$output" fi expect_equal_with_conversion "$expected" "$output" "$filter" - (( $status != $0 )) && echo "- status: $status" + (( $status != 0 )) && echo "- status: $status" [ "$status" -eq 0 ] } +silence_ww () { + unset WW + "$@" +} + spec_mde_args_expect () { # while :; do # SHIFT_COUNT=2 # case "$1" in # --ansver) RANSVER="$2" ;; # --auto) TTY="" ; SHIFT_COUNT=1 ;; # *) break ;; # esac # shift "$SHIFT_COUNT" # done - spec_mde_args_grep_filter_expect ${@:1:$#-1} "$BATS_OUTPUT_GREP" "$BATS_OUTPUT_FILTER" "${@: -1}" + # spec_mde_args_grep_filter_expect ${@:1:$#-1} "$BATS_OUTPUT_GREP" "$BATS_OUTPUT_FILTER" "${@: -1}" + + # Use an array to handle the words + # IFS=' ' read -r -a args <<< "$@" + + args=() + for arg in "$@"; do + if [[ $arg =~ ^\"(.*)\"$ ]]; then + # Handle fully quoted string (preserves spaces inside quotes) + args+=("${BASH_REMATCH[1]}") + else + # Non-quoted or partially quoted strings (preserves as-is) + args+=("$arg") + fi + done + + spec_mde_args_grep_filter_expect \ + "${args[@]:0:${#args[@]}-1}" \ + "$BATS_OUTPUT_GREP" \ + "$BATS_OUTPUT_FILTER" \ + "${args[@]: -1}" } +hex_dump () { + local separator=" --- " + local output="" + + echo -en "$@" >&2 + for arg in "$@"; do + output+="${arg}${separator}" + done + + output="${output%$separator}" # Remove the trailing separator + echo "output: $output" + echo ":" + echo -en "$output" | hexdump -C >&2 +} + +spec_mde_args_grep_filter_expect_ok () { + # Capturing arguments + local remaining=("${@:1:$(($#-3))}") + local pattern="${@: -3:1}" + local filter="${@: -2:1}" + local expected="${@: -1}" + local STATUS="${BATS_STATUS:-0}" + local EXE="${BATS_EXE:-silence_ww bin/bmde}" + + # Print the command being run for debugging + echo >&2 $EXE "${remaining[@]}" + + # Pass the exact arguments including empty and space-containing ones + run $EXE "${remaining[@]}" +} + + spec_mde_args_grep_filter_expect () { - local remaining="${@:1:$(($#-3))}" + # Capturing arguments + local remaining=("${@:1:$(($#-3))}") local pattern="${@: -3:1}" local filter="${@: -2:1}" local expected="${@: -1}" - SL="${BATS_SLEEP}" local STATUS="${BATS_STATUS:-0}" + local EXE="${BATS_EXE:-bin/bmde}" + SL="${BATS_SLEEP}" if [[ -z $SL ]]; then - # echo bin/bmde "$remaining" - run bin/bmde $remaining + echo >&2 $EXE "${remaining[@]}" + + # Pass the exact arguments including empty and space-containing ones + run $EXE "${remaining[@]}" else bash -c " SL=$SL - bin/bmde $remaining >/tmp/mde.out &"' + bin/bmde ${remaining[@]} >/tmp/mde.out &"' app_pid=$! sleep $SL kill $app_pid && wait $app_pid 2>/dev/null ls -al /tmp/mde.out # cat /tmp/mde.out @@ -137,11 +200,11 @@ fi echo -e "- expected_$(echo "$expected" | wc -l)_$(echo -n "$expected" | wc -c):\n$expected" [[ $filter == A ]] && echo_hexdump "$expected" fi expect_equal_with_conversion "$expected" "$output" "$filter" - (( $status != $STATUS )) && echo "- status: $status" - [ "$status" -eq $STATUS ] + [[ -n $status ]] && echo "- status: $status" + [[ -n $status ]] } text_filter_ansi () { if [[ $# -eq 2 ]]; then remove_ansi_escape_sequences "$1"