gitstats: Don't assume the temp path is /tmp
[git-stats.git] / src / t / t8100-stats.sh
blob314ada4d3b87303274eb3fd3edf4b67643c5f742
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
14 export GIT_STATS_PRETTY_PRINT="oneline"
16 ###########
17 # Setup
18 ###########
20 test_expect_success 'extract test repo path' '
21 TEST_REPO_PATH=$(../scripts/setupRepo.py test path) || {
22 trap - exit
23 echo >&5 "FATAL: Cannot extract test repo path"
24 exit 1
28 test_expect_success 'pre-clean' '
29 rm -fr "$TEST_REPO_PATH" || {
30 trap - exit
31 echo >&5 "FATAL: Cannot clean the fresh repo"
32 exit 1
36 test_expect_success 'setup' '
37 ../scripts/setupRepo.py test path "$TEST_REPO_PATH" && \
38 cd "$TEST_REPO_PATH" || {
39 trap - exit
40 echo >&5 "FATAL: Cannot cd into fresh repo"
41 exit 1
45 test_expect_success 'Test that stats.py is reachable' '
46 stats.py -v || {
47 trap - exit
48 echo >&5 "FATAL: stats.py not reachable"
49 exit 1
53 echo "f1fdf284733011b1172b4517b4526879059bb414" > expected
55 test_expect_success 'Test that the expected tree was created by setupRepo' '
56 git rev-parse HEAD > actual
57 test_cmp expected actual || {
58 trap - exit
59 echo >&5 "FATAL: Head revision does not match"
60 exit 1
65 ###########
66 # Author tests
67 ###########
69 echo " 23: 23+ 1- 22~ = content.txt
70 10: 8+ 2- 6~ = docs/README.txt
71 3: 3+ 0- 3~ = notes.txt" > expected
73 test_expect_success \
74 'Test that "author -d" filters as expected for the primary author' \
76 stats.py author -d "author@example.com" > actual
77 test_cmp expected actual
80 echo " 2: 2+ 0- 2~ = content.txt" > expected
82 test_expect_success \
83 'Test that "author -d" filters as expected for the secondary author' \
85 stats.py author -d "roh.tua@example.com" > actual
86 test_cmp expected actual
89 echo "author@example.com:
90 23: 23+ 1- 22~ = content.txt
91 10: 8+ 2- 6~ = docs/README.txt
92 3: 3+ 0- 3~ = notes.txt
94 roh.tua@example.com:
95 2: 2+ 0- 2~ = content.txt
96 " > expected
98 test_expect_success \
99 'Test that "author -e" shows stats for all authors' \
101 stats.py author -e > actual
102 test_cmp expected actual
105 echo "author@example.com: 24
106 roh.tua@example.com: 2" > expected
108 test_expect_success 'Test that "author -f" aggregates as expected' '
109 stats.py author --file=content.txt > actual
110 test_cmp expected actual
113 echo " 25: 25+ 1- 24~ = content.txt
114 10: 8+ 2- 6~ = docs/README.txt
115 3: 3+ 0- 3~ = notes.txt" > expected
117 test_expect_success 'Test that "author -a" aggregates as expected' '
118 stats.py author -a > actual
119 test_cmp expected actual
122 ###########
123 # Branch tests
124 ###########
127 echo "Matching branches:"
128 echo "pu"
129 } > expected
131 test_expect_success 'Test that "branch -c" filters as expected' '
132 stats.py branch -c v0 > actual
133 test_cmp expected actual
137 echo "Matching branches:"
138 echo "erase"
139 echo "maint"
140 echo "master"
141 } > expected
143 test_expect_success \
144 'Test that "branch -c" filters as expected when multiple branches match' \
146 stats.py branch -c v1 > actual
147 test_cmp expected actual
150 echo "junio" >> expected
152 test_expect_success 'Test that "branch -r" works as expected' '
153 stats.py branch -r -c v1 > actual
154 test_cmp expected actual
158 ###########
159 # Commit tests
160 ###########
163 echo "3b0e7ae64f1b39f7b23d789a9d472443dd00c6fb Commit 3
164 9ae22dc6a76c6ac715cc9fe6a011156ca042f480 Commit 2
165 ae9fd667fe1611e0648a2ebec65788b63bb3ce16 Commit 1" > expected
167 test_expect_success 'Test that "commit -t" filters as expected' '
168 stats.py commit -t notes.txt > actual
169 test_cmp expected actual
172 test_expect_success 'commit tests setup' '
173 cd docs
176 echo 'f1fdf284733011b1172b4517b4526879059bb414 Last commit
177 4de759680bf8bd7b51e3a0481d027ee441998542 Revert "Commit 6"
178 255ef82de488015b727e0202f0dfe8ed82443ebb Commit 6
179 4838591dcda04acd0e8882397c5c681af09c9076 Revert "Last commit"
180 4b650481338f95cd8afbc113bd15cd85d94c0c3a Last commit
181 37837a72217f8da3f056d5aa8b159412b93efd69 Commit 5
182 a03fc7e69239cc3e29c96ebf74e7d22e2d72bbef Commit 4
183 39f4923417895119ac26524c572dbd198570f054 Commit 3
184 3302051a5e010ede6cdb6d8fa66cff7e89f63b28 Commit 2
185 7bd493f55b8b0b0c59c08ca5be7c8f98fb159885 Commit 1' > expected
187 test_expect_success 'Test that "commit -r" works as expected' '
188 stats.py commit -r -t README.txt > actual
189 test_cmp expected actual
192 test_expect_success \
193 'Test that "commit -r" works as expected when the file was not found' \
195 test_must_fail stats.py commit -t README.txt
198 test_expect_success 'commit tests teardown' '
199 cd ..
202 echo "9ebfa8e247b99c0ba0198244d574734899dac987 Initial commit" > expected
204 test_expect_success 'Test that "commit --log" filters as expected' '
205 stats.py commit --log-contains=Initial > actual
206 test_cmp expected actual
209 test_expect_success 'Test that "commit --diff" filters as expected' '
210 stats.py commit --diff-contains=Initial > actual
211 test_cmp expected actual
215 ###########
216 # Diff tests
217 ###########
220 echo "Missing the following keys:
221 ('a/test.c', 'b/test.c')" > expected
223 test_expect_success \
224 'Test that "diff -e" works as expected for equal diffs in different files' \
226 stats.py diff -e v0 v4 > actual
227 test_cmp expected actual
230 echo "Missing the following keys:
231 ('a/docs/README.txt', 'b/docs/README.txt')" > expected
233 test_expect_success \
234 'Test that "diff -e" works as expected for equal diffs in different files' \
236 stats.py diff -e v4 v0 > actual
237 test_cmp expected actual
240 echo "Equal" > expected
242 test_expect_success 'Test that "diff -e" works as expected for equal diffs' '
243 stats.py diff -e HEAD HEAD > actual
244 test_cmp expected actual
247 test_expect_success 'Test that "diff -n -e" works as expected' '
248 stats.py diff -n -e v2 v3 > actual
249 test_cmp expected actual
252 echo "Equal" > expected
254 test_expect_success 'Test that "diff -i" works as expected for reverts' '
255 stats.py diff -i -e v2 v3^ > actual
256 test_cmp expected actual
260 ###########
261 # Index tests
262 ###########
265 test_expect_success 'index test setup' '
266 echo "Some Change" >> notes.txt
267 git add notes.txt
270 echo "3b0e7ae64f1b39f7b23d789a9d472443dd00c6fb Commit 3
271 9ae22dc6a76c6ac715cc9fe6a011156ca042f480 Commit 2
272 ae9fd667fe1611e0648a2ebec65788b63bb3ce16 Commit 1" > expected
274 test_expect_success \
275 'Test that "index -t" works as expected when there are staged changes' \
277 stats.py index -t > actual
278 test_cmp expected actual
281 test_expect_success 'index test teardown' '
282 git reset --hard HEAD
285 test_expect_success 'index -a test setup' '
286 git checkout erase
287 git reset --soft v5^
291 echo "No changes staged, no matching commits, or only new files added"
292 } > expected
294 test_expect_success 'Test that "index -t" without -a works as expected' '
295 stats.py index -t > actual
296 test_cmp expected actual
299 echo '28b2600cf58d478b4b937262218e363c88756b89 Deleted file docs/README.txt
300 f1fdf284733011b1172b4517b4526879059bb414 Last commit
301 4de759680bf8bd7b51e3a0481d027ee441998542 Revert "Commit 6"
302 255ef82de488015b727e0202f0dfe8ed82443ebb Commit 6
303 4838591dcda04acd0e8882397c5c681af09c9076 Revert "Last commit"
304 4b650481338f95cd8afbc113bd15cd85d94c0c3a Last commit
305 37837a72217f8da3f056d5aa8b159412b93efd69 Commit 5
306 a03fc7e69239cc3e29c96ebf74e7d22e2d72bbef Commit 4
307 39f4923417895119ac26524c572dbd198570f054 Commit 3
308 3302051a5e010ede6cdb6d8fa66cff7e89f63b28 Commit 2
309 7bd493f55b8b0b0c59c08ca5be7c8f98fb159885 Commit 1' > expected
311 test_expect_success 'Test that "index -a" works as expected' '
312 stats.py index -a -t > actual
313 test_cmp expected actual
316 test_expect_success 'index -a test teardown' '
317 git reset --hard v5
318 git checkout master
322 ###########
323 # Teardown
324 ###########
327 test_expect_success 'Teardown' '
328 cd $ORIG_PATH
331 test_done