Skip to content

Commit 61d3192

Browse files
committed
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.
1 parent ab6a63e commit 61d3192

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
sudo apt -y update
4040
sudo apt -y install zsh fish shellcheck
4141
fi
42-
curl -s https://bashunit.typeddevs.com/install.sh | bash -s 0.23.0
42+
curl -s https://bashunit.typeddevs.com/install.sh | bash -s beta
4343
4444
- name: Show version
4545
run: |

tests/helper-functions.test.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
3+
function set_up_before_script() {
4+
source bin/git-forgit
5+
}
6+
7+
# @data_provider provider_diff_lines
8+
function test_forgit_get_files_from_diff_line() {
9+
local -r input="$1"
10+
shift
11+
local -r expected=("$@")
12+
local -a actual=()
13+
local i
14+
15+
while IFS= read -r line; do
16+
actual+=( "$line" )
17+
done < <( echo -n "$input" | _forgit_get_files_from_diff_line | xargs -0 -n 1 echo )
18+
19+
# Compare array sizes
20+
assert_same "${#expected[@]}" "${#actual[@]}"
21+
22+
# Compare array elements
23+
for i in "${!expected[@]}"; do
24+
assert_same "${expected[i]}" "${actual[i]}"
25+
done
26+
}
27+
28+
function provider_diff_lines() {
29+
data_set "[A] newfile" "newfile"
30+
data_set "[D] oldfile with spaces" "oldfile with spaces"
31+
data_set "[R100] file -> another file" "file" "another file"
32+
data_set "[M] \"file with\ttab.txt\"" "\"file with\ttab.txt\""
33+
}

0 commit comments

Comments
 (0)