Blame


1 6dbf1e9e 2019-03-26 stsp #!/bin/sh
2 6dbf1e9e 2019-03-26 stsp #
3 6dbf1e9e 2019-03-26 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 6dbf1e9e 2019-03-26 stsp #
5 6dbf1e9e 2019-03-26 stsp # Permission to use, copy, modify, and distribute this software for any
6 6dbf1e9e 2019-03-26 stsp # purpose with or without fee is hereby granted, provided that the above
7 6dbf1e9e 2019-03-26 stsp # copyright notice and this permission notice appear in all copies.
8 6dbf1e9e 2019-03-26 stsp #
9 6dbf1e9e 2019-03-26 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 6dbf1e9e 2019-03-26 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 6dbf1e9e 2019-03-26 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 6dbf1e9e 2019-03-26 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 6dbf1e9e 2019-03-26 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 6dbf1e9e 2019-03-26 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 6dbf1e9e 2019-03-26 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 6dbf1e9e 2019-03-26 stsp
17 6dbf1e9e 2019-03-26 stsp . ./common.sh
18 6dbf1e9e 2019-03-26 stsp
19 6dbf1e9e 2019-03-26 stsp function test_add_basic {
20 6dbf1e9e 2019-03-26 stsp local testroot=`test_init add_basic`
21 6dbf1e9e 2019-03-26 stsp
22 6dbf1e9e 2019-03-26 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 6dbf1e9e 2019-03-26 stsp ret="$?"
24 6dbf1e9e 2019-03-26 stsp if [ "$ret" != "0" ]; then
25 6dbf1e9e 2019-03-26 stsp test_done "$testroot" "$ret"
26 6dbf1e9e 2019-03-26 stsp return 1
27 6dbf1e9e 2019-03-26 stsp fi
28 6dbf1e9e 2019-03-26 stsp
29 6dbf1e9e 2019-03-26 stsp echo "new file" > $testroot/wt/foo
30 6dbf1e9e 2019-03-26 stsp
31 6dbf1e9e 2019-03-26 stsp echo 'A foo' > $testroot/stdout.expected
32 6dbf1e9e 2019-03-26 stsp (cd $testroot/wt && got add foo > $testroot/stdout)
33 6dbf1e9e 2019-03-26 stsp
34 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
35 6dbf1e9e 2019-03-26 stsp ret="$?"
36 6dbf1e9e 2019-03-26 stsp if [ "$ret" != "0" ]; then
37 6dbf1e9e 2019-03-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
38 6dbf1e9e 2019-03-26 stsp fi
39 6dbf1e9e 2019-03-26 stsp test_done "$testroot" "$ret"
40 6dbf1e9e 2019-03-26 stsp }
41 6dbf1e9e 2019-03-26 stsp
42 5c99ca9f 2019-03-27 stsp function test_double_add {
43 5c99ca9f 2019-03-27 stsp local testroot=`test_init double_add`
44 5c99ca9f 2019-03-27 stsp
45 5c99ca9f 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
46 5c99ca9f 2019-03-27 stsp ret="$?"
47 5c99ca9f 2019-03-27 stsp if [ "$ret" != "0" ]; then
48 5c99ca9f 2019-03-27 stsp test_done "$testroot" "$ret"
49 5c99ca9f 2019-03-27 stsp return 1
50 5c99ca9f 2019-03-27 stsp fi
51 5c99ca9f 2019-03-27 stsp
52 5c99ca9f 2019-03-27 stsp echo "new file" > $testroot/wt/foo
53 5c99ca9f 2019-03-27 stsp (cd $testroot/wt && got add foo > /dev/null)
54 5c99ca9f 2019-03-27 stsp
55 723c305c 2019-05-11 jcs (cd $testroot/wt && got add foo)
56 5c99ca9f 2019-03-27 stsp ret="$?"
57 723c305c 2019-05-11 jcs if [ "$ret" != "0" ]; then
58 723c305c 2019-05-11 jcs echo "got add failed unexpectedly" >&2
59 5c99ca9f 2019-03-27 stsp test_done "$testroot" 1
60 a7c182ac 2019-03-27 stsp return 1
61 5c99ca9f 2019-03-27 stsp fi
62 5c99ca9f 2019-03-27 stsp
63 723c305c 2019-05-11 jcs test_done "$testroot" "$ret"
64 723c305c 2019-05-11 jcs }
65 723c305c 2019-05-11 jcs
66 723c305c 2019-05-11 jcs function test_add_multiple {
67 723c305c 2019-05-11 jcs local testroot=`test_init multiple_add`
68 723c305c 2019-05-11 jcs
69 723c305c 2019-05-11 jcs got checkout $testroot/repo $testroot/wt > /dev/null
70 5c99ca9f 2019-03-27 stsp ret="$?"
71 5c99ca9f 2019-03-27 stsp if [ "$ret" != "0" ]; then
72 723c305c 2019-05-11 jcs test_done "$testroot" "$ret"
73 723c305c 2019-05-11 jcs return 1
74 5c99ca9f 2019-03-27 stsp fi
75 723c305c 2019-05-11 jcs
76 723c305c 2019-05-11 jcs echo "new file" > $testroot/wt/foo
77 723c305c 2019-05-11 jcs echo "new file" > $testroot/wt/bar
78 723c305c 2019-05-11 jcs echo "new file" > $testroot/wt/baz
79 2b01eb6c 2019-05-11 stsp (cd $testroot/wt && got add foo bar baz > $testroot/stdout)
80 723c305c 2019-05-11 jcs ret="$?"
81 723c305c 2019-05-11 jcs if [ "$ret" != "0" ]; then
82 723c305c 2019-05-11 jcs echo "got add failed unexpectedly" >&2
83 723c305c 2019-05-11 jcs test_done "$testroot" 1
84 723c305c 2019-05-11 jcs return 1
85 723c305c 2019-05-11 jcs fi
86 723c305c 2019-05-11 jcs
87 6d022e97 2019-08-04 stsp echo "A foo" > $testroot/stdout.expected
88 6d022e97 2019-08-04 stsp echo "A bar" >> $testroot/stdout.expected
89 2b01eb6c 2019-05-11 stsp echo "A baz" >> $testroot/stdout.expected
90 2b01eb6c 2019-05-11 stsp
91 8d301dd9 2019-05-14 stsp cmp -s $testroot/stdout.expected $testroot/stdout
92 2b01eb6c 2019-05-11 stsp ret="$?"
93 2b01eb6c 2019-05-11 stsp if [ "$ret" != "0" ]; then
94 2b01eb6c 2019-05-11 stsp diff -u $testroot/stdout.expected $testroot/stdout
95 2b01eb6c 2019-05-11 stsp fi
96 5c99ca9f 2019-03-27 stsp test_done "$testroot" "$ret"
97 5c99ca9f 2019-03-27 stsp }
98 5c99ca9f 2019-03-27 stsp
99 a9fa2909 2019-07-27 stsp function test_add_file_in_new_subdir {
100 a9fa2909 2019-07-27 stsp local testroot=`test_init add_file_in_new_subdir`
101 a9fa2909 2019-07-27 stsp
102 a9fa2909 2019-07-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
103 a9fa2909 2019-07-27 stsp ret="$?"
104 a9fa2909 2019-07-27 stsp if [ "$ret" != "0" ]; then
105 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
106 a9fa2909 2019-07-27 stsp return 1
107 a9fa2909 2019-07-27 stsp fi
108 a9fa2909 2019-07-27 stsp
109 a9fa2909 2019-07-27 stsp mkdir -p $testroot/wt/new
110 a9fa2909 2019-07-27 stsp echo "new file" > $testroot/wt/new/foo
111 a9fa2909 2019-07-27 stsp
112 a9fa2909 2019-07-27 stsp echo 'A new/foo' > $testroot/stdout.expected
113 a9fa2909 2019-07-27 stsp (cd $testroot/wt && got add new/foo > $testroot/stdout)
114 a9fa2909 2019-07-27 stsp
115 a9fa2909 2019-07-27 stsp cmp -s $testroot/stdout.expected $testroot/stdout
116 a9fa2909 2019-07-27 stsp ret="$?"
117 a9fa2909 2019-07-27 stsp if [ "$ret" != "0" ]; then
118 a9fa2909 2019-07-27 stsp diff -u $testroot/stdout.expected $testroot/stdout
119 a9fa2909 2019-07-27 stsp fi
120 a9fa2909 2019-07-27 stsp test_done "$testroot" "$ret"
121 a9fa2909 2019-07-27 stsp }
122 a9fa2909 2019-07-27 stsp
123 6d022e97 2019-08-04 stsp function test_add_deleted {
124 6d022e97 2019-08-04 stsp local testroot=`test_init add_deleted`
125 6d022e97 2019-08-04 stsp
126 6d022e97 2019-08-04 stsp got checkout $testroot/repo $testroot/wt > /dev/null
127 6d022e97 2019-08-04 stsp ret="$?"
128 6d022e97 2019-08-04 stsp if [ "$ret" != "0" ]; then
129 6d022e97 2019-08-04 stsp test_done "$testroot" "$ret"
130 6d022e97 2019-08-04 stsp return 1
131 6d022e97 2019-08-04 stsp fi
132 6d022e97 2019-08-04 stsp
133 6d022e97 2019-08-04 stsp (cd $testroot/wt && got rm beta > /dev/null)
134 6d022e97 2019-08-04 stsp
135 6d022e97 2019-08-04 stsp echo -n > $testroot/stdout.expected
136 6d022e97 2019-08-04 stsp (cd $testroot/wt && got add beta > $testroot/stdout 2> $testroot/stderr)
137 6d022e97 2019-08-04 stsp ret="$?"
138 6d022e97 2019-08-04 stsp if [ "$ret" == "0" ]; then
139 6d022e97 2019-08-04 stsp echo "got add command succeeded unexpectedly" >&2
140 6d022e97 2019-08-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
141 6d022e97 2019-08-04 stsp test_done "$testroot" "1"
142 6d022e97 2019-08-04 stsp return 1
143 6d022e97 2019-08-04 stsp fi
144 6d022e97 2019-08-04 stsp
145 6d022e97 2019-08-04 stsp echo "got: beta: file has unexpected status" > $testroot/stderr.expected
146 6d022e97 2019-08-04 stsp cmp -s $testroot/stderr.expected $testroot/stderr
147 6d022e97 2019-08-04 stsp ret="$?"
148 6d022e97 2019-08-04 stsp if [ "$ret" != "0" ]; then
149 6d022e97 2019-08-04 stsp diff -u $testroot/stderr.expected $testroot/stderr
150 6d022e97 2019-08-04 stsp fi
151 6d022e97 2019-08-04 stsp test_done "$testroot" "$ret"
152 6d022e97 2019-08-04 stsp }
153 6d022e97 2019-08-04 stsp
154 4e68cba3 2019-11-23 stsp function test_add_directory {
155 4e68cba3 2019-11-23 stsp local testroot=`test_init add_directory`
156 4e68cba3 2019-11-23 stsp
157 4e68cba3 2019-11-23 stsp got checkout $testroot/repo $testroot/wt > /dev/null
158 4e68cba3 2019-11-23 stsp ret="$?"
159 4e68cba3 2019-11-23 stsp if [ "$ret" != "0" ]; then
160 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
161 4e68cba3 2019-11-23 stsp return 1
162 4e68cba3 2019-11-23 stsp fi
163 4e68cba3 2019-11-23 stsp
164 4e68cba3 2019-11-23 stsp (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
165 4e68cba3 2019-11-23 stsp ret="$?"
166 4e68cba3 2019-11-23 stsp if [ "$ret" == "0" ]; then
167 4e68cba3 2019-11-23 stsp echo "got add command succeeded unexpectedly" >&2
168 4e68cba3 2019-11-23 stsp test_done "$testroot" "1"
169 4e68cba3 2019-11-23 stsp return 1
170 4e68cba3 2019-11-23 stsp fi
171 4e68cba3 2019-11-23 stsp echo "got: adding directories requires -R option" \
172 4e68cba3 2019-11-23 stsp > $testroot/stderr.expected
173 4e68cba3 2019-11-23 stsp cmp -s $testroot/stderr.expected $testroot/stderr
174 4e68cba3 2019-11-23 stsp ret="$?"
175 4e68cba3 2019-11-23 stsp if [ "$ret" != "0" ]; then
176 4e68cba3 2019-11-23 stsp diff -u $testroot/stderr.expected $testroot/stderr
177 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
178 4e68cba3 2019-11-23 stsp return 1
179 4e68cba3 2019-11-23 stsp fi
180 4e68cba3 2019-11-23 stsp
181 4e68cba3 2019-11-23 stsp echo -n > $testroot/stdout.expected
182 4e68cba3 2019-11-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
183 4e68cba3 2019-11-23 stsp ret="$?"
184 4e68cba3 2019-11-23 stsp if [ "$ret" != "0" ]; then
185 4e68cba3 2019-11-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
186 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
187 4e68cba3 2019-11-23 stsp return 1
188 4e68cba3 2019-11-23 stsp fi
189 4e68cba3 2019-11-23 stsp
190 4e68cba3 2019-11-23 stsp (touch $testroot/wt/epsilon/zeta1 && touch $testroot/wt/epsilon/zeta2)
191 4e68cba3 2019-11-23 stsp
192 4e68cba3 2019-11-23 stsp (cd $testroot/wt && got add -R . > $testroot/stdout)
193 4e68cba3 2019-11-23 stsp
194 4e68cba3 2019-11-23 stsp echo 'A epsilon/zeta1' > $testroot/stdout.expected
195 4e68cba3 2019-11-23 stsp echo 'A epsilon/zeta2' >> $testroot/stdout.expected
196 4e68cba3 2019-11-23 stsp
197 4e68cba3 2019-11-23 stsp cmp -s $testroot/stdout.expected $testroot/stdout
198 4e68cba3 2019-11-23 stsp ret="$?"
199 4e68cba3 2019-11-23 stsp if [ "$ret" != "0" ]; then
200 4e68cba3 2019-11-23 stsp diff -u $testroot/stdout.expected $testroot/stdout
201 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
202 4e68cba3 2019-11-23 stsp return 1
203 4e68cba3 2019-11-23 stsp fi
204 4e68cba3 2019-11-23 stsp
205 4e68cba3 2019-11-23 stsp echo "zeta" > $testroot/content.expected
206 4e68cba3 2019-11-23 stsp cat $testroot/wt/epsilon/zeta > $testroot/content
207 4e68cba3 2019-11-23 stsp
208 4e68cba3 2019-11-23 stsp cmp -s $testroot/content.expected $testroot/content
209 4e68cba3 2019-11-23 stsp ret="$?"
210 4e68cba3 2019-11-23 stsp if [ "$ret" != "0" ]; then
211 4e68cba3 2019-11-23 stsp diff -u $testroot/content.expected $testroot/content
212 4e68cba3 2019-11-23 stsp fi
213 4e68cba3 2019-11-23 stsp test_done "$testroot" "$ret"
214 4e68cba3 2019-11-23 stsp }
215 4e68cba3 2019-11-23 stsp
216 6dbf1e9e 2019-03-26 stsp run_test test_add_basic
217 5c99ca9f 2019-03-27 stsp run_test test_double_add
218 2b01eb6c 2019-05-11 stsp run_test test_add_multiple
219 a9fa2909 2019-07-27 stsp run_test test_add_file_in_new_subdir
220 6d022e97 2019-08-04 stsp run_test test_add_deleted
221 4e68cba3 2019-11-23 stsp run_test test_add_directory