3 # Copyright (c) 2007 Christian Couder
5 test_description='Tests git-bisect functionality'
16 if [ -f "$_file" ]; then
17 echo "$_line" >> $_file || return $?
18 MSG="Add <$_line> into <$_file>."
20 echo "$_line" > $_file || return $?
21 git add $_file || return $?
22 MSG="Create file <$_file> with <$_line> inside."
26 git-commit --quiet -m "$MSG" $_file
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)
45 test_expect_success 'bisect starts with only one bad' '
48 git bisect bad $HASH4 &&
52 test_expect_success 'bisect does not start with only one good' '
55 git bisect good $HASH1 || return 1
59 echo Oops, should have failed.
66 test_expect_success 'bisect start with one bad and good' '
69 git bisect good $HASH1 &&
70 git bisect bad $HASH4 &&
74 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
76 # so we should find $HASH2 as the first bad commit
77 test_expect_success 'bisect skip: successfull result' '
79 git bisect start $HASH4 $HASH1 &&
81 git bisect bad > my_bisect_log.txt &&
82 grep "$HASH2 is first bad commit" my_bisect_log.txt &&
86 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
87 # so we should not be able to tell the first bad commit
88 # among $HASH2, $HASH3 and $HASH4
89 test_expect_success 'bisect skip: cannot tell between 3 commits' '
90 git bisect start $HASH4 $HASH1 &&
91 git bisect skip || return 1
93 if git bisect skip > my_bisect_log.txt
95 echo Oops, should have failed.
99 grep "first bad commit could be any of" my_bisect_log.txt &&
100 ! grep $HASH1 my_bisect_log.txt &&
101 grep $HASH2 my_bisect_log.txt &&
102 grep $HASH3 my_bisect_log.txt &&
103 grep $HASH4 my_bisect_log.txt &&
108 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
109 # but $HASH2 is good,
110 # so we should not be able to tell the first bad commit
111 # among $HASH3 and $HASH4
112 test_expect_success 'bisect skip: cannot tell between 2 commits' '
113 git bisect start $HASH4 $HASH1 &&
114 git bisect skip || return 1
116 if git bisect good > my_bisect_log.txt
118 echo Oops, should have failed.
122 grep "first bad commit could be any of" my_bisect_log.txt &&
123 ! grep $HASH1 my_bisect_log.txt &&
124 ! grep $HASH2 my_bisect_log.txt &&
125 grep $HASH3 my_bisect_log.txt &&
126 grep $HASH4 my_bisect_log.txt &&
131 # We want to automatically find the commit that
132 # introduced "Another" into hello.
133 test_expect_success \
134 '"git bisect run" simple case' \
135 'echo "#"\!"/bin/sh" > test_script.sh &&
136 echo "grep Another hello > /dev/null" >> test_script.sh &&
137 echo "test \$? -ne 0" >> test_script.sh &&
138 chmod +x test_script.sh &&
140 git bisect good $HASH1 &&
141 git bisect bad $HASH4 &&
142 git bisect run ./test_script.sh > my_bisect_log.txt &&
143 grep "$HASH3 is first bad commit" my_bisect_log.txt &&
146 # We want to automatically find the commit that
147 # introduced "Ciao" into hello.
148 test_expect_success \
149 '"git bisect run" with more complex "git bisect start"' \
150 'echo "#"\!"/bin/sh" > test_script.sh &&
151 echo "grep Ciao hello > /dev/null" >> test_script.sh &&
152 echo "test \$? -ne 0" >> test_script.sh &&
153 chmod +x test_script.sh &&
154 git bisect start $HASH4 $HASH1 &&
155 git bisect run ./test_script.sh > my_bisect_log.txt &&
156 grep "$HASH4 is first bad commit" my_bisect_log.txt &&
159 # $HASH1 is good, $HASH5 is bad, we skip $HASH3
160 # but $HASH4 is good,
161 # so we should find $HASH5 as the first bad commit
163 test_expect_success 'bisect skip: add line and then a new test' '
164 add_line_into_file "5: Another new line." hello &&
165 HASH5=$(git rev-parse --verify HEAD) &&
166 git bisect start $HASH5 $HASH1 &&
168 git bisect good > my_bisect_log.txt &&
169 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
170 git bisect log > log_to_replay.txt
174 test_expect_success 'bisect skip and bisect replay' '
175 git bisect replay log_to_replay.txt > my_bisect_log.txt &&
176 grep "$HASH5 is first bad commit" my_bisect_log.txt &&
181 test_expect_success 'bisect run & skip: cannot tell between 2' '
182 add_line_into_file "6: Yet a line." hello &&
183 HASH6=$(git rev-parse --verify HEAD) &&
184 echo "#"\!"/bin/sh" > test_script.sh &&
185 echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
186 echo "grep line hello > /dev/null" >> test_script.sh &&
187 echo "test \$? -ne 0" >> test_script.sh &&
188 chmod +x test_script.sh &&
189 git bisect start $HASH6 $HASH1 &&
190 if git bisect run ./test_script.sh > my_bisect_log.txt
192 echo Oops, should have failed.
196 grep "first bad commit could be any of" my_bisect_log.txt &&
197 ! grep $HASH3 my_bisect_log.txt &&
198 ! grep $HASH6 my_bisect_log.txt &&
199 grep $HASH4 my_bisect_log.txt &&
200 grep $HASH5 my_bisect_log.txt
205 test_expect_success 'bisect run & skip: find first bad' '
207 add_line_into_file "7: Should be the last line." hello &&
208 HASH7=$(git rev-parse --verify HEAD) &&
209 echo "#"\!"/bin/sh" > test_script.sh &&
210 echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh &&
211 echo "tail -1 hello | grep day > /dev/null && exit 125" >> test_script.sh &&
212 echo "grep Yet hello > /dev/null" >> test_script.sh &&
213 echo "test \$? -ne 0" >> test_script.sh &&
214 chmod +x test_script.sh &&
215 git bisect start $HASH7 $HASH1 &&
216 git bisect run ./test_script.sh > my_bisect_log.txt &&
217 grep "$HASH6 is first bad commit" my_bisect_log.txt