summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2017-09-08 13:12:30 +0200
committerMichał Górny <mgorny@gentoo.org>2017-09-19 13:08:26 +0200
commit59a1a0dda7300177a263eb1de347da493f09fdee (patch)
tree58f85d3b329b2807e588ae4aacc8144532bd8df4 /eclass/tests
parentnet-vpn/tor: version bump to 0.3.2.1_alpha (diff)
downloadgentoo-59a1a0dda7300177a263eb1de347da493f09fdee.tar.gz
gentoo-59a1a0dda7300177a263eb1de347da493f09fdee.tar.bz2
gentoo-59a1a0dda7300177a263eb1de347da493f09fdee.zip
eapi7-ver.eclass: 'Early adopter' version of EAPI 7 version manip
EAPI 7 is introducing new version manipulation and comparison functions that aim to replace versionator.eclass. This eclass provides an 'early adopter' versions of those routines. It serves two goals: a. getting wider review and some real-life testing before the specification is set in stone, b. making it possible to adapt ebuilds to the new routines early, reducing the future work of EAPI 7 porting, c. improving cache generation speed (the rountines are roughly 15-20 times than versionator.eclass). For more details on the new logic, please see the eclass documentation. Long story short, we are introducing three functions: 1. ver_cut -- to get substrings of the version string, 2. ver_rs -- to replace version separators via indices, 3. ver_test -- to compare two version numbers. The third function is not implemented in the eclass. It's meant to reuse the algorithms from the package manager, and the final implementation will most likely reuse the code from the package manager (e.g. via IPC). The code has been initially written by Ulrich Müller.
Diffstat (limited to 'eclass/tests')
-rwxr-xr-xeclass/tests/eapi7-ver.sh65
-rwxr-xr-xeclass/tests/eapi7-ver_benchmark.sh113
2 files changed, 178 insertions, 0 deletions
diff --git a/eclass/tests/eapi7-ver.sh b/eclass/tests/eapi7-ver.sh
new file mode 100755
index 000000000000..8a96e4d29b1b
--- /dev/null
+++ b/eclass/tests/eapi7-ver.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+source tests-common.sh
+
+inherit eapi7-ver
+
+teq() {
+ local expected=${1}; shift
+
+ tbegin "${*} -> ${expected}"
+ local got=$("${@}")
+ [[ ${got} == ${expected} ]]
+ tend ${?} "returned: ${got}"
+}
+
+txf() {
+ tbegin "XFAIL: ${*}"
+ local got=$("${@}" 2>&1)
+ [[ ${got} == die:* ]]
+ tend ${?} "function did not die"
+}
+
+teq 1 ver_cut 1 1.2.3
+teq 1 ver_cut 1-1 1.2.3
+teq 1.2 ver_cut 1-2 1.2.3
+teq 2.3 ver_cut 2- 1.2.3
+teq 1.2.3 ver_cut 1- 1.2.3
+teq 3b ver_cut 3-4 1.2.3b_alpha4
+teq alpha ver_cut 5 1.2.3b_alpha4
+teq 1.2 ver_cut 1-2 .1.2.3
+teq .1.2 ver_cut 0-2 .1.2.3
+teq 2.3 ver_cut 2-3 1.2.3.
+teq 2.3. ver_cut 2- 1.2.3.
+teq 2.3. ver_cut 2-4 1.2.3.
+
+teq 1-2.3 ver_rs 1 - 1.2.3
+teq 1.2-3 ver_rs 2 - 1.2.3
+teq 1-2-3.4 ver_rs 1-2 - 1.2.3.4
+teq 1.2-3-4 ver_rs 2- - 1.2.3.4
+teq 1.2.3 ver_rs 2 . 1.2-3
+teq 1.2.3.a ver_rs 3 . 1.2.3a
+teq 1.2-alpha-4 ver_rs 2-3 - 1.2_alpha4
+teq 1.23-b_alpha4 ver_rs 3 - 2 "" 1.2.3b_alpha4
+teq a1b_2-c-3-d4e5 ver_rs 3-5 _ 4-6 - a1b2c3d4e5
+teq .1-2.3 ver_rs 1 - .1.2.3
+teq -1.2.3 ver_rs 0 - .1.2.3
+
+# truncating range
+teq 1.2 ver_cut 0-2 1.2.3
+teq 2.3 ver_cut 2-5 1.2.3
+teq "" ver_cut 4 1.2.3
+teq "" ver_cut 0 1.2.3
+teq "" ver_cut 4- 1.2.3
+teq 1.2.3 ver_rs 0 - 1.2.3
+teq 1.2.3 ver_rs 3 . 1.2.3
+teq 1.2.3 ver_rs 3- . 1.2.3
+teq 1.2.3 ver_rs 3-5 . 1.2.3
+
+txf ver_cut foo 1.2.3
+txf ver_rs -3 _ a1b2c3d4e5
+txf ver_rs 5-3 _ a1b2c3d4e5
diff --git a/eclass/tests/eapi7-ver_benchmark.sh b/eclass/tests/eapi7-ver_benchmark.sh
new file mode 100755
index 000000000000..7e3c830fcb75
--- /dev/null
+++ b/eclass/tests/eapi7-ver_benchmark.sh
@@ -0,0 +1,113 @@
+#!/bin/bash
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+source tests-common.sh
+
+inherit eapi7-ver versionator
+
+cutting() {
+ local x
+ for x in {1..1000}; do
+ ver_cut 1 1.2.3
+ ver_cut 1-2 1.2.3
+ ver_cut 2- 1.2.3
+ ver_cut 1- 1.2.3
+ ver_cut 3-4 1.2.3b_alpha4
+ ver_cut 5 1.2.3b_alpha4
+ ver_cut 1-2 .1.2.3
+ ver_cut 0-2 .1.2.3
+ ver_cut 2-3 1.2.3.
+ ver_cut 2- 1.2.3.
+ ver_cut 2-4 1.2.3.
+ done >/dev/null
+}
+
+cutting_versionator() {
+ local x
+ for x in {1..100}; do
+ get_version_component_range 1 1.2.3
+ get_version_component_range 1-2 1.2.3
+ get_version_component_range 2- 1.2.3
+ get_version_component_range 1- 1.2.3
+ get_version_component_range 3-4 1.2.3b_alpha4
+ get_version_component_range 5 1.2.3b_alpha4
+ get_version_component_range 1-2 .1.2.3
+ get_version_component_range 0-2 .1.2.3
+ get_version_component_range 2-3 1.2.3.
+ get_version_component_range 2- 1.2.3.
+ get_version_component_range 2-4 1.2.3.
+ done >/dev/null
+}
+
+replacing() {
+ local x
+ for x in {1..1000}; do
+ ver_rs 1 - 1.2.3
+ ver_rs 2 - 1.2.3
+ ver_rs 1-2 - 1.2.3.4
+ ver_rs 2- - 1.2.3.4
+ ver_rs 2 . 1.2-3
+ ver_rs 3 . 1.2.3a
+ ver_rs 2-3 - 1.2_alpha4
+ #ver_rs 3 - 2 "" 1.2.3b_alpha4
+ #ver_rs 3-5 _ 4-6 - a1b2c3d4e5
+ ver_rs 1 - .1.2.3
+ ver_rs 0 - .1.2.3
+ done >/dev/null
+}
+
+replacing_versionator() {
+ local x
+ for x in {1..100}; do
+ replace_version_separator 1 - 1.2.3
+ replace_version_separator 2 - 1.2.3
+ replace_version_separator 1-2 - 1.2.3.4
+ replace_version_separator 2- - 1.2.3.4
+ replace_version_separator 2 . 1.2-3
+ replace_version_separator 3 . 1.2.3a
+ replace_version_separator 2-3 - 1.2_alpha4
+ #replace_version_separator 3 - 2 "" 1.2.3b_alpha4
+ #replace_version_separator 3-5 _ 4-6 - a1b2c3d4e5
+ replace_version_separator 1 - .1.2.3
+ replace_version_separator 0 - .1.2.3
+ done >/dev/null
+}
+
+get_times() {
+ local factor=${1}; shift
+ echo "${*}"
+ local real=()
+ local user=()
+
+ for x in {1..5}; do
+ while read tt tv; do
+ case ${tt} in
+ real) real+=( $(dc -e "${tv} ${factor} * p") );;
+ user) user+=( $(dc -e "${tv} ${factor} * p") );;
+ esac
+ done < <( ( time -p "${@}" ) 2>&1 )
+ done
+
+ [[ ${#real[@]} == 5 ]] || die "Did not get 5 real times"
+ [[ ${#user[@]} == 5 ]] || die "Did not get 5 user times"
+
+ local sum
+ for v in real user; do
+ vr="${v}[*]"
+ sum=$(dc -e "${!vr} + + + + 3 k 5 / p")
+
+ vr="${v}[@]"
+ printf '%s %4.2f %4.2f %4.2f %4.2f %4.2f %4.2f\n' \
+ "${v}" "${!vr}" "${sum}"
+ done
+}
+
+export LC_ALL=C
+
+get_times 1 cutting
+get_times 10 cutting_versionator
+get_times 1 replacing
+get_times 10 replacing_versionator