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 e7303626 2020-05-14 stsp (cd $testroot/repo && git submodule -q add ../repo2)
85 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
86 e7303626 2020-05-14 stsp
87 e7303626 2020-05-14 stsp local submodule_id=$(got tree -r $testroot/repo -i | \
88 e7303626 2020-05-14 stsp grep 'repo2\$$' | cut -d ' ' -f1)
89 e7303626 2020-05-14 stsp local objpath=`get_loose_object_path $testroot/repo $submodule_id`
90 e7303626 2020-05-14 stsp
91 e7303626 2020-05-14 stsp # Currently fails in open(2)
92 e7303626 2020-05-14 stsp got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
93 49c543a6 2022-03-31 naddy ret=$?
94 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
95 e7303626 2020-05-14 stsp echo "tree command succeeded unexpectedly" >&2
96 e7303626 2020-05-14 stsp test_done "$testroot" "1"
97 e7303626 2020-05-14 stsp return 1
98 e7303626 2020-05-14 stsp fi
99 e7303626 2020-05-14 stsp echo "got: open: $objpath: No such file or directory" \
100 e7303626 2020-05-14 stsp > $testroot/stderr.expected
101 e7303626 2020-05-14 stsp
102 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
103 49c543a6 2022-03-31 naddy ret=$?
104 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
105 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
106 e7303626 2020-05-14 stsp return 1
107 e7303626 2020-05-14 stsp fi
108 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
109 e7303626 2020-05-14 stsp }
110 e7303626 2020-05-14 stsp
111 f6cae3ed 2020-09-13 naddy test_tree_submodule_of_same_repo() {
112 e7303626 2020-05-14 stsp local testroot=`test_init tree_submodule_of_same_repo`
113 e7303626 2020-05-14 stsp
114 e7303626 2020-05-14 stsp (cd $testroot && git clone -q repo repo2 >/dev/null)
115 e7303626 2020-05-14 stsp (cd $testroot/repo && git submodule -q add ../repo2)
116 e7303626 2020-05-14 stsp (cd $testroot/repo && git commit -q -m 'adding submodule')
117 e7303626 2020-05-14 stsp
118 e7303626 2020-05-14 stsp # Currently fails with "bad object data"
119 e7303626 2020-05-14 stsp got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr
120 49c543a6 2022-03-31 naddy ret=$?
121 49c543a6 2022-03-31 naddy if [ $ret -eq 0 ]; then
122 e7303626 2020-05-14 stsp echo "tree command succeeded unexpectedly" >&2
123 e7303626 2020-05-14 stsp test_done "$testroot" "1"
124 e7303626 2020-05-14 stsp return 1
125 e7303626 2020-05-14 stsp fi
126 c5fdccbf 2020-12-10 yzhong if [ -n "$GOT_TEST_PACK" ]; then
127 c5fdccbf 2020-12-10 yzhong echo "got-read-pack: bad object data" \
128 c5fdccbf 2020-12-10 yzhong > $testroot/stderr.expected
129 c5fdccbf 2020-12-10 yzhong else
130 c5fdccbf 2020-12-10 yzhong echo "got-read-tree: bad object data" \
131 c5fdccbf 2020-12-10 yzhong > $testroot/stderr.expected
132 c5fdccbf 2020-12-10 yzhong fi
133 e7303626 2020-05-14 stsp echo "got: bad object data" >> $testroot/stderr.expected
134 e7303626 2020-05-14 stsp
135 e7303626 2020-05-14 stsp cmp -s $testroot/stderr.expected $testroot/stderr
136 49c543a6 2022-03-31 naddy ret=$?
137 49c543a6 2022-03-31 naddy if [ $ret -ne 0 ]; then
138 e7303626 2020-05-14 stsp diff -u $testroot/stderr.expected $testroot/stderr
139 e7303626 2020-05-14 stsp return 1
140 e7303626 2020-05-14 stsp fi
141 e7303626 2020-05-14 stsp test_done "$testroot" "$ret"
142 e7303626 2020-05-14 stsp }
143 e7303626 2020-05-14 stsp
144 7fb414ae 2020-08-08 stsp test_parseargs "$@"
145 4e0a20a4 2020-03-23 tracey run_test test_tree_basic
146 4e0a20a4 2020-03-23 tracey run_test test_tree_branch
147 e7303626 2020-05-14 stsp run_test test_tree_submodule
148 e7303626 2020-05-14 stsp run_test test_tree_submodule_of_same_repo