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
|
|
|
|
|
|
2021-10-22 11:49:04 +11:00
|
|
|
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"* ]]
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 08:51:44 +11:00
|
|
|
@test "no deprecated set-output calls made" {
|
2024-04-24 12:18:29 +10:00
|
|
|
run grep -q "::set-output" version-lookup.sh
|
2022-10-19 08:51:44 +11:00
|
|
|
|
|
|
|
|
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 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"CURRENT_VERSION=0.1.2"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
2021-11-15 06:54:21 +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
|
2021-11-15 06:54:21 +11:00
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"CURRENT_VERSION=0.1.2"* ]] &&
|
|
|
|
|
[[ "$output" = *"CURRENT_V_VERSION=v0.1.2"* ]]
|
2021-11-15 06:54:21 +11:00
|
|
|
}
|
|
|
|
|
|
2024-08-30 11:05:23 +02:00
|
|
|
@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 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"CURRENT_VERSION=1.2.300"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
2024-08-31 13:16:51 +10:00
|
|
|
@test "finds only prefixed tags when tag_prefix set" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export tag_prefix="@org/product"
|
|
|
|
|
|
|
|
|
|
git tag @org/product@0.1.2
|
|
|
|
|
git tag @org/product@0.1.3-dev.123
|
|
|
|
|
git tag 2.4.5
|
|
|
|
|
git tag 2.4.6-dev.456
|
|
|
|
|
|
|
|
|
|
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 "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 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$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 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$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
|
|
|
|
|
|
2021-10-22 11:49:04 +11:00
|
|
|
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 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$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 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"CURRENT_VERSION=3.4.5"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|