Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
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.
8 #
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.
17 . ./common.sh
19 function test_add_basic {
20 local testroot=`test_init add_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
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
35 ret="$?"
36 if [ "$ret" != "0" ]; then
37 diff -u $testroot/stdout.expected $testroot/stdout
38 fi
39 test_done "$testroot" "$ret"
40 }
42 function test_double_add {
43 local testroot=`test_init double_add`
45 got checkout $testroot/repo $testroot/wt > /dev/null
46 ret="$?"
47 if [ "$ret" != "0" ]; then
48 test_done "$testroot" "$ret"
49 return 1
50 fi
52 echo "new file" > $testroot/wt/foo
53 (cd $testroot/wt && got add foo > /dev/null)
55 (cd $testroot/wt && got add foo)
56 ret="$?"
57 if [ "$ret" != "0" ]; then
58 echo "got add failed unexpectedly" >&2
59 test_done "$testroot" 1
60 return 1
61 fi
63 test_done "$testroot" "$ret"
64 }
66 function test_add_multiple {
67 local testroot=`test_init multiple_add`
69 got checkout $testroot/repo $testroot/wt > /dev/null
70 ret="$?"
71 if [ "$ret" != "0" ]; then
72 test_done "$testroot" "$ret"
73 return 1
74 fi
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)
80 ret="$?"
81 if [ "$ret" != "0" ]; then
82 echo "got add failed unexpectedly" >&2
83 test_done "$testroot" 1
84 return 1
85 fi
87 echo "A bar" > $testroot/stdout.expected
88 echo "A baz" >> $testroot/stdout.expected
89 echo "A foo" >> $testroot/stdout.expected
91 cmp -s $testroot/stdout.expected $testroot/stdout
92 ret="$?"
93 if [ "$ret" != "0" ]; then
94 diff -u $testroot/stdout.expected $testroot/stdout
95 fi
96 test_done "$testroot" "$ret"
97 }
99 run_test test_add_basic
100 run_test test_double_add
101 run_test test_add_multiple