Blame


1 01073a5d 2019-08-22 stsp #!/bin/sh
2 01073a5d 2019-08-22 stsp #
3 01073a5d 2019-08-22 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 01073a5d 2019-08-22 stsp #
5 01073a5d 2019-08-22 stsp # Permission to use, copy, modify, and distribute this software for any
6 01073a5d 2019-08-22 stsp # purpose with or without fee is hereby granted, provided that the above
7 01073a5d 2019-08-22 stsp # copyright notice and this permission notice appear in all copies.
8 01073a5d 2019-08-22 stsp #
9 01073a5d 2019-08-22 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 01073a5d 2019-08-22 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 01073a5d 2019-08-22 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 01073a5d 2019-08-22 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 01073a5d 2019-08-22 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 01073a5d 2019-08-22 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 01073a5d 2019-08-22 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 01073a5d 2019-08-22 stsp
17 01073a5d 2019-08-22 stsp . ./common.sh
18 01073a5d 2019-08-22 stsp
19 01073a5d 2019-08-22 stsp function test_cat_basic {
20 01073a5d 2019-08-22 stsp local testroot=`test_init cat_basic`
21 01073a5d 2019-08-22 stsp local commit_id=`git_show_head $testroot/repo`
22 01073a5d 2019-08-22 stsp local author_time=`git_show_author_time $testroot/repo`
23 01073a5d 2019-08-22 stsp local alpha_id=`got tree -r $testroot/repo -i | grep 'alpha$' | cut -d' ' -f 1`
24 01073a5d 2019-08-22 stsp local gamma_id=`got tree -r $testroot/repo -i | grep 'gamma/$' | cut -d' ' -f 1`
25 01073a5d 2019-08-22 stsp local delta_id=`got tree -r $testroot/repo -i gamma | grep 'delta$' | cut -d' ' -f 1`
26 01073a5d 2019-08-22 stsp
27 01073a5d 2019-08-22 stsp # cat blob
28 01073a5d 2019-08-22 stsp echo "alpha" > $testroot/stdout.expected
29 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $alpha_id > $testroot/stdout
30 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
31 01073a5d 2019-08-22 stsp ret="$?"
32 01073a5d 2019-08-22 stsp if [ "$ret" != "0" ]; then
33 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
34 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
35 01073a5d 2019-08-22 stsp return 1
36 01073a5d 2019-08-22 stsp fi
37 01073a5d 2019-08-22 stsp
38 01073a5d 2019-08-22 stsp # cat tree
39 01073a5d 2019-08-22 stsp echo "$delta_id 0100644 delta" > $testroot/stdout.expected
40 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $gamma_id > $testroot/stdout
41 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
42 01073a5d 2019-08-22 stsp ret="$?"
43 01073a5d 2019-08-22 stsp if [ "$ret" != "0" ]; then
44 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
45 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
46 01073a5d 2019-08-22 stsp return 1
47 01073a5d 2019-08-22 stsp fi
48 01073a5d 2019-08-22 stsp
49 01073a5d 2019-08-22 stsp # cat commit
50 8aa93786 2019-08-22 stsp echo -n "tree " > $testroot/stdout.expected
51 01073a5d 2019-08-22 stsp git_show_tree $testroot/repo >> $testroot/stdout.expected
52 01073a5d 2019-08-22 stsp echo >> $testroot/stdout.expected
53 8aa93786 2019-08-22 stsp echo "numparents 0" >> $testroot/stdout.expected
54 8aa93786 2019-08-22 stsp echo "author $GOT_AUTHOR $author_time +0000" >> $testroot/stdout.expected
55 8aa93786 2019-08-22 stsp echo "committer Flan Hacker <flan_hacker@openbsd.org> $author_time +0000" >> $testroot/stdout.expected
56 8aa93786 2019-08-22 stsp echo "messagelen 22" >> $testroot/stdout.expected
57 01073a5d 2019-08-22 stsp printf "\nadding the test tree\n" >> $testroot/stdout.expected
58 01073a5d 2019-08-22 stsp
59 01073a5d 2019-08-22 stsp got cat -r $testroot/repo $commit_id > $testroot/stdout
60 01073a5d 2019-08-22 stsp cmp -s $testroot/stdout.expected $testroot/stdout
61 01073a5d 2019-08-22 stsp ret="$?"
62 01073a5d 2019-08-22 stsp if [ "$ret" != "0" ]; then
63 01073a5d 2019-08-22 stsp diff -u $testroot/stdout.expected $testroot/stdout
64 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
65 01073a5d 2019-08-22 stsp return 1
66 01073a5d 2019-08-22 stsp fi
67 01073a5d 2019-08-22 stsp
68 01073a5d 2019-08-22 stsp # TODO: test cat tag
69 01073a5d 2019-08-22 stsp
70 01073a5d 2019-08-22 stsp test_done "$testroot" "$ret"
71 01073a5d 2019-08-22 stsp
72 01073a5d 2019-08-22 stsp }
73 01073a5d 2019-08-22 stsp
74 01073a5d 2019-08-22 stsp run_test test_cat_basic