test(fgrep): added test for fgrep

pull/19/head
Kevin Zhuang 4 years ago
parent 4acc4963c9
commit bd8ba1f7dc

@ -17,7 +17,7 @@ source "${mydir}"/../helper/set_variable.sh
source "${mydir}"/../helper/git_query.sh
function usage() {
echo -e "Usage: dotbare fedit [-h] ...
echo -e "Usage: dotbare fgrep [-h] ...
Grep words within tracked files and select to edit them through fzf.

@ -20,6 +20,7 @@ edit_commits() {
edit_files() {
export PATH="${BATS_TEST_DIRNAME}:$PATH"
export EDITOR="echo"
bash "${BATS_TEST_DIRNAME}"/../dotbare fedit
}
@ -48,7 +49,5 @@ edit_files() {
@test "fedit edit files" {
run edit_files
# to avoid actually invoking vim, the fzf mock file exit without pringting anything
# when detecting the correct flag called with fzf
[ "${status}" -eq 1 ]
[[ "${output}" =~ "fedit_files" ]]
}

@ -0,0 +1,32 @@
#!/usr/bin/env bats
help() {
bash "${BATS_TEST_DIRNAME}"/../dotbare fgrep -h
}
invalid_option() {
bash "${BATS_TEST_DIRNAME}"/../dotbare fgrep -p
}
edit_lines() {
export PATH="${BATS_TEST_DIRNAME}:$PATH"
export EDITOR="echo"
bash "${BATS_TEST_DIRNAME}"/../dotbare fgrep
}
@test "fgrep help" {
run help
[ "${status}" -eq 0 ]
[ "${lines[0]}" = "Usage: dotbare fgrep [-h] ..." ]
}
@test "fgrep invalid option" {
run invalid_option
[ "${status}" -eq 1 ]
[ "${lines[0]}" = "Invalid option: -p" ]
}
@test "fgrep edit lines" {
run edit_lines
[[ "${output}" =~ "fgrep_lines" ]]
}

@ -35,7 +35,7 @@ elif [[ "$*" =~ "--header=select a commit to rename --no-multi" ]] && [[ "$*" =~
echo "fedit_commits"
elif [[ "$*" =~ "--header=select tracked files to edit" ]]; then
# dotbare fedit -- "./fedit.bats" @test "fedit edit files"
exit
echo "fedit_files"
elif [[ "$*" =~ '--header=select the target commit for HEAD --no-multi' ]] && [[ "$*" =~ "show --color" ]]; then
# dotbare freset --commit -y -- "./freset.bats" @test "freset select commit"
echo "freset_commit"
@ -60,6 +60,9 @@ elif [[ "$*" =~ '--header=select stash to delete' ]] && [[ "$*" =~ "show -p __ -
elif [[ "$*" =~ '--header=select stash to apply' ]] && [[ "$*" =~ "show -p __ --color=always" ]]; then
# dotbare fstash -- "./fstash.bats" @test "fstash apply stash"
echo "fstash_apply"
elif [[ "$*" =~ '--delimiter : --nth 3..' ]]; then
# dotbare fgrep -- "./fgrep.bats" @test "fgrep edit lines"
echo "fgrep_lines"
else
echo "$@"
fi

Loading…
Cancel
Save