Skip to content

Instantly share code, notes, and snippets.

@kevinAlbs
Created May 25, 2023 21:50
Show Gist options
  • Save kevinAlbs/7105dce823f0732a1330cd4e17fc9213 to your computer and use it in GitHub Desktop.
Save kevinAlbs/7105dce823f0732a1330cd4e17fc9213 to your computer and use it in GitHub Desktop.
Proposed self tests of calc_release_version.py
# calc_release_version_selftest.sh is used to test output of calc_release_version.py.
# run with:
# cd build
# ./calc_release_version_selftest.sh
function assert_eq () {
a="$1"
b="$2"
if [[ "$a" != "$b" ]]; then
echo "Assertion failed: $a != $b"
# Print caller
caller
exit 1
fi
}
SAVED_REF=$(git rev-parse HEAD)
function cleanup () {
rm calc_release_version_test.py
git checkout $SAVED_REF --quiet
}
trap cleanup EXIT
# copy calc_release_version.py to a separate file not tracked by git so it does not change on `git checkout`
cp calc_release_version.py calc_release_version_test.py
echo "Test a tagged commit ... begin"
{
git checkout 1.23.4 --quiet
got=$(python calc_release_version_test.py)
assert_eq "$got" "1.23.4"
got=$(python calc_release_version_test.py -p)
assert_eq "$got" "1.23.3"
git checkout - --quiet
}
echo "Test a tagged commit ... end"
DATE=$(date +%Y%m%d)
echo "Test an untagged commit ... begin"
{
# 42a818429d6d586a6abf22367ac6fea1e9ce3f2c is commit before 1.23.4
git checkout 42a818429d6d586a6abf22367ac6fea1e9ce3f2c --quiet
got=$(python calc_release_version_test.py)
assert_eq "$got" "1.23.4-$DATE+git42a818429d"
got=$(python calc_release_version_test.py -p)
assert_eq "$got" "1.23.4"
git checkout - --quiet
}
echo "Test an untagged commit ... end"
echo "Test next minor version ... begin"
{
CURRENT_SHORTREF=$(git rev-parse --revs-only --short=10 HEAD)
got=$(python calc_release_version_test.py --next-minor)
# The expected output may need to be updated after a release.
assert_eq "$got" "1.24.0-$DATE+git$CURRENT_SHORTREF"
got=$(python calc_release_version_test.py --next-minor -p)
# The expected output may need to be updated after a release.
assert_eq "$got" "1.23.4"
}
echo "Test next minor version ... end"
echo "All tests passed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment