test(freset): update mock

pull/13/head
kevin zhuang 4 years ago
parent cca4157add
commit feaedf15be

@ -74,7 +74,7 @@ while [[ "$#" -gt 0 ]]; do
done
if [[ "${reset_type}" == "commit" ]]; then
selected_commit=$(get_commit)
selected_commit=$(get_commit "select the target commit for HEAD")
[[ -z "${selected_commit}" ]] && exit 0
[[ -z "${confirm}" ]] && confirm=$(get_confirmation "Reset HEAD to ${selected_commit} ${reset_option}?")
[[ "${confirm}" != 'y' ]] && exit 1
@ -83,6 +83,6 @@ else
while IFS= read -r line; do
selected_files+=("${line}")
done < <(get_modified_file 'select files to unstage' 'staged')
[[ "${#selected_files}" -eq 0 ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" reset HEAD "${selected_files[@]}"
[[ "${#selected_files[@]}" -eq 0 ]] && exit 1
/usr/bin/git --git-dir="${DOTBARE_DIR}" --work-tree="${DOTBARE_TREE}" reset "${selected_files[@]}"
fi

@ -34,29 +34,29 @@ select_files() {
[ "${lines[0]}" = "Invalid option: -p" ]
}
@test "freset no selection made" {
run no_selection_made
[ "${status}" -eq 1 ]
}
@test "freset select commit" {
run select_commit
if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then
[ "${lines[0]}" = "fatal: your current branch 'master' does not have any commits yet" ]
else
result=$(echo "${lines[0]}" | tr '`' "'")
[ "${result}" = "error: unknown option 'no-multi'" ]
[ "${result}" = "error: unknown option 'commitshow'" ]
fi
[ "${status}" -eq 129 ]
}
@test "freset no selection made" {
run no_selection_made
[ "${status}" -eq 1 ]
}
@test "freset select files" {
run select_files
if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then
[ "${status}" -eq 128 ]
[ "${lines[0]}" = "fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree." ]
else
[ "${status}" -eq 0 ]
[ -z "${output}" ]
[ "${status}" -eq 128 ]
[ "${lines[0]}" = "fatal: ambiguous argument '/Users/kevinzhuang/modifiedfile': unknown revision or path not in the working tree." ]
fi
}

@ -5,21 +5,36 @@
#
# usage:
# export PATH="${BATS_TEST_DIRNAME}:$PATH"
# example:
# echo "commitdiff" when attempting to mock a local file search
# error code 128
# fatal: pathspec '/Users/kevinzhuang/modifiedfile' did not match any files
# echo "-- modifiedfile" when attempting to mock a local file search
# error code 1 or code 128
# error: pathspec '/Users/kevinzhuang/modifiedfile' did not match any file(s) known to git
# echo "--branch" when attempting to mock branch commit
# error code 129
# error: unknown option `commitshow'
# use something like tr "`" "'" to avoid any potential error bats would raise
if [[ "$*" =~ "--header=select a commit to checkout" ]] && [[ "$*" =~ "show --color" ]]; then
echo "--commitshow"
elif [[ "$*" =~ '--no-multi --header=select the target commit for HEAD' ]] && [[ "$*" =~ "show --color" ]]; then
echo "--commitshow"
elif [[ "$*" =~ "--no-multi --header=select a branch to checkout" ]]; then
echo "--branch"
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 [[ "$*" =~ '--multi --preview ' ]] && [[ "$*" =~ "tree -L 1 -C --dirsfirst {}" ]]; then
echo "searchdir"
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 a file to checkout version in HEAD" ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
echo "-- modifiedfile"
elif [[ "$*" =~ '--header=select files to stage' ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
echo "-- modifiedfile"
elif [[ "$*" =~ "--header=select files to unstage" ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
echo "-- modifiedfile"
fi

Loading…
Cancel
Save