]> git.ipfire.org Git - thirdparty/git.git/blame - t/lib-t6000.sh
wildmatch: rename constants and update prototype
[thirdparty/git.git] / t / lib-t6000.sh
CommitLineData
b9b727dd
JH
1: included from 6002 and others
2
ce11895d
JS
3[ -d .git/refs/tags ] || mkdir -p .git/refs/tags
4
28346d2d 5:> sed.script
ce11895d
JS
6
7# Answer the sha1 has associated with the tag. The tag must exist in .git or .git/refs/tags
8tag()
9{
10 _tag=$1
11 [ -f .git/refs/tags/$_tag ] || error "tag: \"$_tag\" does not exist"
12 cat .git/refs/tags/$_tag
13}
14
15# Generate a commit using the text specified to make it unique and the tree
16# named by the tag specified.
17unique_commit()
18{
19 _text=$1
20 _tree=$2
21 shift 2
5be60078 22 echo $_text | git commit-tree $(tag $_tree) "$@"
ce11895d
JS
23}
24
25# Save the output of a command into the tag specified. Prepend
28346d2d 26# a substitution script for the tag onto the front of sed.script
ce11895d
JS
27save_tag()
28{
a6080a0a 29 _tag=$1
ce11895d
JS
30 [ -n "$_tag" ] || error "usage: save_tag tag commit-args ..."
31 shift 1
a6080a0a 32 "$@" >.git/refs/tags/$_tag
f6069c59 33
28346d2d
JS
34 echo "s/$(tag $_tag)/$_tag/g" > sed.script.tmp
35 cat sed.script >> sed.script.tmp
36 rm sed.script
37 mv sed.script.tmp sed.script
ce11895d
JS
38}
39
a6080a0a 40# Replace unhelpful sha1 hashses with their symbolic equivalents
ce11895d
JS
41entag()
42{
28346d2d 43 sed -f sed.script
ce11895d
JS
44}
45
46# Execute a command after first saving, then setting the GIT_AUTHOR_EMAIL
47# tag to a specified value. Restore the original value on return.
48as_author()
49{
50 _author=$1
51 shift 1
52 _save=$GIT_AUTHOR_EMAIL
53
0e46e704
BD
54 GIT_AUTHOR_EMAIL="$_author"
55 export GIT_AUTHOR_EMAIL
ce11895d 56 "$@"
47e013f9
JH
57 if test -z "$_save"
58 then
59 unset GIT_AUTHOR_EMAIL
60 else
0e46e704
BD
61 GIT_AUTHOR_EMAIL="$_save"
62 export GIT_AUTHOR_EMAIL
47e013f9 63 fi
ce11895d
JS
64}
65
66commit_date()
67{
68 _commit=$1
5be60078 69 git cat-file commit $_commit | sed -n "s/^committer .*> \([0-9]*\) .*/\1/p"
ce11895d
JS
70}
71
72on_committer_date()
73{
74 _date=$1
75 shift 1
0e46e704
BD
76 GIT_COMMITTER_DATE="$_date"
77 export GIT_COMMITTER_DATE
933e4f09
EW
78 "$@"
79 unset GIT_COMMITTER_DATE
ce11895d
JS
80}
81
82# Execute a command and suppress any error output.
83hide_error()
84{
85 "$@" 2>/dev/null
86}
87
88check_output()
89{
90 _name=$1
91 shift 1
92 if eval "$*" | entag > $_name.actual
93 then
4fdf71be 94 test_cmp $_name.expected $_name.actual
ce11895d
JS
95 else
96 return 1;
97 fi
98}
99
100# Turn a reasonable test description into a reasonable test name.
101# All alphanums translated into -'s which are then compressed and stripped
102# from front and back.
103name_from_description()
104{
aab0abf7
JK
105 perl -pe '
106 s/[^A-Za-z0-9.]/-/g;
107 s/-+/-/g;
108 s/-$//;
109 s/^-//;
110 y/A-Z/a-z/;
111 '
ce11895d
JS
112}
113
114
115# Execute the test described by the first argument, by eval'ing
116# command line specified in the 2nd argument. Check the status code
a6080a0a 117# is zero and that the output matches the stream read from
ce11895d
JS
118# stdin.
119test_output_expect_success()
a6080a0a 120{
ce11895d
JS
121 _description=$1
122 _test=$2
123 [ $# -eq 2 ] || error "usage: test_output_expect_success description test <<EOF ... EOF"
124 _name=$(echo $_description | name_from_description)
125 cat > $_name.expected
a6080a0a 126 test_expect_success "$_description" "check_output $_name \"$_test\""
ce11895d 127}