-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot.bats
283 lines (213 loc) · 6.3 KB
/
dot.bats
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/usr/bin/env bats
# Copyright 2015 Sean Kelleher. All rights reserved.
# Use of this source code is governed by a GPL
# license that can be found in the LICENSE file.
dot=$PWD/dot
setup() {
cd $(mktemp -d -t 'tmp.XXXXXXXXXX')
export repo=$(mktemp -d -t 'tmp.XXXXXXXXXX')
git init --bare "$repo" | sed 's/^/[SETUP] /'
}
@test '`dot` outputs usage message' {
run bash "$dot"
[ "$status" -eq 1 ]
[ "$output" = "usage: $dot <repo> <base> [path]" ]
}
@test '`dot $repo` outputs usage message' {
run bash "$dot" "$repo"
[ "$status" -eq 1 ]
[ "$output" = "usage: $dot <repo> <base> [path]" ]
}
@test '`dot $repo $PWD/a b/file` outputs error message' {
mkdir b
run bash "$dot" "$repo" "$PWD/a" "b/file"
[ "$status" -eq 1 ]
[ "$output" = "'$PWD/b/file' is not in '$PWD/a'" ]
}
@test '`dot $repo $PWD file` adds `>file` to `$repo`' {
echo 'initial' > file
run bash "$dot" "$repo" "$PWD" file
[ "$status" -eq 0 ]
[ "$output" = "" ]
git clone "$repo" repo
diff repo/'>file' file
}
@test '`dot $repo $PWD file` outputs error if `git` not installed' {
echo 'initial' > file
echo 'echo >&2 "bash: git: command not found" && exit 127' > git
chmod +x git
PATH="$PWD:$PATH" run bash "$dot" "$repo" "$PWD" file
[ "$status" -eq 1 ]
[ "$output" = "Couldn't find \`git\` command" ]
}
@test '`dot $repo $PWD file` does not modify directory' {
echo 'initial' > file
old=$(ls -A)
run bash "$dot" "$repo" "$PWD" file
[ "$status" -eq 0 ]
[ "$output" = "" ]
[ "$old" = $(ls -A) ]
}
@test '`dot $repo $PWD .git` adds `>.git` to `$repo`' {
echo 'initial' > .git
run bash "$dot" "$repo" "$PWD" .git
[ "$status" -eq 0 ]
[ "$output" = "" ]
git clone "$repo" repo
diff repo/'>.git' .git
}
@test '`dot $repo / $PWD/file` adds file to `$repo`' {
echo 'initial' > file
run bash "$dot" "$repo" / "$PWD"/file
[ "$status" -eq 0 ]
[ "$output" = "" ]
git clone "$repo" repo
diff repo/*file file
}
@test '`dot $repo $PWD a b` adds `>a` and `>b` to `$repo`' {
echo 'a' > a
echo 'b' > b
run bash "$dot" "$repo" "$PWD" a b
[ "$status" -eq 0 ]
[ "$output" = "" ]
git clone "$repo" repo
diff repo/'>a' a
diff repo/'>b' b
}
@test '`dot $repo $PWD file` outputs error if `file` missing' {
run bash "$dot" "$repo" "$PWD" file
[ "$status" -eq 1 ]
echo $output
echo "No file at '$PWD/file'"
[ "$output" = "No file at '$PWD/file'" ]
}
@test '`dot $repo $PWD dir/file` adds `>dir>file` to `$repo`' {
mkdir dir
echo 'initial' > dir/file
run bash "$dot" "$repo" "$PWD" dir/file
[ "$status" -eq 0 ]
[ "$output" = "" ]
git clone "$repo" repo
diff repo/'>dir>file' dir/file
}
@test '`dot $repo $PWD dir/file` outputs error if `dir` missing' {
run bash "$dot" "$repo" "$PWD" dir/file
[ "$status" -eq 1 ]
[ "$output" = "Couldn't open 'dir'" ]
}
@test '`dot $repo $PWD dir/dir/file` adds `>dir>dir>file` to `$repo`' {
mkdir -p dir/dir
echo 'initial' > dir/dir/file
run bash "$dot" "$repo" "$PWD" dir/dir/file
[ "$status" -eq 0 ]
[ "$output" = "" ]
git clone "$repo" repo
diff repo/'>dir>dir>file' dir/dir/file
}
@test '`dot $repo $PWD/dir dir/dir/file` adds `>dir>file` to `$repo`' {
mkdir -p dir/dir
echo 'initial' > dir/dir/file
run bash "$dot" "$repo" "$PWD/dir" dir/dir/file
[ "$status" -eq 0 ]
[ "$output" = "" ]
git clone "$repo" repo
diff repo/'>dir>file' dir/dir/file
}
@test '`dot $repo $PWD file` when `file` unchanged outputs "No changes."' {
echo 'initial' > file
bash "$dot" "$repo" "$PWD" file
run bash "$dot" "$repo" "$PWD" file
[ "$status" -eq 1 ]
[ "$output" = "No changes." ]
}
@test '`dot $repo $PWD file` overwrites `file` in `$repo`' {
echo 'initial' > file
bash "$dot" "$repo" "$PWD" file
git clone "$repo" repo
diff repo/'>file' file
rm -rf repo
echo 'update' > file
bash "$dot" "$repo" "$PWD" file
git clone "$repo" repo
diff repo/'>file' file
}
@test '`dot $repo $PWD` creates `file` from `$repo` if missing' {
echo 'initial' > file
bash "$dot" "$repo" "$PWD" file
mv file file.bak
run bash "$dot" "$repo" "$PWD"
[ "$status" -eq 0 ]
[ "$output" = "" ]
diff file file.bak
}
@test '`dot $repo $PWD` creates path to `file` from `$repo` if missing' {
mkdir dir
echo 'initial' > dir/file
bash "$dot" "$repo" "$PWD" dir/file
mv dir dir.bak
run bash "$dot" "$repo" "$PWD"
[ "$status" -eq 0 ]
[ "$output" = "" ]
diff dir/file dir.bak/file
}
@test '`dot $repo $PWD` overwrites file if exists' {
echo 'initial' > file
bash "$dot" "$repo" "$PWD" file
cp file file.bak
echo 'update' > file
run bash "$dot" "$repo" "$PWD"
[ "$status" -eq 0 ]
[ "$output" = "" ]
diff file file.bak
}
@test '`dot $repo $PWD` retrieves multiple files from `$repo`' {
echo 'a' > a
echo 'b' > b
bash "$dot" "$repo" "$PWD" a b
mv a a.bak
mv b b.bak
bash "$dot" "$repo" "$PWD"
diff a a.bak
diff b b.bak
}
@test '`dot $repo $PWD` retrieves hidden files in `$repo`' {
echo 'initial' > .file
run bash "$dot" "$repo" "$PWD" .file
[ "$status" -eq 0 ]
[ "$output" = "" ]
mv .file .file.bak
run bash "$dot" "$repo" "$PWD"
[ "$status" -eq 0 ]
[ "$output" = "" ]
diff .file .file.bak
}
@test '`dot $repo $PWD` retrieves files with whitespace in `$repo`' {
echo 'first' > 'a tricky name'
run bash "$dot" "$repo" "$PWD" 'a tricky name'
[ "$status" -eq 0 ]
[ "$output" = "" ]
mv 'a tricky name' 'a tricky name.bak'
run bash "$dot" "$repo" "$PWD"
[ "$status" -eq 0 ]
[ "$output" = "" ]
diff 'a tricky name' 'a tricky name.bak'
}
@test '`dot $repo $PWD` handles `stdout` and `stderr` filenames' {
echo 'stdout' > stdout
echo 'stderr' > stderr
run bash "$dot" "$repo" "$PWD" stdout stderr
[ "$status" -eq 0 ]
[ "$output" = "" ]
git clone "$repo" repo
diff repo/'>stdout' stdout
diff repo/'>stderr' stderr
}
@test '`dot $repo $PWD/b` retrieves `file` pushed from `$PWD/a`' {
mkdir a
echo 'initial' > a/file
bash "$dot" "$repo" "$PWD/a" a/file
run bash "$dot" "$repo" "$PWD/b"
[ "$status" -eq 0 ]
[ "$output" = "" ]
diff a/file b/file
}