Skip to content

Commit 2fd7105

Browse files
committed
add self-test for calc_release_version.py
1 parent b4c194e commit 2fd7105

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

etc/calc_release_version.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
current Git commit.
2323
"""
2424

25+
# XXX NOTE XXX NOTE XXX NOTE XXX
26+
# After modifying this script it is advisable to execute the self-test.
27+
#
28+
# This is done by starting in the directory containing this script and then
29+
# executing a separate self-test script, like this:
30+
#
31+
# $ bash ./calc_release_version_selftest.sh
32+
#
33+
# The self-test script will emit diagnostic output. If tracing of the execution
34+
# of each command is desired, then add the -x option to the bash invocation.
35+
# XXX NOTE XXX NOTE XXX NOTE XXX
36+
2537
import datetime
2638
import re
2739
import subprocess

etc/calc_release_version_selftest.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/bin/bash
2+
# calc_release_version_selftest.sh is used to test output of calc_release_version.py.
3+
# run with:
4+
# cd etc
5+
# ./calc_release_version_selftest.sh
6+
7+
set -o errexit
8+
set -o pipefail
9+
10+
function assert_eq () {
11+
a="$1"
12+
b="$2"
13+
if [[ "$a" != "$b" ]]; then
14+
echo "Assertion failed: $a != $b"
15+
# Print caller
16+
caller
17+
exit 1
18+
fi
19+
}
20+
21+
SAVED_REF=$(git rev-parse HEAD)
22+
23+
function cleanup () {
24+
[[ -e calc_release_version_test.py ]] && rm calc_release_version_test.py
25+
git checkout $SAVED_REF --quiet
26+
}
27+
28+
trap cleanup EXIT
29+
30+
: ${PYTHON_INTERP:=python}
31+
if [[ -z $(command -v "${PYTHON_INTERP}") ]]; then
32+
echo "Python interpreter '${PYTHON_INTERP}' is not valid."
33+
echo "Set the PYTHON_INTERP environment variable to a valid interpreter."
34+
exit 1
35+
fi
36+
37+
# copy calc_release_version.py to a separate file not tracked by git so it does not change on `git checkout`
38+
cp calc_release_version.py calc_release_version_test.py
39+
40+
echo "Test a tagged commit ... begin"
41+
{
42+
git checkout r3.7.2 --quiet
43+
got=$("${PYTHON_INTERP}" calc_release_version_test.py)
44+
assert_eq "$got" "3.7.2"
45+
git checkout - --quiet
46+
}
47+
echo "Test a tagged commit ... end"
48+
49+
DATE=$(date +%Y%m%d)
50+
echo "Test an untagged commit ... begin"
51+
{
52+
# 15756bff8640435b8647fe2eccf8d9c1f6d78816 is commit before r3.7.2
53+
git checkout 15756bff8640435b8647fe2eccf8d9c1f6d78816 --quiet
54+
got=$("${PYTHON_INTERP}" calc_release_version_test.py)
55+
assert_eq "$got" "3.7.2-$DATE+git15756bff86"
56+
git checkout - --quiet
57+
}
58+
echo "Test an untagged commit ... end"
59+
60+
echo "Test next minor version ... begin"
61+
{
62+
CURRENT_SHORTREF=$(git rev-parse --revs-only --short=10 HEAD)
63+
got=$("${PYTHON_INTERP}" calc_release_version_test.py --next-minor)
64+
# XXX NOTE XXX NOTE XXX
65+
# If you find yourself looking at this line because the assertion below
66+
# failed, then it is probably because a new major/minor release was made.
67+
# Update the expected output to represent the correct next version.
68+
# XXX NOTE XXX NOTE XXX
69+
assert_eq "$got" "3.9.0-$DATE+git$CURRENT_SHORTREF"
70+
}
71+
echo "Test next minor version ... end"
72+
73+
echo "All tests passed"

0 commit comments

Comments
 (0)