-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.sh
executable file
·131 lines (105 loc) · 2.57 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cleanup(){
cd "$(git rev-parse --show-toplevel)"
git reset HEAD
git clean -df .
exit "$1"
}
# Setup tests
git reset HEAD
git clean -df .
echo '/tests/ignored/test
/tests/ignored-dir/
/tests/ignored-dir-both/
' >> .gitignore
PATH="$(git rev-parse --show-toplevel):$PATH"
mkdir -p tests
cd tests
mkdir -p test-staged
touch test-staged/test
git add test-staged/test
mkdir -p test-unstaged
touch test-unstaged/test
mkdir -p test-empty
mkdir -p test-both
touch test-both/staged
touch test-both/unstaged
git add test-both/staged
mkdir -p ignored
touch ignored/test
mkdir -p ignored-dir
touch ignored-dir/test
mkdir -p ignored-dir-both
touch ignored-dir-both/unstaged
touch ignored-dir-both/staged
git add -f ignored-dir-both/staged
touch staged
touch unstaged
touch ignored
git add staged
# Start testing
# Test output
result="$(git ls -b -a)"
expected=$'ignored\tGitignored
ignored-dir\tGitignored
ignored-dir-both\tStaged
staged\tStaged
test-both\tStaged
test-empty\tEmpty
test-staged\tStaged
test-unstaged\tUntracked
unstaged\tUntracked'
if [ "$result" != "$expected" ]
then
cleanup 1
fi
# Test formatting
result="$(git ls -c -a)"
expected=$'ignored \tGitignored
ignored-dir \tGitignored
ignored-dir-both\tStaged
staged \tStaged
test-both \tStaged
test-empty \tEmpty
test-staged \tStaged
test-unstaged \tUntracked
unstaged \tUntracked'
if [ "$result" != "$expected" ]
then
cleanup 1
fi
# Test gitignored dir contents
result="$(git ls -b -a "ignored-dir")"
expected=$'test\tGitignored'
if [ "$result" != "$expected" ]
then
cleanup 1
fi
# Test gitignored dir with staged contents
result="$(git ls -b -a "ignored-dir-both")"
expected=$'staged\tStaged
unstaged\tGitignored'
if [ "$result" != "$expected" ]
then
cleanup 1
fi
# Test empty dir
result="$(git ls -b -a "test-empty")"
expected=""
if [ "$result" != "$expected" ]
then
cleanup 1
fi
cleanup 0