-
Notifications
You must be signed in to change notification settings - Fork 5
/
test.sh
executable file
·116 lines (102 loc) · 2.04 KB
/
test.sh
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
#! /usr/bin/env atf-sh
set_up() {
# Install goat into the test directory.
prefix="$PWD/usr"
make -C "$(atf_get_srcdir)" PREFIX="$prefix" install
# Prepare environment.
goat="${prefix}/bin/goat"
libgoat="${prefix}/share/goat/libgoat.sh"
export GOAT_PATH="${PWD}/var/db/goat"
# Set up some directories.
mkdir -p 1/2/3
}
atf_test_case goat
goat_head() { atf_set "descr" "Test goat(1)"; }
goat_body() {
set_up
# Check that goat can create aliases.
$goat link l1 1
$goat link l2 1/2
atf_check test -L ${GOAT_PATH}/l1
atf_check -o "match:^${PWD}/1$" readlink ${GOAT_PATH}/l1
}
atf_test_case cd
cd_head() { atf_set "descr" "Test the custom cd(1) command"; }
cd_body() {
set_up
$goat link l1 1
$goat link l2 1/2
$goat link l3 1/2/3
# Check that libgoat is sourceable.
atf_check sh -c ". '$libgoat'"
# Check that standard cd(1) functionalities still work as expected.
atf_check -o "match:^$PWD$" sh -e <<-EOF
. "$libgoat"
cd "$PWD"
pwd
EOF
atf_check -e "match:No such file or directory" -s "not-exit:0" sh -e <<-EOF
. "$libgoat"
cd nonexistent
pwd
EOF
# Check that cd(1) can follow aliases.
atf_check -o "match:^$PWD/1$" sh -e <<-EOF
. "$libgoat"
cd l1
pwd
EOF
# Check that "cd -" works.
atf_check -o "match:^$PWD/1$" sh -e <<-EOF
. "$libgoat"
cd l1
cd l2
cd -
pwd
EOF
# Check that "cd ." works.
atf_check -o "match:^$PWD/1$" sh -e <<-EOF
. "$libgoat"
cd l1
cd .
pwd
EOF
# Check that "cd .." works.
atf_check -o "match:^$PWD/1$" sh -e <<-EOF
. "$libgoat"
cd l2
cd ..
pwd
EOF
# Check that "cd ..." works.
atf_check -o "match:^$PWD/1$" sh -e <<-EOF
. "$libgoat"
cd l3
cd ...
pwd
EOF
# Check that cd(1) prefers directories in $PWD over aliases.
atf_check -o "match:^$PWD/l1$" sh -e <<-EOF
. "$libgoat"
mkdir l1
cd l1
pwd
cd ..
rmdir l1
EOF
# Check that if two or more arguments are passed to cd(1), then aliases
# are not considered.
atf_check -o "match:^$PWD/l1$" sh -e <<-EOF
. "$libgoat"
mkdir l1
cd -- l1
pwd
cd ..
rmdir l1
EOF
}
atf_init_test_cases()
{
atf_add_test_case goat
atf_add_test_case cd
}