Blame


1 4e0a20a4 2020-03-23 tracey #!/bin/sh
2 4e0a20a4 2020-03-23 tracey #
3 4e0a20a4 2020-03-23 tracey # Copyright (c) 2020 Tracey Emery <tracey@openbsd.org>
4 4e0a20a4 2020-03-23 tracey #
5 4e0a20a4 2020-03-23 tracey # Permission to use, copy, modify, and distribute this software for any
6 4e0a20a4 2020-03-23 tracey # purpose with or without fee is hereby granted, provided that the above
7 4e0a20a4 2020-03-23 tracey # copyright notice and this permission notice appear in all copies.
8 4e0a20a4 2020-03-23 tracey #
9 4e0a20a4 2020-03-23 tracey # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 4e0a20a4 2020-03-23 tracey # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 4e0a20a4 2020-03-23 tracey # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 4e0a20a4 2020-03-23 tracey # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 4e0a20a4 2020-03-23 tracey # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 4e0a20a4 2020-03-23 tracey # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 4e0a20a4 2020-03-23 tracey # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 4e0a20a4 2020-03-23 tracey
17 4e0a20a4 2020-03-23 tracey . ./common.sh
18 4e0a20a4 2020-03-23 tracey
19 f6cae3ed 2020-09-13 naddy test_tree_basic() {
20 4e0a20a4 2020-03-23 tracey local testroot=`test_init tree_basic`
21 4e0a20a4 2020-03-23 tracey
22 4e0a20a4 2020-03-23 tracey got checkout $testroot/repo $testroot/wt > /dev/null
23 4e0a20a4 2020-03-23 tracey
24 4e0a20a4 2020-03-23 tracey echo "new file" > $testroot/wt/foo
25 4e0a20a4 2020-03-23 tracey
26 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got add foo > /dev/null)
27 810a850e 2020-03-23 tracey (cd $testroot/wt && got commit -m "add foo" foo > /dev/null)
28 4e0a20a4 2020-03-23 tracey
29 4e0a20a4 2020-03-23 tracey echo 'alpha' > $testroot/stdout.expected
30 4e0a20a4 2020-03-23 tracey echo 'beta' >> $testroot/stdout.expected
31 4e0a20a4 2020-03-23 tracey echo 'epsilon/' >> $testroot/stdout.expected
32 4e0a20a4 2020-03-23 tracey echo 'foo' >> $testroot/stdout.expected
33 4e0a20a4 2020-03-23 tracey echo 'gamma/' >> $testroot/stdout.expected
34 4e0a20a4 2020-03-23 tracey
35 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got tree > $testroot/stdout)
36 4e0a20a4 2020-03-23 tracey
37 4e0a20a4 2020-03-23 tracey cmp -s $testroot/stdout.expected $testroot/stdout
38 49c543a6 2022-03-31 naddy ret=$?
39 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
40 4e0a20a4 2020-03-23 tracey diff -u $testroot/stdout.expected $testroot/stdout
41 4e0a20a4 2020-03-23 tracey fi
42 4e0a20a4 2020-03-23 tracey
43 4e0a20a4 2020-03-23 tracey test_done "$testroot" "$ret"
44 4e0a20a4 2020-03-23 tracey }
45 4e0a20a4 2020-03-23 tracey
46 f6cae3ed 2020-09-13 naddy test_tree_branch() {
47 4e0a20a4 2020-03-23 tracey local testroot=`test_init tree_branch`
48 4e0a20a4 2020-03-23 tracey
49 4e0a20a4 2020-03-23 tracey got checkout $testroot/repo $testroot/wt > /dev/null
50 49c543a6 2022-03-31 naddy ret=$?
51 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
52 4e0a20a4 2020-03-23 tracey test_done "$testroot" "$ret"
53 4e0a20a4 2020-03-23 tracey return 1
54 4e0a20a4 2020-03-23 tracey fi
55 4e0a20a4 2020-03-23 tracey
56 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got br foo > $testroot/stdout)
57 4e0a20a4 2020-03-23 tracey
58 4e0a20a4 2020-03-23 tracey echo "new file" > $testroot/wt/foo
59 4e0a20a4 2020-03-23 tracey
60 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got add foo > /dev/null)
61 810a850e 2020-03-23 tracey (cd $testroot/wt && got commit -m "add foo" foo > /dev/null)
62 4e0a20a4 2020-03-23 tracey
63 4e0a20a4 2020-03-23 tracey echo 'alpha' > $testroot/stdout.expected
64 4e0a20a4 2020-03-23 tracey echo 'beta' >> $testroot/stdout.expected
65 4e0a20a4 2020-03-23 tracey echo 'epsilon/' >> $testroot/stdout.expected
66 4e0a20a4 2020-03-23 tracey echo 'foo' >> $testroot/stdout.expected
67 4e0a20a4 2020-03-23 tracey echo 'gamma/' >> $testroot/stdout.expected
68 4e0a20a4 2020-03-23 tracey
69 4e0a20a4 2020-03-23 tracey (cd $testroot/wt && got tree > $testroot/stdout)
70 4e0a20a4 2020-03-23 tracey
71 4e0a20a4 2020-03-23 tracey cmp -s $testroot/stdout.expected $testroot/stdout
72 49c543a6 2022-03-31 naddy ret=$?
73 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
74 4e0a20a4 2020-03-23 tracey diff -u $testroot/stdout.expected $testroot/stdout
75 4e0a20a4 2020-03-23 tracey fi
76 4e0a20a4 2020-03-23 tracey
77 4e0a20a4 2020-03-23 tracey test_done "$testroot" "$ret"
78 4e0a20a4 2020-03-23 tracey }
79 4e0a20a4 2020-03-23 tracey
80 f6cae3ed 2020-09-13 naddy test_tree_submodule() {
81 e7303626 2020-05-14 stsp local testroot=`test_init tree_submodule`
82 e7303626 2020-05-14 stsp
83 e7303626 2020-05-14 stsp make_single_file_repo $testroot/repo2 foo
84 f1aec6ed 2022-10-24 stsp (cd $testroot/repo && git -c protocol.file.allow=always \
85 f1aec6ed 2022-10-24 stsp submodule -q add ../repo2)
86 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
87 e7303626 2020-05-14 stsp
88 e7303626 2020-05-14 stsp local submodule_id=$(got tree -r $testroot/repo -i | \
89 e7303626 2020-05-14 stsp grep 'repo2\$$' | cut -d ' ' -f1)
90 e7303626 2020-05-14 stsp local objpath=`get_loose_object_path $testroot/repo $submodule_id`
91 e7303626 2020-05-14 stsp
92 e7303626 2020-05-14 stsp # Currently fails in open(2)
93 e7303626 2020-05-14 stsp got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
94 49c543a6 2022-03-31 naddy ret=$?
95 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
96 e7303626 2020-05-14 stsp echo "tree command succeeded unexpectedly" >&2
97 e7303626 2020-05-14 stsp test_done "$testroot" "1"
98 e7303626 2020-05-14 stsp return 1
99 e7303626 2020-05-14 stsp fi
100 e7303626 2020-05-14 stsp echo "got: open: $objpath: No such file or directory" \
101 e7303626 2020-05-14 stsp > $testroot/stderr.expected
102 e7303626 2020-05-14 stsp
103 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
104 49c543a6 2022-03-31 naddy ret=$?
105 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
106 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
107 e7303626 2020-05-14 stsp return 1
108 e7303626 2020-05-14 stsp fi
109 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
110 e7303626 2020-05-14 stsp }
111 e7303626 2020-05-14 stsp
112 f6cae3ed 2020-09-13 naddy test_tree_submodule_of_same_repo() {
113 e7303626 2020-05-14 stsp local testroot=`test_init tree_submodule_of_same_repo`
114 e7303626 2020-05-14 stsp
115 e7303626 2020-05-14 stsp (cd $testroot && git clone -q repo repo2 >/dev/null)
116 f1aec6ed 2022-10-24 stsp (cd $testroot/repo && git -c protocol.file.allow=always \
117 f1aec6ed 2022-10-24 stsp submodule -q add ../repo2)
118 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
119 e7303626 2020-05-14 stsp
120 e7303626 2020-05-14 stsp # Currently fails with "bad object data"
121 e7303626 2020-05-14 stsp got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
122 49c543a6 2022-03-31 naddy ret=$?
123 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
124 e7303626 2020-05-14 stsp echo "tree command succeeded unexpectedly" >&2
125 e7303626 2020-05-14 stsp test_done "$testroot" "1"
126 e7303626 2020-05-14 stsp return 1
127 e7303626 2020-05-14 stsp fi
128 c5fdccbf 2020-12-10 yzhong if [ -n "$GOT_TEST_PACK" ]; then
129 c5fdccbf 2020-12-10 yzhong echo "got-read-pack: bad object data" \
130 c5fdccbf 2020-12-10 yzhong > $testroot/stderr.expected
131 c5fdccbf 2020-12-10 yzhong else
132 c5fdccbf 2020-12-10 yzhong echo "got-read-tree: bad object data" \
133 c5fdccbf 2020-12-10 yzhong > $testroot/stderr.expected
134 c5fdccbf 2020-12-10 yzhong fi
135 e7303626 2020-05-14 stsp echo "got: bad object data" >> $testroot/stderr.expected
136 e7303626 2020-05-14 stsp
137 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
138 49c543a6 2022-03-31 naddy ret=$?
139 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
140 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
141 e7303626 2020-05-14 stsp return 1
142 e7303626 2020-05-14 stsp fi
143 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
144 e7303626 2020-05-14 stsp }
145 e7303626 2020-05-14 stsp
146 7fb414ae 2020-08-08 stsp test_parseargs "$@"
147 4e0a20a4 2020-03-23 tracey run_test test_tree_basic
148 4e0a20a4 2020-03-23 tracey run_test test_tree_branch
149 e7303626 2020-05-14 stsp run_test test_tree_submodule
150 e7303626 2020-05-14 stsp run_test test_tree_submodule_of_same_repo