summaryrefslogtreecommitdiff
path: root/test/test-lib.bash
blob: fba9aa0e683f8fbb50b97c37a1a2f3bfe96e300c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
DEBUG=${DEBUG:-false}
DOTBOT_EXEC="${BASEDIR}/bin/dotbot"
DOTFILES="/home/$(whoami)/dotfiles"
INSTALL_CONF='install.conf.yaml'
INSTALL_CONF_JSON='install.conf.json'

test_run_() {
    if ! ${DEBUG}; then
        (eval "$*") >/dev/null 2>&1
    else
        (eval "$*")
    fi
}

test_expect_success() {
    local tag=${1} && shift
    if ! test_run_ "$@"; then
        >&2 echo "- ${tag} failed."
        exit 1
    fi
}

test_expect_failure() {
    local tag=${1} && shift
    if test_run_ "$@"; then
        >&2 echo "- ${tag} failed."
        exit 1
    fi
}

check_env() {
    if [ "${DOTBOT_TEST}" != "true" ]; then
        >&2 echo "test must be run by test driver"
        exit 1
    fi
}

initialize() {
    check_env
    echo "${test_description}"
    mkdir -p "${DOTFILES}"
    cd
}

run_dotbot() {
    (
        cat > "${DOTFILES}/${INSTALL_CONF}"
        ${DOTBOT_EXEC} -c "${DOTFILES}/${INSTALL_CONF}" "${@}"
    )
}

run_dotbot_json() {
    (
        cat > "${DOTFILES}/${INSTALL_CONF_JSON}"
        ${DOTBOT_EXEC} -c "${DOTFILES}/${INSTALL_CONF_JSON}" "${@}"
    )
}

initialize