Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The existing vercmp_numbers function only handles, as the name says, numbers. I noticed that "sort" has had a version sort for a long time [1] and, rather than re-implement it badly, use this as a version of vercmp that works a bit more naturally. This is intended to be used in an "if" statement as in prog_ver=$(prog_ver --version | grep ...) if vercmp $prog_ver "<" 2.0; then ... fi A test-case is added to test the basic features and some edge-cases. [1] http://git.savannah.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=4c9fae4e97d95a9f89d1399a8aeb03051f0fec96 Change-Id: Ie55283acdc40a095b80b2631a55310072883ad0d
- Loading branch information
Showing
3 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Tests for DevStack vercmp functionality | ||
|
||
TOP=$(cd $(dirname "$0")/.. && pwd) | ||
|
||
# Import common functions | ||
source $TOP/functions | ||
source $TOP/tests/unittest.sh | ||
|
||
assert_true "numeric gt" vercmp 2.0 ">" 1.0 | ||
assert_true "numeric gte" vercmp 2.0 ">=" 1.0 | ||
assert_true "numeric gt" vercmp 1.0.1 ">" 1.0 | ||
assert_true "numeric gte" vercmp 1.0.1 ">=" 1.0 | ||
assert_true "alpha gt" vercmp 1.0.1b ">" 1.0.1a | ||
assert_true "alpha gte" vercmp 1.0.1b ">=" 1.0.1a | ||
assert_true "alpha gt" vercmp b ">" a | ||
assert_true "alpha gte" vercmp b ">=" a | ||
assert_true "alpha gt" vercmp 2.0-rc3 ">" 2.0-rc1 | ||
assert_true "alpha gte" vercmp 2.0-rc3 ">=" 2.0-rc1 | ||
|
||
assert_false "numeric gt fail" vercmp 1.0 ">" 1.0 | ||
assert_true "numeric gte" vercmp 1.0 ">=" 1.0 | ||
assert_false "numeric gt fail" vercmp 0.9 ">" 1.0 | ||
assert_false "numeric gte fail" vercmp 0.9 ">=" 1.0 | ||
assert_false "numeric gt fail" vercmp 0.9.9 ">" 1.0 | ||
assert_false "numeric gte fail" vercmp 0.9.9 ">=" 1.0 | ||
assert_false "numeric gt fail" vercmp 0.9a.9 ">" 1.0.1 | ||
assert_false "numeric gte fail" vercmp 0.9a.9 ">=" 1.0.1 | ||
|
||
assert_false "numeric lt" vercmp 1.0 "<" 1.0 | ||
assert_true "numeric lte" vercmp 1.0 "<=" 1.0 | ||
assert_true "numeric lt" vercmp 1.0 "<" 1.0.1 | ||
assert_true "numeric lte" vercmp 1.0 "<=" 1.0.1 | ||
assert_true "alpha lt" vercmp 1.0.1a "<" 1.0.1b | ||
assert_true "alpha lte" vercmp 1.0.1a "<=" 1.0.1b | ||
assert_true "alpha lt" vercmp a "<" b | ||
assert_true "alpha lte" vercmp a "<=" b | ||
assert_true "alpha lt" vercmp 2.0-rc1 "<" 2.0-rc3 | ||
assert_true "alpha lte" vercmp 2.0-rc1 "<=" 2.0-rc3 | ||
|
||
assert_true "eq" vercmp 1.0 "==" 1.0 | ||
assert_true "eq" vercmp 1.0.1 "==" 1.0.1 | ||
assert_false "eq fail" vercmp 1.0.1 "==" 1.0.2 | ||
assert_false "eq fail" vercmp 2.0-rc1 "==" 2.0-rc2 | ||
|
||
report_results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters