]>
Commit | Line | Data |
---|---|---|
a17c4101 CC |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Christian Couder | |
4 | # | |
4f506716 | 5 | test_description='Tests git-bisect functionality' |
a17c4101 | 6 | |
0a5280a9 JH |
7 | exec </dev/null |
8 | ||
a17c4101 CC |
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 | ||
ab69e89c JH |
25 | test_tick |
26 | git-commit --quiet -m "$MSG" $_file | |
a17c4101 CC |
27 | } |
28 | ||
29 | HASH1= | |
ab69e89c | 30 | HASH2= |
a17c4101 CC |
31 | HASH3= |
32 | HASH4= | |
33 | ||
ab69e89c JH |
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) && | |
a17c4101 | 37 | add_line_into_file "2: A new day for git" hello && |
ab69e89c | 38 | HASH2=$(git rev-parse --verify HEAD) && |
a17c4101 | 39 | add_line_into_file "3: Another new day for git" hello && |
ab69e89c | 40 | HASH3=$(git rev-parse --verify HEAD) && |
a17c4101 | 41 | add_line_into_file "4: Ciao for now" hello && |
ab69e89c JH |
42 | HASH4=$(git rev-parse --verify HEAD) |
43 | ' | |
a17c4101 | 44 | |
0a5280a9 | 45 | test_expect_success 'bisect starts with only one bad' ' |
4f506716 JH |
46 | git bisect reset && |
47 | git bisect start && | |
0a5280a9 JH |
48 | git bisect bad $HASH4 && |
49 | git bisect next | |
4f506716 JH |
50 | ' |
51 | ||
f9487929 | 52 | test_expect_success 'bisect does not start with only one good' ' |
4f506716 JH |
53 | git bisect reset && |
54 | git bisect start && | |
55 | git bisect good $HASH1 || return 1 | |
56 | ||
57 | if git bisect next | |
58 | then | |
59 | echo Oops, should have failed. | |
60 | false | |
61 | else | |
62 | : | |
63 | fi | |
64 | ' | |
65 | ||
66 | test_expect_success 'bisect start with one bad and good' ' | |
67 | git bisect reset && | |
68 | git bisect start && | |
69 | git bisect good $HASH1 && | |
70 | git bisect bad $HASH4 && | |
71 | git bisect next | |
72 | ' | |
73 | ||
a17c4101 CC |
74 | # We want to automatically find the commit that |
75 | # introduced "Another" into hello. | |
76 | test_expect_success \ | |
38a47fd6 CC |
77 | '"git bisect run" simple case' \ |
78 | 'echo "#"\!"/bin/sh" > test_script.sh && | |
a17c4101 CC |
79 | echo "grep Another hello > /dev/null" >> test_script.sh && |
80 | echo "test \$? -ne 0" >> test_script.sh && | |
81 | chmod +x test_script.sh && | |
82 | git bisect start && | |
83 | git bisect good $HASH1 && | |
84 | git bisect bad $HASH4 && | |
85 | git bisect run ./test_script.sh > my_bisect_log.txt && | |
38a47fd6 CC |
86 | grep "$HASH3 is first bad commit" my_bisect_log.txt && |
87 | git bisect reset' | |
88 | ||
89 | # We want to automatically find the commit that | |
90 | # introduced "Ciao" into hello. | |
91 | test_expect_success \ | |
92 | '"git bisect run" with more complex "git bisect start"' \ | |
93 | 'echo "#"\!"/bin/sh" > test_script.sh && | |
94 | echo "grep Ciao hello > /dev/null" >> test_script.sh && | |
95 | echo "test \$? -ne 0" >> test_script.sh && | |
96 | chmod +x test_script.sh && | |
97 | git bisect start $HASH4 $HASH1 && | |
98 | git bisect run ./test_script.sh > my_bisect_log.txt && | |
99 | grep "$HASH4 is first bad commit" my_bisect_log.txt && | |
100 | git bisect reset' | |
a17c4101 CC |
101 | |
102 | # | |
103 | # | |
104 | test_done |