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

- old
+ new

@@ -1,17 +1,50 @@ # facilitate execution of program, comparison of output -export PROJECT_ROOT="/Users/fareed/Documents/dev/ruby/markdown_exec" - date_from_history_file_name () { basename "$1" | sed -E 's/.*([0-9]{4}-[0-9]{2}-[0-9]{2}).*/\1/' } echo_hexdump () { echo -en "$1" | hexdump -C } +echo_hexdump_expected_output_filter () { + local expected="$1" + local output="$2" + local filter="$3" + + echo -e "- output_$(echo "$output" | wc -l)_$(echo -n "$output" | wc -c):\n$output" + if [[ $filter == A ]]; then + echo -e "- converted_$(echo "$output" | wc -l)_$(echo -n "$output" | wc -c):" + echo "$(remove_ansi_escape_sequences "$output")" + fi + echo -e "- expected_$(echo "$expected" | wc -l)_$(echo -n "$expected" | wc -c):\n$expected" + + if [[ $filter == A ]]; then + echo "- output" + echo_hexdump "$output" + echo "- converted" + echo_hexdump "$(remove_ansi_escape_sequences "$output")" + echo "- expected" + echo_hexdump "$expected" + fi +} + +echo_xansi_command_expected_output_filter () { + local command="$1" + local expected="$2" + local output="$3" + local filter="$4" + + echo -e "- command: $command" + echo -e "- expected:\n$expected" + echo_hexdump "$expected" + echo -e "- output:\n$(text_filter_ansi "$output" "$filter")" + echo_hexdump "$output" +} + exec_mde () { echo "bin/bmde "$1" "${@:2}"" run bin/bmde "$1" ${@:2} } @@ -28,10 +61,25 @@ fi fi [[ "$expected" == "$actual" ]] } +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 +} + most_recent_history_file_name () { ls -f logs/*examples_save_md* | tail -n 1 } # remove_ansi_escape_sequences @@ -71,15 +119,11 @@ expected="${!#}" exec_mde docs/dev/specs.md ${@:1:$#-1} filter="${BATS_OUTPUT_FILTER:-A}" if ( ! expect_equal_with_conversion "$expected" "$output" "$filter" ); then - echo -e "- command: ${@:1:$#-1}" - echo -e "- expected:\n$expected" - echo_hexdump "$expected" - echo -e "- output:\n$(text_filter_ansi "$output" "$filter")" - echo_hexdump "$output" + echo_xansi_command_expected_output_filter "${@:1:$#-1}" "$expected" "$output" "$filter" fi expect_equal_with_conversion "$expected" "$output" "$filter" (( $status != 0 )) && echo "- status: $status" [ "$status" -eq 0 ] @@ -121,42 +165,10 @@ "$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 () { # Capturing arguments local remaining=("${@:1:$(($#-3))}") local pattern="${@: -3:1}" local filter="${@: -2:1}" @@ -188,23 +200,36 @@ # prevent error from grep output="$(echo -en "$output" | grep "$pattern")" || : fi if ( ! expect_equal_with_conversion "$expected" "$output" "$filter"); then - echo -e "- output_$(echo "$output" | wc -l)_$(echo -n "$output" | wc -c):\n$output" - [[ $filter == A ]] && echo_hexdump "$output" - - if [[ $filter == A ]]; then - echo -e "- converted_$(echo "$output" | wc -l)_$(echo -n "$output" | wc -c):" - echo "$(remove_ansi_escape_sequences "$output")" - echo_hexdump "$(remove_ansi_escape_sequences "$output")" - fi - echo -e "- expected_$(echo "$expected" | wc -l)_$(echo -n "$expected" | wc -c):\n$expected" - [[ $filter == A ]] && echo_hexdump "$expected" + echo_hexdump_expected_output_filter "$expected" "$output" "$filter" fi expect_equal_with_conversion "$expected" "$output" "$filter" [[ -n $status ]] && echo "- status: $status" [[ -n $status ]] +} + +spec_mde_xansi_dname_doc_blocks_expect () { + BATS_OUTPUT_FILTER=A + BATS_SAFE=_ + spec_mde_args_expect "$1" \ + "${@:2:$(($#-2))}" \ + --list-blocks-message dname \ + --list-blocks-type 3 \ + --list-blocks \ + "${!#}" +} + +spec_mde_xansi_oname_doc_blocks_expect () { + BATS_OUTPUT_FILTER=A + BATS_SAFE=_ + spec_mde_args_expect "$1" \ + "${@:2:$(($#-2))}" \ + --list-blocks-message oname \ + --list-blocks-type 3 \ + --list-blocks \ + "${!#}" } text_filter_ansi () { if [[ $# -eq 2 ]]; then remove_ansi_escape_sequences "$1"