@matheusbsbs / matheus-bagliano / commits / 921df15f1d
Fork 0

rev-parse: add test script for "--verify"

This patch documents the current behavior of "git rev-parse --verify". This command is tested both with and without the "--quiet" and "--default" options. This shows some problems with the current behavior that will be fixed in latter patches: - in case of errors, there should be no good rev output on stdout, - with "--default" one test case is broken Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed May 11, 2008 at 18:27 UTC 921df15f1d276bdecb7c4e134dff97f4e3adf953
1 file changed +114
t/t1503-rev-parse-verify.sh new
+114
@@ -0,0 +1,114 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2008 Christian Couder
4 +#
5 +test_description='test git rev-parse --verify'
6 +
7 +exec </dev/null
8 +
9 +. ./test-lib.sh
10 +
11 +add_line_into_file()
12 +{
13 + _line=$1
14 + _file=$2
15 +
16 + if [ -f "$_file" ]; then
17 + echo "$_line" >> $_file || return $?
18 + MSG="Add <$_line> into <$_file>."
19 + else
20 + echo "$_line" > $_file || return $?
21 + git add $_file || return $?
22 + MSG="Create file <$_file> with <$_line> inside."
23 + fi
24 +
25 + test_tick
26 + git-commit --quiet -m "$MSG" $_file
27 +}
28 +
29 +HASH1=
30 +HASH2=
31 +HASH3=
32 +HASH4=
33 +
34 +test_expect_success 'set up basic repo with 1 file (hello) and 4 commits' '
35 + add_line_into_file "1: Hello World" hello &&
36 + HASH1=$(git rev-parse --verify HEAD) &&
37 + add_line_into_file "2: A new day for git" hello &&
38 + HASH2=$(git rev-parse --verify HEAD) &&
39 + add_line_into_file "3: Another new day for git" hello &&
40 + HASH3=$(git rev-parse --verify HEAD) &&
41 + add_line_into_file "4: Ciao for now" hello &&
42 + HASH4=$(git rev-parse --verify HEAD)
43 +'
44 +
45 +test_expect_success 'works with one good rev' '
46 + rev_hash1=$(git rev-parse --verify $HASH1) &&
47 + test "$rev_hash1" = "$HASH1" &&
48 + rev_hash2=$(git rev-parse --verify $HASH2) &&
49 + test "$rev_hash2" = "$HASH2" &&
50 + rev_hash3=$(git rev-parse --verify $HASH3) &&
51 + test "$rev_hash3" = "$HASH3" &&
52 + rev_hash4=$(git rev-parse --verify $HASH4) &&
53 + test "$rev_hash4" = "$HASH4" &&
54 + rev_master=$(git rev-parse --verify master) &&
55 + test "$rev_master" = "$HASH4" &&
56 + rev_head=$(git rev-parse --verify HEAD) &&
57 + test "$rev_head" = "$HASH4"
58 +'
59 +
60 +test_expect_success 'fails with any bad rev or many good revs' '
61 + test_must_fail git rev-parse --verify 2>error &&
62 + grep "single revision" error &&
63 + test_must_fail git rev-parse --verify foo 2>error &&
64 + grep "single revision" error &&
65 + test_must_fail git rev-parse --verify HEAD bar 2>error &&
66 + grep "single revision" error &&
67 + test_must_fail git rev-parse --verify baz HEAD 2>error &&
68 + grep "single revision" error &&
69 + test_must_fail git rev-parse --verify $HASH2 HEAD 2>error &&
70 + grep "single revision" error
71 +'
72 +
73 +test_expect_success 'fails silently when using -q' '
74 + test_must_fail git rev-parse --verify --quiet 2>error &&
75 + test -z "$(cat error)" &&
76 + test_must_fail git rev-parse -q --verify foo 2>error &&
77 + test -z "$(cat error)" &&
78 + test_must_fail git rev-parse --verify -q HEAD bar 2>error &&
79 + test -z "$(cat error)" &&
80 + test_must_fail git rev-parse --quiet --verify baz HEAD 2>error &&
81 + test -z "$(cat error)" &&
82 + test_must_fail git rev-parse -q --verify $HASH2 HEAD 2>error &&
83 + test -z "$(cat error)"
84 +'
85 +
86 +test_expect_success '1 no stdout output on error' '
87 + test -z "$(git rev-parse --verify)" &&
88 + test -z "$(git rev-parse --verify foo)" &&
89 + test -z "$(git rev-parse --verify baz HEAD)"
90 +'
91 +
92 +test_expect_failure '2 no stdout output on error' '
93 + test -z "$(git rev-parse --verify HEAD bar)"
94 +'
95 +
96 +test_expect_failure '3 no stdout output on error' '
97 + test -z "$(git rev-parse --verify $HASH2 HEAD)"
98 +'
99 +
100 +test_expect_success '1 with --default' '
101 + git rev-parse --verify --default master &&
102 + git rev-parse --verify --default master HEAD &&
103 + git rev-parse --default master --verify &&
104 + git rev-parse --default master --verify HEAD &&
105 + test_must_fail git rev-parse --verify foo --default master &&
106 + test_must_fail git rev-parse --default HEAD --verify bar &&
107 + test_must_fail git rev-parse --verify --default HEAD baz
108 +'
109 +
110 +test_expect_failure '2 with --default' '
111 + git rev-parse --verify HEAD --default master
112 +'
113 +
114 +test_done