Blame


1 2ec1f75b 2019-03-26 stsp #!/bin/sh
2 2ec1f75b 2019-03-26 stsp #
3 2ec1f75b 2019-03-26 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 2ec1f75b 2019-03-26 stsp #
5 2ec1f75b 2019-03-26 stsp # Permission to use, copy, modify, and distribute this software for any
6 2ec1f75b 2019-03-26 stsp # purpose with or without fee is hereby granted, provided that the above
7 2ec1f75b 2019-03-26 stsp # copyright notice and this permission notice appear in all copies.
8 2ec1f75b 2019-03-26 stsp #
9 2ec1f75b 2019-03-26 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 2ec1f75b 2019-03-26 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 2ec1f75b 2019-03-26 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 2ec1f75b 2019-03-26 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 2ec1f75b 2019-03-26 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 2ec1f75b 2019-03-26 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 2ec1f75b 2019-03-26 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 2ec1f75b 2019-03-26 stsp
17 2ec1f75b 2019-03-26 stsp . ./common.sh
18 2ec1f75b 2019-03-26 stsp
19 2ec1f75b 2019-03-26 stsp function test_rm_basic {
20 2ec1f75b 2019-03-26 stsp local testroot=`test_init rm_basic`
21 2ec1f75b 2019-03-26 stsp
22 2ec1f75b 2019-03-26 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 2ec1f75b 2019-03-26 stsp ret="$?"
24 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
25 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
26 2ec1f75b 2019-03-26 stsp return 1
27 2ec1f75b 2019-03-26 stsp fi
28 2ec1f75b 2019-03-26 stsp
29 2ec1f75b 2019-03-26 stsp echo 'D beta' > $testroot/stdout.expected
30 2ec1f75b 2019-03-26 stsp (cd $testroot/wt && got rm beta > $testroot/stdout)
31 2ec1f75b 2019-03-26 stsp
32 2ec1f75b 2019-03-26 stsp cmp $testroot/stdout.expected $testroot/stdout
33 2ec1f75b 2019-03-26 stsp ret="$?"
34 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
35 2ec1f75b 2019-03-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
36 2ec1f75b 2019-03-26 stsp fi
37 2ec1f75b 2019-03-26 stsp
38 2ec1f75b 2019-03-26 stsp if [ -e $testroot/wt/beta ]; then
39 2ec1f75b 2019-03-26 stsp echo "removed file beta still exists on disk" >&2
40 2ec1f75b 2019-03-26 stsp test_done "$testroot" "1"
41 2ec1f75b 2019-03-26 stsp return 1
42 2ec1f75b 2019-03-26 stsp fi
43 2ec1f75b 2019-03-26 stsp
44 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
45 2ec1f75b 2019-03-26 stsp }
46 2ec1f75b 2019-03-26 stsp
47 2ec1f75b 2019-03-26 stsp function test_rm_with_local_mods {
48 2ec1f75b 2019-03-26 stsp local testroot=`test_init rm_with_local_mods`
49 2ec1f75b 2019-03-26 stsp
50 2ec1f75b 2019-03-26 stsp got checkout $testroot/repo $testroot/wt > /dev/null
51 2ec1f75b 2019-03-26 stsp ret="$?"
52 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
53 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
54 2ec1f75b 2019-03-26 stsp return 1
55 2ec1f75b 2019-03-26 stsp fi
56 2ec1f75b 2019-03-26 stsp
57 2ec1f75b 2019-03-26 stsp echo "modified beta" > $testroot/wt/beta
58 2ec1f75b 2019-03-26 stsp echo 'got: file contains modifications' > $testroot/stderr.expected
59 2ec1f75b 2019-03-26 stsp (cd $testroot/wt && got rm beta 2>$testroot/stderr)
60 2ec1f75b 2019-03-26 stsp
61 2ec1f75b 2019-03-26 stsp cmp $testroot/stderr.expected $testroot/stderr
62 2ec1f75b 2019-03-26 stsp ret="$?"
63 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
64 2ec1f75b 2019-03-26 stsp diff -u $testroot/stderr.expected $testroot/stderr
65 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
66 2ec1f75b 2019-03-26 stsp return 1
67 2ec1f75b 2019-03-26 stsp fi
68 2ec1f75b 2019-03-26 stsp
69 2ec1f75b 2019-03-26 stsp echo 'D beta' > $testroot/stdout.expected
70 2ec1f75b 2019-03-26 stsp (cd $testroot/wt && got rm -f beta > $testroot/stdout)
71 2ec1f75b 2019-03-26 stsp
72 2ec1f75b 2019-03-26 stsp cmp $testroot/stdout.expected $testroot/stdout
73 2ec1f75b 2019-03-26 stsp ret="$?"
74 2ec1f75b 2019-03-26 stsp if [ "$ret" != "0" ]; then
75 2ec1f75b 2019-03-26 stsp diff -u $testroot/stdout.expected $testroot/stdout
76 2ec1f75b 2019-03-26 stsp fi
77 2ec1f75b 2019-03-26 stsp
78 2ec1f75b 2019-03-26 stsp if [ -e $testroot/wt/beta ]; then
79 2ec1f75b 2019-03-26 stsp echo "removed file beta still exists on disk" >&2
80 2ec1f75b 2019-03-26 stsp test_done "$testroot" "1"
81 2ec1f75b 2019-03-26 stsp return 1
82 2ec1f75b 2019-03-26 stsp fi
83 2ec1f75b 2019-03-26 stsp
84 2ec1f75b 2019-03-26 stsp test_done "$testroot" "$ret"
85 2ec1f75b 2019-03-26 stsp }
86 2ec1f75b 2019-03-26 stsp
87 71a29355 2019-03-27 stsp function test_double_rm {
88 71a29355 2019-03-27 stsp local testroot=`test_init double_rm`
89 71a29355 2019-03-27 stsp
90 71a29355 2019-03-27 stsp got checkout $testroot/repo $testroot/wt > /dev/null
91 71a29355 2019-03-27 stsp ret="$?"
92 71a29355 2019-03-27 stsp if [ "$ret" != "0" ]; then
93 71a29355 2019-03-27 stsp test_done "$testroot" "$ret"
94 71a29355 2019-03-27 stsp return 1
95 71a29355 2019-03-27 stsp fi
96 71a29355 2019-03-27 stsp
97 71a29355 2019-03-27 stsp (cd $testroot/wt && got rm beta > /dev/null)
98 71a29355 2019-03-27 stsp
99 71a29355 2019-03-27 stsp for fflag in "" "-f"; do
100 71a29355 2019-03-27 stsp (cd $testroot/wt && got rm $fflag beta 2> $testroot/stderr)
101 71a29355 2019-03-27 stsp ret="$?"
102 71a29355 2019-03-27 stsp if [ "$ret" == "0" ]; then
103 71a29355 2019-03-27 stsp echo "got rm command succeeded unexpectedly" >&2
104 71a29355 2019-03-27 stsp test_done "$testroot" 1
105 71a29355 2019-03-27 stsp fi
106 71a29355 2019-03-27 stsp
107 2af4a041 2019-05-11 jcs grep "No such file or directory" $testroot/stderr > \
108 2af4a041 2019-05-11 jcs $testroot/stderr.actual
109 71a29355 2019-03-27 stsp ret="$?"
110 71a29355 2019-03-27 stsp if [ "$ret" != "0" ]; then
111 2af4a041 2019-05-11 jcs cat $testroot/stderr
112 71a29355 2019-03-27 stsp test_done "$testroot" "$ret"
113 71a29355 2019-03-27 stsp fi
114 71a29355 2019-03-27 stsp done
115 71a29355 2019-03-27 stsp test_done "$testroot" "0"
116 71a29355 2019-03-27 stsp }
117 71a29355 2019-03-27 stsp
118 2ec1f75b 2019-03-26 stsp run_test test_rm_basic
119 2ec1f75b 2019-03-26 stsp run_test test_rm_with_local_mods
120 71a29355 2019-03-27 stsp run_test test_double_rm