-
Notifications
You must be signed in to change notification settings - Fork 6
/
test
executable file
·95 lines (82 loc) · 2.43 KB
/
test
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env bash
main() {
set -e
(
echo "==> Testing git-get"
setup
cd "$($INSTALL_DIR/git-get https://github.com/pietvanzoen/git-get.git)"
assert_equal $(pwd) "$GIT_PATH/github.com/pietvanzoen/git-get" "sets correct repo path"
)
(
echo "==> Testing default prefix"
setup
export GIT_GET_DEFAULT_PREFIX="https://github.com/"
$INSTALL_DIR/git-get pietvanzoen/hint
assert_exists "$GIT_PATH/github.com/pietvanzoen/hint/.git" "clones repo using default prefix"
)
(
echo "==> Testing failed clone"
setup
$INSTALL_DIR/git-get https://github.com/pietvanzoen/wibble.git || true
assert_not_exists "$GIT_PATH/github.com/pietvanzoen" "does not create parent directory for failed clone"
$INSTALL_DIR/git-get https://github.com/pietvanzoen/hint.git
$INSTALL_DIR/git-get https://github.com/pietvanzoen/wibble.git || true
assert_exists "$GIT_PATH/github.com/pietvanzoen/hint" "does not remove parent directory for failed clone when another repo exists"
)
(
echo "==> Testing when path exists"
setup
$INSTALL_DIR/git-get https://github.com/pietvanzoen/hint.git
cd "$($INSTALL_DIR/git-get https://github.com/pietvanzoen/hint.git)"
assert_equal $(pwd) "$GIT_PATH/github.com/pietvanzoen/hint" "returns repo path when it has already been cloned"
)
(
echo "==> Testing when path exists and forced clone"
setup
$INSTALL_DIR/git-get https://github.com/pietvanzoen/hint.git
cd "$($INSTALL_DIR/git-get -f https://github.com/pietvanzoen/hint.git)"
assert_equal $(pwd) "$GIT_PATH/github.com/pietvanzoen/hint" "removes, reclones, and returns repo path"
)
}
setup() {
TEST_DIR="$(mktemp -d)"
export GIT_PATH="$TEST_DIR/repos"
export INSTALL_DIR="$TEST_DIR/bin"
mkdir -p $INSTALL_DIR
mkdir -p $GIT_PATH
./install
assert_exists "$INSTALL_DIR/git-get" "git-get was installed"
}
assert() {
if ! ($1); then
echo "FAIL: $2"
echo -e " expected $1 to pass"
exit 1
fi
echo "PASS: $2"
}
assert_equal() {
if [[ "$1" != "$2" ]]; then
echo "FAIL: $3"
echo -e " expected $2 \n but got $1"
exit 1
fi
echo "PASS: $3"
}
assert_exists() {
if ! [[ -s "$1" ]]; then
echo "FAIL: $2"
echo -e " expected $1 to exist with a size greater than zero"
exit 1
fi
echo "PASS: $2"
}
assert_not_exists() {
if [[ -s "$1" ]]; then
echo "FAIL: $2"
echo -e " expected $1 not to exist"
exit 1
fi
echo "PASS: $2"
}
main