-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·135 lines (116 loc) · 3.59 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#! /bin/sh -
#
# test - Test suite for goat.
#
# Usage: ./test
#
# Environmental variables:
# - GOAT_PATH -- A place where goat should live.
# - DEBUG -- A non-empty string will result in extra details being printed.
#
# ---
#
# Copyright (c) 2017 Mateusz Piotrowski <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
set -eu
[ -n "${DEBUG:-}" ] && set -x
err()
{
printf "%s\n" "$@" 1>&2
}
clean_up()
{
set +e
if expr "$GOAT_PATH" : '/tmp/goat-test-*' 1>/dev/null &&
[ -d "$GOAT_PATH" ]
then
rm -fr -- "$GOAT_PATH"
else
err "Skipping the removal of '$GOAT_PATH'"
fi
}
set_up()
{
mkdir -p "$GOAT_PATH/uno/dos/tres"
command cd "$GOAT_PATH"
"$goat" link one "$GOAT_PATH/uno"
"$goat" link two "$GOAT_PATH/uno/dos"
"$goat" link three "$GOAT_PATH/uno/dos/tres"
"$goat" 1 uno
command cd uno/dos/tres
"$goat" 2 ..
"$goat" 3 .
command cd "$GOAT_PATH"
"$goat" drei "$GOAT_PATH/uno/dos/tres"
}
test_case()
{
oldpwd="$PWD"
srcpwd="$1"
link="$2"
destdir="$3"
command cd "$srcpwd"
cd "$link"
test x"${PWD##/*/}" = x"$destdir"
command cd "$oldpwd"
}
trap clean_up EXIT
goat="$PWD/goat"
export GOAT_PATH="${TEST_PATH:-"/tmp/goat-test-$$-$(date +%Y-%m-%d-%H-%M-%S)"}"
libgoat="$PWD/libgoat.sh"
. "$libgoat"
set_up
test_case "$PWD" "one" "uno"
test_case "$PWD/uno" "two" "dos"
test_case "$PWD/uno/dos" "three" "tres"
test_case "$GOAT_PATH" "1" "uno"
test_case "$GOAT_PATH" "2" "dos"
test_case "$GOAT_PATH" "3" "tres"
test_case "$GOAT_PATH/uno/dos/tres" "..." "uno"
test_case "$GOAT_PATH/uno/dos/tres" "...." "$(basename -- "$GOAT_PATH")"
"$goat" list | grep drei 1>/dev/null
rmdir "$GOAT_PATH/uno/dos/tres"
"$goat" drei "$GOAT_PATH/uno/dos/tres" || :
"$goat" fix
"$goat" list | grep -v drei 1>/dev/null
"$goat" nuke
test x = x"$("$goat" list)"
# Test `goat delete` for more than 1 argument.
set_up
"$goat" delete one three
"$goat" list | grep -v one 1>/dev/null
"$goat" list | grep -v three 1>/dev/null
# Test `goat deleteprefix`.
set_up
"$goat" link three2 "$GOAT_PATH/uno/dos/tres"
"$goat" link three3 "$GOAT_PATH/uno/dos/tres"
"$goat" link three4 "$GOAT_PATH/uno/dos/tres"
"$goat" deleteprefix "$GOAT_PATH/uno/dos"
"$goat" list | grep -v two 1>/dev/null
"$goat" list | grep -v three 1>/dev/null
"$goat" list | grep -v three2 1>/dev/null
"$goat" list | grep -v three3 1>/dev/null
"$goat" list | grep -v three4 1>/dev/null
echo OK
# vim: filetype=sh softtabstop=8 shiftwidth=8 tabstop=8 noexpandtab