gitstats: Licensed GitStats under the Apache License, 2.0
[git-stats.git] / src / t / t8101-metrics.sh
blob108a4ec6d57e2bdffd500fe7febbfdaa110194bd
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
11 PATH=$ORIG_PATH/..:$PATH
13 . ./test-lib.sh
15 export PATH
17 ###########
18 # Setup
19 ###########
21 test_expect_success 'extract test repo path' '
22 METRICS_REPO_PATH=$(python ../scripts/setupRepo.py metrics path) || {
23 trap - exit
24 echo >&5 "FATAL: Cannot extract test repo path"
25 exit 1
29 test_expect_success 'pre-clean' '
30 rm -fr "$METRICS_REPO_PATH" || {
31 trap - exit
32 echo >&5 "FATAL: Cannot clean the fresh repo"
33 exit 1
37 test_expect_success 'setup' '
38 python ../scripts/setupRepo.py metrics path "$METRICS_REPO_PATH" && \
39 cd "$METRICS_REPO_PATH" || {
40 trap - exit
41 echo >&5 "FATAL: Cannot cd into fresh repo"
42 exit 1
46 test_expect_success 'Test that stats.py is reachable' '
47 stats.py -v || {
48 trap - exit
49 echo >&5 "FATAL: stats.py not reachable"
50 exit 1
54 echo "e5aa8fcf1233ea51764bad0d929ed15dc5c90dc1" > expected
56 test_expect_success 'Test that the expected tree was created by setupRepo' '
57 git rev-parse HEAD > actual
58 test_cmp expected actual || {
59 trap - exit
60 echo >&5 "FATAL: Head revision does not match"
61 exit 1
66 ###########
67 # Belongs to
68 ###########
70 echo "Matching branches:
71 master
72 maint
73 side" > expected
75 test_expect_success 'Test that the initial revision is owned by all' '
76 stats.py branch -b a23d994 > actual
77 test_cmp expected actual
80 echo "Matching branches:
81 master" > expected
83 test_expect_success \
84 'Test that a commit made on the master branch belongs only to master' \
86 stats.py branch -b 2e560d2 > actual
87 test_cmp expected actual
90 test_expect_success \
91 'Test that the dilution is correct when another branch is merged in later on' \
93 stats.py branch -b 866d9d7 > actual
94 test_cmp expected actual
97 echo "Matching branches:
98 maint
99 side" > expected
101 # It should belong to both maint and side since side was
102 # branched off from maint after the tested commit was made.
103 # Tested are:
104 # * The point where side branched off from maint
105 # * A point before the branch off point
106 # * A commit on a side branch that was merged in
107 test_expect_success \
108 'Test that a commit made on maint belongs to both maint and side' \
110 stats.py branch -b 38c3784 > actual1
111 stats.py branch -b 9a0b6cc > actual2
112 stats.py branch -b 442be4c > actual3
113 test_cmp expected actual1 &&
114 test_cmp expected actual2 &&
115 test_cmp expected actual3
118 echo "Matching branches:
119 maint" > expected
121 test_expect_success \
122 'Test that a merge commit belongs to the branch the merge was done on' \
124 stats.py branch -b 4ff12b2 > actual
125 test_cmp expected actual
128 echo "Matching branches:
129 side" > expected
131 test_expect_success \
132 'Test that the base of a merge belongs to the branch the merge was based on' \
134 stats.py branch -b 40843d5 > actual
135 test_cmp expected actual
138 test_expect_success \
139 'Test that the dilution is correct when other branches merge with its branch' \
141 stats.py branch -b bb33bd1 > actual
142 test_cmp expected actual
145 test_expect_success \
146 'Test that a branch made on side, and not merged later, belongs to side' \
148 stats.py branch -b 698a02f > actual
149 test_cmp expected actual
153 ###########
154 # Teardown
155 ###########
158 test_expect_success 'Teardown' '
159 cd $ORIG_PATH
162 test_done