Blob


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