mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
makefiles/utils/strings.mk: add version_greater_or_equal
This commit is contained in:
parent
ba4228cccf
commit
e455ccd3c0
@ -33,3 +33,16 @@ _is_greater = $(if $(filter $1,$(firstword $(sort $1 $2))),,1)
|
||||
# Return 1 if $1 is greater than $2, nothing otherwise
|
||||
version_is_greater = $(call _is_greater,$(call _padded_version,$1),\
|
||||
$(call _padded_version,$2))
|
||||
|
||||
# Checks if version $1 is equal to version $2
|
||||
# $1,$2: version to check, '.' separated version 'major.minor.patch'
|
||||
# Return 1 if $1 equal to $2, nothing otherwise
|
||||
_is_equal = $(if $(and $(findstring $(1),$(2)),$(findstring $(2),$(1))),1,)
|
||||
|
||||
# Checks if version $1 is greater or equal than version $2
|
||||
# $1: version to check, '.' separated version 'major.minor.patch'
|
||||
# $2: minimum version, '.' separated version 'major.minor.patch'
|
||||
# Return 1 if $1 is greater or equal than $2, nothing otherwise
|
||||
version_is_greater_or_equal = $(or \
|
||||
$(call _is_greater,$(call _padded_version,$1),$(call _padded_version,$2)),\
|
||||
$(call _is_equal,$(call _padded_version,$1),$(call _padded_version,$2)))
|
||||
|
@ -18,6 +18,7 @@ TEST_VERSION_1 = 4.1
|
||||
TEST_VERSION_2 = 3.10
|
||||
TEST_VERSION_3 = 4.2.3
|
||||
TEST_VERSION_4 = 4.19.3
|
||||
TEST_VERSION_5 = 4.1.0
|
||||
|
||||
test-version_is_greater:
|
||||
$(Q)bash -c 'test 1 = "$(call version_is_greater,$(TEST_VERSION_1),$(TEST_VERSION_2))" || { echo ERROR: "$(TEST_VERSION_2)" \< "$(TEST_VERSION_1)"; exit 1; }'
|
||||
@ -25,3 +26,12 @@ test-version_is_greater:
|
||||
$(Q)bash -c 'test 1 = "$(call version_is_greater,$(TEST_VERSION_4),$(TEST_VERSION_3))" || { echo ERROR: "$(TEST_VERSION_3)" \< "$(TEST_VERSION_4)"; exit 1; }'
|
||||
$(Q)bash -c 'test "" = "$(call version_is_greater,$(TEST_VERSION_3),$(TEST_VERSION_4))" || { echo ERROR: Test should fail, "$(TEST_VERSION_4)" is not \< "$(TEST_VERSION_3)"; exit 1; }'
|
||||
$(Q)bash -c 'test "" = "$(call version_is_greater,$(TEST_VERSION_1),$(TEST_VERSION_4))" || { echo ERROR: Test should fail, "$(TEST_VERSION_1)" is not \< "$(TEST_VERSION_4)"; exit 1; }'
|
||||
|
||||
test-version_is_greater_or_equal:
|
||||
$(Q)bash -c 'test 1 = "$(call version_is_greater_or_equal,$(TEST_VERSION_1),$(TEST_VERSION_5))" || { echo ERROR: "$(TEST_VERSION_5)" == "$(TEST_VERSION_1)"; exit 1; }'
|
||||
$(Q)bash -c 'test 1 = "$(call version_is_greater_or_equal,$(TEST_VERSION_1),$(TEST_VERSION_1))" || { echo ERROR: "$(TEST_VERSION_1)" == "$(TEST_VERSION_1)"; exit 1; }'
|
||||
$(Q)bash -c 'test 1 = "$(call version_is_greater_or_equal,$(TEST_VERSION_3),$(TEST_VERSION_3))" || { echo ERROR: "$(TEST_VERSION_3)" == "$(TEST_VERSION_3)"; exit 1; }'
|
||||
$(Q)bash -c 'test 1 = "$(call version_is_greater_or_equal,$(TEST_VERSION_3),$(TEST_VERSION_1))" || { echo ERROR: "$(TEST_VERSION_1)" \< "$(TEST_VERSION_3)"; exit 1; }'
|
||||
$(Q)bash -c 'test 1 = "$(call version_is_greater_or_equal,$(TEST_VERSION_4),$(TEST_VERSION_3))" || { echo ERROR: "$(TEST_VERSION_3)" \< "$(TEST_VERSION_4)"; exit 1; }'
|
||||
$(Q)bash -c 'test "" = "$(call version_is_greater_or_equal,$(TEST_VERSION_3),$(TEST_VERSION_4))" || { echo ERROR: Test should fail, "$(TEST_VERSION_4)" is not \< "$(TEST_VERSION_3)"; exit 1; }'
|
||||
$(Q)bash -c 'test "" = "$(call version_is_greater_or_equal,$(TEST_VERSION_1),$(TEST_VERSION_4))" || { echo ERROR: Test should fail, "$(TEST_VERSION_1)" is not \< "$(TEST_VERSION_4)"; exit 1; }'
|
||||
|
@ -23,6 +23,7 @@ COMPILE_TESTS += test-lowercase
|
||||
COMPILE_TESTS += test-uppercase
|
||||
COMPILE_TESTS += test-uppercase_and_underscore
|
||||
COMPILE_TESTS += test-version_is_greater
|
||||
COMPILE_TESTS += test-version_is_greater_or_equal
|
||||
|
||||
# Tests will be run both in the host machine and in `docker`
|
||||
all: build-system-utils-tests
|
||||
@ -55,3 +56,6 @@ test-uppercase_and_underscore:
|
||||
|
||||
test-version_is_greater:
|
||||
$(Q)$(call command_should_succeed,"$(MAKE)" -C $(MAKEFILES_UTILS) -f test-strings.mk test-version_is_greater)
|
||||
|
||||
test-version_is_greater_or_equal:
|
||||
$(Q)$(call command_should_succeed,"$(MAKE)" -C $(MAKEFILES_UTILS) -f test-strings.mk test-version_is_greater_or_equal)
|
||||
|
Loading…
Reference in New Issue
Block a user