From b244e344f59a735aae2afcfea8b0b8de9e8107bc Mon Sep 17 00:00:00 2001 From: carlfriedrich Date: Sat, 6 Sep 2025 13:26:56 +0200 Subject: [PATCH] Meta: Add unit test for _forgit_get_files_from_diff_line function (#464) Update CI to install latest bashunit beta version instead of fixed 0.23.0 version because we need the new "data_set" function for parameterized tests. --- .github/workflows/ci.yaml | 2 +- tests/helper-functions.test.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/helper-functions.test.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index df9bd5a..035759e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -39,7 +39,7 @@ jobs: sudo apt -y update sudo apt -y install zsh fish shellcheck fi - curl -s https://bashunit.typeddevs.com/install.sh | bash -s 0.23.0 + curl -s https://bashunit.typeddevs.com/install.sh | bash -s beta - name: Show version run: | diff --git a/tests/helper-functions.test.sh b/tests/helper-functions.test.sh new file mode 100644 index 0000000..30096c3 --- /dev/null +++ b/tests/helper-functions.test.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +function set_up_before_script() { + source bin/git-forgit +} + +# @data_provider provider_diff_lines +function test_forgit_get_files_from_diff_line() { + local -r input="$1" + shift + local -r expected=("$@") + local -a actual=() + local i + + while IFS= read -r line; do + actual+=( "$line" ) + done < <( echo -n "$input" | _forgit_get_files_from_diff_line | xargs -0 -n 1 echo ) + + # Compare array sizes + assert_same "${#expected[@]}" "${#actual[@]}" + + # Compare array elements + for i in "${!expected[@]}"; do + assert_same "${expected[i]}" "${actual[i]}" + done +} + +function provider_diff_lines() { + data_set "[A] newfile" "newfile" + data_set "[D] oldfile with spaces" "oldfile with spaces" + data_set "[R100] file -> another file" "file" "another file" + data_set "[M] \"file with\ttab.txt\"" "\"file with\ttab.txt\"" +}