3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 function test_add_basic {
20 local testroot=`test_init add_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
29 echo "new file" > $testroot/wt/foo
31 echo 'A foo' > $testroot/stdout.expected
32 (cd $testroot/wt && got add foo > $testroot/stdout)
34 cmp -s $testroot/stdout.expected $testroot/stdout
36 if [ "$ret" != "0" ]; then
37 diff -u $testroot/stdout.expected $testroot/stdout
39 test_done "$testroot" "$ret"
42 function test_double_add {
43 local testroot=`test_init double_add`
45 got checkout $testroot/repo $testroot/wt > /dev/null
47 if [ "$ret" != "0" ]; then
48 test_done "$testroot" "$ret"
52 echo "new file" > $testroot/wt/foo
53 (cd $testroot/wt && got add foo > /dev/null)
55 (cd $testroot/wt && got add foo)
57 if [ "$ret" != "0" ]; then
58 echo "got add failed unexpectedly" >&2
59 test_done "$testroot" 1
63 test_done "$testroot" "$ret"
66 function test_add_multiple {
67 local testroot=`test_init multiple_add`
69 got checkout $testroot/repo $testroot/wt > /dev/null
71 if [ "$ret" != "0" ]; then
72 test_done "$testroot" "$ret"
76 echo "new file" > $testroot/wt/foo
77 echo "new file" > $testroot/wt/bar
78 echo "new file" > $testroot/wt/baz
79 (cd $testroot/wt && got add foo bar baz > $testroot/stdout)
81 if [ "$ret" != "0" ]; then
82 echo "got add failed unexpectedly" >&2
83 test_done "$testroot" 1
87 echo "A foo" > $testroot/stdout.expected
88 echo "A bar" >> $testroot/stdout.expected
89 echo "A baz" >> $testroot/stdout.expected
91 cmp -s $testroot/stdout.expected $testroot/stdout
93 if [ "$ret" != "0" ]; then
94 diff -u $testroot/stdout.expected $testroot/stdout
96 test_done "$testroot" "$ret"
99 function test_add_file_in_new_subdir {
100 local testroot=`test_init add_file_in_new_subdir`
102 got checkout $testroot/repo $testroot/wt > /dev/null
104 if [ "$ret" != "0" ]; then
105 test_done "$testroot" "$ret"
109 mkdir -p $testroot/wt/new
110 echo "new file" > $testroot/wt/new/foo
112 echo 'A new/foo' > $testroot/stdout.expected
113 (cd $testroot/wt && got add new/foo > $testroot/stdout)
115 cmp -s $testroot/stdout.expected $testroot/stdout
117 if [ "$ret" != "0" ]; then
118 diff -u $testroot/stdout.expected $testroot/stdout
120 test_done "$testroot" "$ret"
123 function test_add_deleted {
124 local testroot=`test_init add_deleted`
126 got checkout $testroot/repo $testroot/wt > /dev/null
128 if [ "$ret" != "0" ]; then
129 test_done "$testroot" "$ret"
133 (cd $testroot/wt && got rm beta > /dev/null)
135 echo -n > $testroot/stdout.expected
136 (cd $testroot/wt && got add beta > $testroot/stdout 2> $testroot/stderr)
138 if [ "$ret" == "0" ]; then
139 echo "got add command succeeded unexpectedly" >&2
140 diff -u $testroot/stdout.expected $testroot/stdout
141 test_done "$testroot" "1"
145 echo "got: beta: file has unexpected status" > $testroot/stderr.expected
146 cmp -s $testroot/stderr.expected $testroot/stderr
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stderr.expected $testroot/stderr
151 test_done "$testroot" "$ret"
154 function test_add_directory {
155 local testroot=`test_init add_directory`
157 got checkout $testroot/repo $testroot/wt > /dev/null
159 if [ "$ret" != "0" ]; then
160 test_done "$testroot" "$ret"
164 (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
166 if [ "$ret" == "0" ]; then
167 echo "got add command succeeded unexpectedly" >&2
168 test_done "$testroot" "1"
171 echo "got: adding directories requires -R option" \
172 > $testroot/stderr.expected
173 cmp -s $testroot/stderr.expected $testroot/stderr
175 if [ "$ret" != "0" ]; then
176 diff -u $testroot/stderr.expected $testroot/stderr
177 test_done "$testroot" "$ret"
181 echo -n > $testroot/stdout.expected
182 cmp -s $testroot/stdout.expected $testroot/stdout
184 if [ "$ret" != "0" ]; then
185 diff -u $testroot/stdout.expected $testroot/stdout
186 test_done "$testroot" "$ret"
190 (touch $testroot/wt/epsilon/zeta1 && touch $testroot/wt/epsilon/zeta2)
192 (cd $testroot/wt && got add -R . > $testroot/stdout)
194 echo 'A epsilon/zeta1' > $testroot/stdout.expected
195 echo 'A epsilon/zeta2' >> $testroot/stdout.expected
197 cmp -s $testroot/stdout.expected $testroot/stdout
199 if [ "$ret" != "0" ]; then
200 diff -u $testroot/stdout.expected $testroot/stdout
201 test_done "$testroot" "$ret"
205 echo "zeta" > $testroot/content.expected
206 cat $testroot/wt/epsilon/zeta > $testroot/content
208 cmp -s $testroot/content.expected $testroot/content
210 if [ "$ret" != "0" ]; then
211 diff -u $testroot/content.expected $testroot/content
213 test_done "$testroot" "$ret"
216 run_test test_add_basic
217 run_test test_double_add
218 run_test test_add_multiple
219 run_test test_add_file_in_new_subdir
220 run_test test_add_deleted
221 run_test test_add_directory