test(fbackup): more coverage for fbackup

pull/13/head
kevin zhuang 4 years ago
parent 38c59f83de
commit 036b3f7a71

@ -9,10 +9,10 @@
# ${selected_files}: selected files to backup
# ${action_command}: actions to run, cp|mv
# Arguments
# -h: show help message and exit
# -s: select individual files through fzf and backup
# -p: pass in path and backup
# -m: use mv to backup instead of cp
# -h|--help: show help message and exit
# -s|--select: select individual files through fzf and backup
# -p|--path: pass in path and backup
# -m|--move: use mv to backup instead of cp
set -e
set -f

@ -6,7 +6,7 @@ setup() {
}
teardown() {
[ -d "${DOTBARE_BACKUP}" ] && rm -r "$DOTBARE_BACKUP"
[ -d "${DOTBARE_BACKUP}" ] && rm -r "${DOTBARE_BACKUP}"
unset DOTBARE_BACKUP
}
@ -27,8 +27,14 @@ individual_backup() {
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup -p fadd.bats
}
check_empty() {
bash "${BATS_TEST_DIRNAME}"/../dotbare log
move_file() {
touch bats_test.txt
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup --path bats_test.txt -m
}
select_file() {
export PATH="${BATS_TEST_DIRNAME}:$PATH"
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup --select
}
@test "fbackup help" {
@ -39,18 +45,17 @@ check_empty() {
@test "fbackup invalid option" {
run invalid_option
[ "${status}" -eq 1 ]
[ "${lines[0]}" = 'Invalid option: f' ]
[ "${lines[0]}" = 'Invalid option: -f' ]
}
@test "fbackup backup all files" {
run check_empty
if [ "${status}" -eq 0 ]; then
if ! "${BATS_TEST_DIRNAME}"/../dotbare log &>/dev/null; then
run backup
[ "${status}" -eq 0 ]
[ -f "${DOTBARE_BACKUP}"/.bashrc ]
[ "${status}" -eq 1 ]
else
run backup
[ "${status}" -eq 1 ]
[ "${status}" -eq 0 ]
[ -f "${DOTBARE_BACKUP}"/.bashrc ]
fi
}
@ -59,3 +64,16 @@ check_empty() {
[ "${status}" -eq 0 ]
[ -f "${DOTBARE_BACKUP}"/fadd.bats ]
}
@test "fbackup move file" {
run move_file
[ "${status}" -eq 0 ]
[ -f "${DOTBARE_BACKUP}"/bats_test.txt ]
[ ! -f "${BATS_TEST_DIRNAME}"/bats_test.txt ]
}
@test "fbackup select file" {
run select_file
[ "${status}" -eq 1 ]
[[ "${output}" =~ 'cp: selectgitfile: No such file or directory' ]]
}

@ -25,6 +25,8 @@ elif [[ "$*" =~ "--no-multi --header=select a branch to checkout" ]]; then
echo "--branch"
elif [[ "$*" =~ '--header=select a file to checkout' ]] && [[ "$*" =~ "cat" ]]; then
echo "selectgitfile"
elif [[ "$*" =~ '--header=select files to backup' ]] && [[ "$*" =~ "cat" ]]; then
echo "selectgitfile"
elif [[ "$*" =~ '--multi --preview ' ]] && [[ "$*" =~ "tree -L 1 -C --dirsfirst {}" ]]; then
echo "searchdir"
elif [[ "$*" =~ '--header=select the target commit' ]] && [[ "$*" =~ "diff --color" ]]; then

Loading…
Cancel
Save