Bail out when the testrepo couldn't be set up
[git-stats.git] / src / t / t8100-stats.sh
blob5f21c4ef7a2e4a853b9f693090ef1d76c9588e51
1 #!/bin/sh
3 # Copyright (c) 2008 Sverre Rabbelier
6 test_description='stats tests (basics)
8 This test verifies that the basic stats commands work as expected.'
10 ORIG_PATH=$PWD
12 . ./test-lib.sh
15 ###########
16 # Setup
17 ###########
20 test_expect_success 'pre-clean' '
21 rm -fr "/tmp/testrepo" || {
22 trap - exit
23 echo >&5 "FATAL: Cannot clean the fresh repo"
24 exit 1
28 test_expect_success 'setup' '
29 ../scripts/setupRepo.py test && \
30 cd "/tmp/testrepo" || {
31 trap - exit
32 echo >&5 "FATAL: Cannot cd into fresh repo"
33 exit 1
37 test_expect_success 'Test that stats.py is reachable' '
38 stats.py -v || {
39 trap - exit
40 echo >&5 "FATAL: stats.py not reachable"
41 exit 1
45 echo "f1fdf284733011b1172b4517b4526879059bb414" > expected
47 test_expect_success 'Test that the expected tree was created by setupRepo' '
48 git rev-parse HEAD > actual
49 test_cmp expected actual || {
50 trap - exit
51 echo >&5 "FATAL: Head revision does not match"
52 exit 1
57 ###########
58 # Author tests
59 ###########
63 echo "notes.txt = 3: +3 -0"
64 echo "content.txt = 23: +23 -1"
65 echo "docs/README.txt = 10: +8 -2"
66 } > expected
68 test_expect_success \
69 'Test that "author -d" filters as expected for the primary author' \
71 stats.py author -d "author@example.com" > actual
72 test_cmp expected actual
76 echo "content.txt = 2: +2 -0"
77 } > expected
79 test_expect_success \
80 'Test that "author -d" filters as expected for the secondary author' \
82 stats.py author -d "roh.tua@example.com" > actual
83 test_cmp expected actual
86 rm expected
87 touch expected
89 test_expect_failure 'Test that "author -a" aggregates as expected' '
90 `stats.py author -a` > actual
91 test_must_fail test_cmp expected actual
94 ###########
95 # Branch tests
96 ###########
99 echo "Matching branches:"
100 echo "pu"
101 } > expected
103 test_expect_success 'Test that "branch -c" filters as expected' '
104 stats.py branch -c 6f01ab2afb8471d6eee83162ddeabe179e443d59 > actual
105 test_cmp expected actual
109 echo "Matching branches:"
110 echo "erase"
111 echo "maint"
112 echo "master"
113 } > expected
115 test_expect_success \
116 'Test that "branch -c" filters as expected when multiple branches match' \
118 stats.py branch -c c0e49264fd921d2a62f90556340e371e719b45cc > actual
119 test_cmp expected actual
122 echo "junio" >> expected
124 test_expect_success 'Test that "branch -r" works as expected' '
125 stats.py branch -r -c c0e49264fd921d2a62f90556340e371e719b45cc > actual
126 test_cmp expected actual
130 ###########
131 # Commit tests
132 ###########
135 echo "commit e76ad031836912c01da47ab93d3c21676763267e
136 Author: A U Thor <author@example.com>
137 Date: Thu May 26 23:30:00 2005 +0000
139 Commit 3
141 notes.txt
143 commit e8fa5fed0d1823c1e3e120579b03343aecf26ab6
144 Author: A U Thor <author@example.com>
145 Date: Thu May 26 23:30:00 2005 +0000
147 Commit 2
149 notes.txt
151 commit bd952062891010102e3632aecd0f738a35c1fca3
152 Author: A U Thor <author@example.com>
153 Date: Thu May 26 23:30:00 2005 +0000
155 Commit 1
157 notes.txt
158 " > expected
160 test_expect_success 'Test that "commit -t" filters as expected' '
161 stats.py commit -t notes.txt > actual
162 test_cmp expected actual
165 test_expect_success 'commit tests setup' '
166 cd docs
169 test_expect_success 'Test that "commit -r" works as expected' '
170 stats.py commit -r -t README.txt
173 test_expect_success \
174 'Test that "commit -r" works as expected when the file was not found' \
176 test_must_fail stats.py commit -t README.txt
179 test_expect_success 'commit tests teardown' '
180 cd ..
183 echo "commit bc6d646fd15953cdb514d14458f013a1fc05153c
184 Author: A U Thor <author@example.com>
185 Date: Thu May 26 23:30:00 2005 +0000
187 Initial commit
189 content.txt
190 " > expected
192 test_expect_success 'Test that "commit --log" filters as expected' '
193 stats.py commit --log-contains=Initial > actual
194 test_cmp expected actual
197 test_expect_success 'Test that "commit --diff" filters as expected' '
198 stats.py commit --diff-contains=Initial > actual
199 test_cmp expected actual
203 ###########
204 # Diff tests
205 ###########
208 echo "Missing the following keys:
209 ('/dev/null', 'b/notes.txt')" > expected
211 test_expect_success \
212 'Test that "diff -e" works as expected for equal diffs in different files' \
214 stats.py diff -e bd9520628910101 3c34aec51560970c > actual
215 test_cmp expected actual
218 echo "Missing the following keys:
219 ('/dev/null', 'b/test.c')" > expected
221 test_expect_success \
222 'Test that "diff -e" works as expected for equal diffs in different files' \
224 stats.py diff -e 3c34aec51560970c bd9520628910101 > actual
225 test_cmp expected actual
228 echo "Equal" > expected
230 test_expect_success 'Test that "diff -e" works as expected for equal diffs' '
231 stats.py diff -e HEAD HEAD > actual
232 test_cmp expected actual
235 test_expect_success 'Test that "diff -n -e" works as expected' '
236 stats.py diff -n -e 90511e146e24b29 38aa44905fb99a6 > actual
237 test_cmp expected actual
240 echo "Equal" > expected
242 test_expect_success 'Test that "diff -i" works as expected for reverts' '
243 stats.py diff -i -e cc2d11f96d7ec43 c2d26c33f9e8eb6 > actual
244 test_cmp expected actual
248 ###########
249 # Index tests
250 ###########
253 test_expect_success 'index test setup' '
254 echo "Some Change" >> notes.txt
255 git add notes.txt
258 echo "commit e76ad031836912c01da47ab93d3c21676763267e
259 Author: A U Thor <author@example.com>
260 Date: Thu May 26 23:30:00 2005 +0000
262 Commit 3
264 notes.txt
266 commit e8fa5fed0d1823c1e3e120579b03343aecf26ab6
267 Author: A U Thor <author@example.com>
268 Date: Thu May 26 23:30:00 2005 +0000
270 Commit 2
272 notes.txt
274 commit bd952062891010102e3632aecd0f738a35c1fca3
275 Author: A U Thor <author@example.com>
276 Date: Thu May 26 23:30:00 2005 +0000
278 Commit 1
280 notes.txt
281 " > expected
283 test_expect_success \
284 'Test that "index -t" works as expected when there are staged changes' \
286 stats.py index -t > actual
287 test_cmp expected actual
290 test_expect_success 'index test teardown' '
291 git reset --hard HEAD
294 test_expect_success 'index -a test setup' '
295 git checkout erase
296 git reset --soft v2^
300 echo "No changes staged, no matching commits, or only new files added"
301 } > expected
303 test_expect_success 'Test that "index -t" without -a works as expected' '
304 stats.py index -t > actual
305 test_cmp expected actual
308 test_expect_success 'Test that "index -a" works as expected' '
309 stats.py index -a -t
312 test_expect_success 'index -a test teardown' '
313 git reset --hard v2
314 git checkout master
318 ###########
319 # Teardown
320 ###########
323 test_expect_success 'Teardown' '
324 cd $ORIG_PATH
327 test_done