3 a129376b 2019-03-28 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
5 a129376b 2019-03-28 stsp # Permission to use, copy, modify, and distribute this software for any
6 a129376b 2019-03-28 stsp # purpose with or without fee is hereby granted, provided that the above
7 a129376b 2019-03-28 stsp # copyright notice and this permission notice appear in all copies.
9 a129376b 2019-03-28 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 a129376b 2019-03-28 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 a129376b 2019-03-28 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 a129376b 2019-03-28 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 a129376b 2019-03-28 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 a129376b 2019-03-28 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 a129376b 2019-03-28 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 a129376b 2019-03-28 stsp . ./common.sh
19 a129376b 2019-03-28 stsp function test_revert_basic {
20 a129376b 2019-03-28 stsp local testroot=`test_init revert_basic`
22 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
24 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
25 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
29 a129376b 2019-03-28 stsp echo "modified alpha" > $testroot/wt/alpha
31 a129376b 2019-03-28 stsp echo 'R alpha' > $testroot/stdout.expected
33 a129376b 2019-03-28 stsp (cd $testroot/wt && got revert alpha > $testroot/stdout)
35 a129376b 2019-03-28 stsp cmp $testroot/stdout.expected $testroot/stdout
37 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
38 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
39 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
43 a129376b 2019-03-28 stsp echo "alpha" > $testroot/content.expected
44 a129376b 2019-03-28 stsp cat $testroot/wt/alpha > $testroot/content
46 a129376b 2019-03-28 stsp cmp $testroot/content.expected $testroot/content
48 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
49 a129376b 2019-03-28 stsp diff -u $testroot/content.expected $testroot/content
51 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
55 a129376b 2019-03-28 stsp function test_revert_rm {
56 a129376b 2019-03-28 stsp local testroot=`test_init revert_rm`
58 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
60 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
61 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
65 a129376b 2019-03-28 stsp (cd $testroot/wt && got rm beta >/dev/null)
67 a129376b 2019-03-28 stsp echo 'R beta' > $testroot/stdout.expected
69 a129376b 2019-03-28 stsp (cd $testroot/wt && got revert beta > $testroot/stdout)
71 a129376b 2019-03-28 stsp cmp $testroot/stdout.expected $testroot/stdout
73 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
74 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
75 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
79 a129376b 2019-03-28 stsp echo "beta" > $testroot/content.expected
80 a129376b 2019-03-28 stsp cat $testroot/wt/beta > $testroot/content
82 a129376b 2019-03-28 stsp cmp $testroot/content.expected $testroot/content
84 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
85 a129376b 2019-03-28 stsp diff -u $testroot/content.expected $testroot/content
87 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
90 a129376b 2019-03-28 stsp function test_revert_add {
91 a129376b 2019-03-28 stsp local testroot=`test_init revert_add`
93 a129376b 2019-03-28 stsp got checkout $testroot/repo $testroot/wt > /dev/null
95 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
96 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
100 a129376b 2019-03-28 stsp echo "new file" > $testroot/wt/new
101 a129376b 2019-03-28 stsp (cd $testroot/wt && got add new >/dev/null)
103 a129376b 2019-03-28 stsp echo 'R new' > $testroot/stdout.expected
105 a129376b 2019-03-28 stsp (cd $testroot/wt && got revert new > $testroot/stdout)
107 a129376b 2019-03-28 stsp cmp $testroot/stdout.expected $testroot/stdout
109 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
110 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
111 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
115 a129376b 2019-03-28 stsp echo "new file" > $testroot/content.expected
116 a129376b 2019-03-28 stsp cat $testroot/wt/new > $testroot/content
118 a129376b 2019-03-28 stsp cmp $testroot/content.expected $testroot/content
120 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
121 a129376b 2019-03-28 stsp diff -u $testroot/content.expected $testroot/content
122 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
126 a129376b 2019-03-28 stsp echo '? new' > $testroot/stdout.expected
128 a129376b 2019-03-28 stsp (cd $testroot/wt && got status > $testroot/stdout)
130 a129376b 2019-03-28 stsp cmp $testroot/stdout.expected $testroot/stdout
132 a129376b 2019-03-28 stsp if [ "$ret" != "0" ]; then
133 a129376b 2019-03-28 stsp diff -u $testroot/stdout.expected $testroot/stdout
135 a129376b 2019-03-28 stsp test_done "$testroot" "$ret"
138 a129376b 2019-03-28 stsp run_test test_revert_basic
139 a129376b 2019-03-28 stsp run_test test_revert_rm
140 a129376b 2019-03-28 stsp run_test test_revert_add