backup test

pull/3/head
kevin zhuang 4 years ago
parent 36e2798dde
commit 5a52e7d504

@ -33,6 +33,13 @@ function search_file() {
fi
}
#######################################
# chekc if fd and tree are available
# the reason to check output in unconventional way is
# because the status code is reused multiple times
# Outputs:
# status: 1 or 0
#######################################
function fd_exists() {
fd -V &>/dev/null
echo "$?"

@ -68,7 +68,7 @@ while getopts ":hsp:m" opt; do
*)
echo "Invalid option: ${OPTARG}" >&2
usage
exit 0
exit 1
;;
esac
done

@ -0,0 +1,48 @@
#!/usr/bin/env bats
setup() {
export DOTBARE_BACKUP="$HOME/.local/share/dotbare_test"
}
teardown() {
rm -r "$DOTBARE_BACKUP"
unset DOTBARE_BACKUP
}
help() {
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup -h
}
invalid_option() {
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup -f
}
backup() {
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup
}
individual_backup() {
cd "${BATS_TEST_DIRNAME}"
bash "${BATS_TEST_DIRNAME}"/../dotbare fbackup -p fadd.bats
}
@test "fbackup help" {
run help
[ "${status}" -eq 0 ]
}
@test "fbackup invalid option" {
run invalid_option
[ "${status}" -eq 1 ]
[ "${lines[0]}" = 'Invalid option: f' ]
}
@test "backup all files" {
run backup
[ "${status}" -eq 0 ]
}
@test "backup individual file" {
run individual_backup
[ "${status}" -eq 0 ]
}
Loading…
Cancel
Save