diff --git a/testframework.sh b/testframework.sh index 083f77b7..9c183ef4 100644 --- a/testframework.sh +++ b/testframework.sh @@ -840,6 +840,20 @@ tfw_quietly() { fi } +# Compare the two arguments as dotted ascii decimal version strings. +# Return 0 if they are equal, 1 if arg1 < arg2, 2 if arg1 > arg2 +tfw_cmp_version() { + local IFS=. + local i=0 a=($1) b=($2) + for (( i=0; i < ${#a[@]} || i < ${#b[@]}; ++i )); do + local ai="${a[i]:-0}" + local bi="${b[i]:-0}" + (( 10#$ai < 10#$bi )) && return 1 + (( 10#$ai > 10#$bi )) && return 2 + done + return 0 +} + # Append the contents of a file to the test case's stdout log. A normal 'cat' # to stdout would also do this, but tfw_cat echoes header and footer delimiter # lines around to content to help distinguish it, and also works even in a diff --git a/tests/framework b/tests/framework new file mode 100755 index 00000000..2343ceb2 --- /dev/null +++ b/tests/framework @@ -0,0 +1,47 @@ +#!/bin/bash + +# Tests for Serval rhizome operations. +# +# Copyright 2012 Serval Project, Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +source "${0%/*}/../testframework.sh" + +shopt -s extglob + +test_tfw_cmp_version() { + execute --exit-status=1 tfw_cmp_version 1 2 + execute --exit-status=2 tfw_cmp_version 1.0.1 1.0.0 + execute --exit-status=1 tfw_cmp_version 1.0 1.1 + execute --exit-status=0 tfw_cmp_version 1 1 + execute --exit-status=1 tfw_cmp_version 2.1 2.2 + execute --exit-status=2 tfw_cmp_version 3.0.4.10 3.0.4.2 + execute --exit-status=1 tfw_cmp_version 4.08 4.08.01 + execute --exit-status=2 tfw_cmp_version 3.2.1.9.8144 3.2 + execute --exit-status=1 tfw_cmp_version 3.2 3.2.1.9.8144 + execute --exit-status=1 tfw_cmp_version 1.2 2.1 + execute --exit-status=2 tfw_cmp_version 2.1 1.2 + execute --exit-status=0 tfw_cmp_version 5.6.7 5.6.7 + execute --exit-status=0 tfw_cmp_version 1.01.1 1.1.1 + execute --exit-status=0 tfw_cmp_version 1.1.1 1.01.1 + execute --exit-status=0 tfw_cmp_version 1 1.0 + execute --exit-status=0 tfw_cmp_version 1.0 1 + execute --exit-status=0 tfw_cmp_version 1.0.2.0 1.0.2 + execute --exit-status=0 tfw_cmp_version 1..0 1.0 + execute --exit-status=0 tfw_cmp_version 1.0 1..0 +} + +runTests "$@"