test(fadd): update mock

pull/13/head
kevin zhuang 4 years ago
parent b5ff22ed6d
commit 18338836f8

@ -12,7 +12,7 @@
function search_file() {
local search_type="$1"
if [[ "${search_type}" == "f" ]]; then
find . -maxdepth 1 -type f | sed "s|\./||g" | fzf --multi --preview "head -200 {}"
find . -maxdepth 1 -type f | sed "s|\./||g" | fzf --multi --preview "cat {}"
elif [[ "${search_type}" == "d" ]]; then
if tree --version &>/dev/null; then
find . -maxdepth 1 -type d | awk '{if ($0 != "." && $0 != "./.git"){gsub(/^\.\//, "", $0);print $0}}' | fzf --multi --preview "tree -L 1 -C --dirsfirst {}"

@ -73,12 +73,12 @@ done
if [[ "${action_type}" == "branch" ]]; then
# checkout branch
selected_branch=$(get_branch 'Select a branch to checkout')
selected_branch=$(get_branch 'select a branch to checkout')
[[ -z "${selected_branch}" ]] && exit 0
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_branch}"
elif [[ "${action_type}" == "commit" ]]; then
# checkout commit
selected_commit=$(get_commit 'Select a commit to checkout')
selected_commit=$(get_commit 'select a commit to checkout')
[[ -z "${selected_commit}" ]] && exit 0
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" checkout "${selected_commit}"
elif [[ "${action_type}" == "modified" ]]; then

@ -25,7 +25,7 @@ stage_selected_dir() {
stage_modified_file() {
export PATH="${BATS_TEST_DIRNAME}:$PATH"
bash "${BATS_TEST_DIRNAME}"/../dotbare fadd --dir
bash "${BATS_TEST_DIRNAME}"/../dotbare fadd
}
@test "fadd help" {
@ -47,14 +47,18 @@ stage_modified_file() {
@test "fadd stage selected file" {
run stage_selected_file
[ "${status}" -eq 129 ]
result=$(echo "${lines[0]}" | tr '`' "'")
[ "${result}" = "error: unknown option 'multi --preview head -200 {}'" ]
[ "${status}" -eq 128 ]
[ "${lines[0]}" = "fatal: pathspec 'searchfile' did not match any files" ]
}
@test "fadd stage selected dir" {
run stage_selected_dir
[ "${status}" -eq 129 ]
result=$(echo "${lines[0]}" | tr '`' "'")
[ "${result}" = "error: unknown option 'multi --preview tree -L 1 -C --dirsfirst {}'" ]
[ "${status}" -eq 128 ]
[ "${lines[0]}" = "fatal: pathspec 'searchdir' did not match any files" ]
}
@test "fadd stage modified file" {
run stage_modified_file
[ "${status}" -eq 128 ]
[ "${lines[0]}" = "fatal: pathspec '/Users/kevinzhuang/modifiedfile' did not match any files" ]
}

@ -6,14 +6,20 @@
# usage:
# export PATH="${BATS_TEST_DIRNAME}:$PATH"
if [[ "$*" =~ "--header=Select a commit to checkout" ]] && [[ "$*" =~ "show --color" ]]; then
if [[ "$*" =~ "--header=select a commit to checkout" ]] && [[ "$*" =~ "show --color" ]]; then
echo "--commitshow"
elif [[ "$*" =~ "--no-multi --header=Select a branch to checkout" ]]; then
elif [[ "$*" =~ "--no-multi --header=select a branch to checkout" ]]; then
echo "--branch"
elif [[ "$*" =~ "--header=select a file to checkout version in HEAD --preview" ]]; then
elif [[ "$*" =~ "--header=select a file to checkout version in HEAD" ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
echo "-- modifiedfile"
elif [[ "$*" =~ '--header=select a file to checkout' ]] && [[ "$*" =~ "cat" ]]; then
echo "selectgitfile"
elif [[ "$*" =~ '--header=select the target commit' ]] && [[ "$*" =~ "diff --color" ]]; then
echo "commitdiff"
elif [[ "$*" =~ '--multi --preview ' ]] && [[ "$*" =~ "cat {}" ]]; then
echo "searchfile"
elif [[ "$*" =~ '--multi --preview ' ]] && [[ "$*" =~ "tree -L 1 -C --dirsfirst {}" ]]; then
echo "searchdir"
elif [[ "$*" =~ '--header=select files to stage' ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
echo "-- modifiedfile"
fi

Loading…
Cancel
Save