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