test: begin update all mocks

pull/17/head
Kevin Zhuang 4 years ago
parent abafd6b7af
commit cba4e36faa

@ -17,6 +17,7 @@ routing2() {
}
normal_git() {
export PATH="${BATS_TEST_DIRNAME}:$PATH"
"${BATS_TEST_DIRNAME}"/../dotbare add -h
}
@ -25,10 +26,14 @@ invalid_command() {
}
version() {
source "${BATS_TEST_DIRNAME}"/../helper/set_variable.sh
"${BATS_TEST_DIRNAME}"/../dotbare --version
}
no_argument() {
export PATH="${BATS_TEST_DIRNAME}:$PATH"
"${BATS_TEST_DIRNAME}"/../dotbare
}
@test "main help" {
run help
[ "${status}" -eq 0 ]
@ -61,10 +66,16 @@ version() {
@test "main git command" {
run normal_git
[ "${status}" -eq 129 ]
[ "${status}" -eq 0 ]
[[ "${output}" =~ "--git-dir=$DOTBARE_DIR --work-tree=$DOTBARE_TREE add -h" ]]
}
@test "main invliad command" {
run invalid_command
[ "${status}" -eq 1 ]
}
@test "main no argument" {
run no_argument
[[ "${output}" =~ "Available commands" ]]
}

@ -5,73 +5,5 @@
#
# usage:
# export PATH="${BATS_TEST_DIRNAME}:$PATH"
# example:
# echo "commitdiff" when attempting to mock a local file search
# error code 128
# fatal: pathspec '$HOME/modifiedfile' did not match any files
# echo "-- modifiedfile" when attempting to mock a local file search
# error code 1 or code 128
# error: pathspec '$HOME/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
# dotbare fcheckout --c -- "./fcheckout.bats" @test "fcheckout commit"
echo "--fcheckout_commit"
elif [[ "$*" =~ '--no-multi --header=select the target commit for HEAD' ]] && [[ "$*" =~ "show --color" ]]; then
# dotbare freset --commit -y -- "./freset.bats" @test "freset select commit"
echo "--freset_commit"
elif [[ "$*" =~ "--no-multi --header=select a commit to rename" ]] && [[ "$*" =~ "show --color=always" ]]; then
# dotbare fedit --commit -- "./fedit.bats" @test "fedit edit commits"
echo "fedit_commits"
elif [[ "$*" =~ '--header=select a commit' ]] && [[ "$*" =~ "show --color" ]]; then
# dotbare flog --reset -y -- "./flog.bats" @test "flog reset"
echo "--flog_reset"
elif [[ "$*" =~ "--no-multi --header=select a branch to checkout" ]]; then
# dotbare fcheckout --branch -- "./fcheckout.bats" @test "fcheckout branch"
echo "--fcheckout_branch"
elif [[ "$*" =~ '--header=select a file to checkout' ]] && [[ "$*" =~ "cat ${DOTBARE_TREE}/{}" ]]; then
# dotbare fcheckout --yes -s -- "./fcheckout.bats" @test "fcheckout select"
echo "fcheckout_select_gitfile"
elif [[ "$*" =~ '--header=select files to backup' ]] && [[ "$*" =~ "cat ${DOTBARE_TREE}/{}" ]]; then
# dotbare fbackup --select -- "./fbackup.bats" @test "fbackup select file"
echo "fbackup_select_file"
elif [[ "$*" =~ "--header=select files to untrack" ]] && [[ "$*" =~ "cat ${DOTBARE_TREE}/{}" ]]; then
# dotbare funtrack -- "./funtrack.bats" @test "funtrack untrack file"
echo "funtrack_file"
elif [[ "$*" =~ '--multi --preview ' ]] && [[ "$*" =~ "tree -L 1 -C --dirsfirst {}" ]]; then
# dotbare fadd --dir -- "./fadd.bats" @test "fadd stage selected dir"
echo "fadd_stage_dir"
elif [[ "$*" =~ '--header=select the target commit' ]] && [[ "$*" =~ "diff --color" ]]; then
# dotbare fcheckout --yes -s -- "./fcheckout.bats" @test "fcheckout select"
echo "fcheckout_select_commitdiff"
elif [[ "$*" =~ '--multi --preview ' ]] && [[ "$*" =~ "cat {}" ]]; then
# dotbare fadd -f -- "./fadd.bats" @test "fadd stage selected file"
echo "fadd_stage_file"
elif [[ "$*" =~ '--header=select files to add to a stash' ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
# dotbare fstash -s -- "./fstash.bats" @test "fstash stash select file"
echo "-- fstash_select"
elif [[ "$*" =~ '--header=select stash to delete' ]] && [[ "$*" =~ "show -p __ --color=always" ]]; then
# dotbare fstash --delete -- "./fstash.bats" @test "fstash stash delete"
echo "fstash_delete"
elif [[ "$*" =~ '--header=select stash to apply' ]] && [[ "$*" =~ "show -p __ --color=always" ]]; then
# dotbare fstash -- "./fstash.bats" @test "fstash apply stash"
echo "fstash_apply"
elif [[ "$*" =~ "--header=select a file to checkout version in HEAD" ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
# dotbare fcheckout -y -- "./fcheckout.bats" @test "fcheckout modified"
echo "-- fcheckout_modified"
elif [[ "$*" =~ '--header=select files to stage' ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
# dotbare fadd -- "./fadd.bats" @test "fadd stage modified files"
echo "-- fadd_add_modified"
elif [[ "$*" =~ "--header=select files to unstage" ]] && [[ "$*" =~ "diff HEAD --color=always" ]]; then
# dotbare freset -- "./freset.bats" @test "freset select files"
echo "-- freset_file"
elif [[ "$*" =~ "--header=select tracked files to edit" ]]; then
# dotbare fedit -- "./fedit.bats" @test "fedit edit files"
exit
elif [[ "$*" =~ "--no-multi --header=commit --flog_reset" ]]; then
# dotbare flog -- "./flog.bats" @test "flog checkout routing"
echo "exit"
fi
echo "$@"

@ -0,0 +1,9 @@
#!/usr/bin/env bash
#
# This script is for mocking git during unit test,
# used to mock all the git calls.
#
# usage:
# export PATH="${BATS_TEST_DIRNAME}:$PATH"
echo "$@"

@ -1,7 +1,8 @@
#!/usr/bin/env bash
#
# This script is for mocking fzf for testing,
# it will stop fzf for goin into a interactive mode
# This script is for mocking tree during unit test,
# just that we don't need install tree during different
# test environment.
#
# usage:
# export PATH="${BATS_TEST_DIRNAME}:$PATH"

Loading…
Cancel
Save