Files
version-increment/tests/test_version-lookup.bats

164 lines
3.3 KiB
Plaintext
Raw Normal View History

2021-10-20 11:18:23 +11:00
#!/usr/bin/env bats
# vim: set ft=sh sw=4 :
load helper_print-info
export repo=".tmp_testing/repo"
2024-03-05 14:27:19 +01:00
setup() {
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
# make executables in src/ visible to PATH
PATH="$DIR/../:$PATH"
}
2021-10-20 11:18:23 +11:00
function init_repo {
rm -rf "${repo}" &&
mkdir -p "${repo}" &&
cd "${repo}" &&
git init &&
touch README.md &&
git add README.md &&
git config user.email test@example.com &&
git config user.name Tester &&
git commit -m "README"
}
@test "fails if invalid scheme given" {
init_repo
export scheme="foover"
2021-10-20 11:18:23 +11:00
2024-03-05 14:27:19 +01:00
run version-lookup.sh
2021-10-20 11:18:23 +11:00
print_run_info
[ "$status" -eq 8 ] &&
[[ "$output" = *"Value of 'scheme' is not valid"* ]]
}
@test "no deprecated set-output calls made" {
run grep -q "::set-output" version-lookup.sh
print_run_info
[ "$status" -eq 1 ]
}
2021-10-20 11:18:23 +11:00
@test "finds the current normal version" {
init_repo
git tag 0.0.1
git tag 0.1.1
git tag 0.1.2
2024-03-05 14:27:19 +01:00
run version-lookup.sh
2021-10-20 11:18:23 +11:00
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=0.1.2"* ]]
2021-10-20 11:18:23 +11:00
}
@test "prefixes with a v" {
init_repo
git tag 0.1.2
2024-03-05 14:27:19 +01:00
run version-lookup.sh
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=0.1.2"* ]] &&
[[ "$output" = *"CURRENT_V_VERSION=v0.1.2"* ]]
}
@test "finds the current normal version with tag_prefix enabled" {
init_repo
export tag_prefix="@org/product"
git tag @org/product@0.0.1
git tag @org/product@0.1.1
git tag @org/product@0.1.2
run version-lookup.sh
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=0.1.2"* ]]
}
@test "tag_prefix enabled prefixes with a v" {
init_repo
export tag_prefix="@org/product"
git tag @org/product@0.1.2
run version-lookup.sh
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=0.1.2"* ]] &&
[[ "$output" = *"CURRENT_V_VERSION=v0.1.2"* ]]
}
2021-10-20 11:18:23 +11:00
@test "finds the current normal version even if there's a newer pre-release version" {
init_repo
git tag 1.2.300
git tag 1.2.301-dev.234
2024-03-05 14:27:19 +01:00
run version-lookup.sh
2021-10-20 11:18:23 +11:00
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=1.2.300"* ]]
2021-10-20 11:18:23 +11:00
}
@test "returns 0.0.0 if no normal version detected" {
init_repo
2024-03-05 14:27:19 +01:00
run version-lookup.sh
2021-10-20 11:18:23 +11:00
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=0.0.0"* ]]
2021-10-20 11:18:23 +11:00
}
@test "returns 0.0.0 if no normal version detected even if there's a pre-release version" {
init_repo
git tag 0.0.1-dev.999
2024-03-05 14:27:19 +01:00
run version-lookup.sh
2021-10-20 11:18:23 +11:00
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=0.0.0"* ]]
2021-10-20 11:18:23 +11:00
}
@test "returns a calver if no normal version detected and calver scheme specified" {
init_repo
export scheme="calver"
2021-10-20 11:18:23 +11:00
2024-03-05 14:27:19 +01:00
run version-lookup.sh
2021-10-20 11:18:23 +11:00
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=$(date '+%Y.%-m.0')"* ]]
2021-10-20 11:18:23 +11:00
}
@test "strips v from the version" {
init_repo
git tag v3.4.5
2024-03-05 14:27:19 +01:00
run version-lookup.sh
2021-10-20 11:18:23 +11:00
print_run_info
[ "$status" -eq 0 ] &&
[[ "$output" = *"CURRENT_VERSION=3.4.5"* ]]
2021-10-20 11:18:23 +11:00
}