diff options
author | Dan Nicholson <dbn.lists@gmail.com> | 2012-04-21 11:08:12 -0700 |
---|---|---|
committer | Dan Nicholson <dbn.lists@gmail.com> | 2012-05-10 05:51:35 -0700 |
commit | a83a14c2911d1969d5a79029ac1624bdf317373c (patch) | |
tree | 55ff006b5cd9a5aa087a4adabb19d47e5dfcd987 | |
parent | 5fc77a96b7a1114e296f968037342f060d4bc34b (diff) |
Unify handling of operator and command line option version checking
The code for --exact/atleast/max-version was taking a different path
than the handling of operators like =/>=/<=. Make the long option
versions override the operators and take place during the standard
package checking stage. This also means that --print-errors is
respected.
Fixes Freedesktop #8653
-rw-r--r-- | check/Makefile.am | 2 | ||||
-rwxr-xr-x | check/check-version | 107 | ||||
-rw-r--r-- | main.c | 48 |
3 files changed, 128 insertions, 29 deletions
diff --git a/check/Makefile.am b/check/Makefile.am index 29ec729..0ce476a 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -2,7 +2,7 @@ TESTS = check-cflags check-libs check-define-variable \ check-libs-private check-requires-private check-includedir \ check-conflicts check-missing check-idirafter check-whitespace \ - check-cmd-options + check-cmd-options check-version EXTRA_DIST = $(TESTS) common simple.pc requires-test.pc public-dep.pc \ private-dep.pc includedir.pc missing-requires-private.pc \ diff --git a/check/check-version b/check/check-version new file mode 100755 index 0000000..6e92077 --- /dev/null +++ b/check/check-version @@ -0,0 +1,107 @@ +#! /bin/sh + +# Make sure we're POSIX +if [ "$PKG_CONFIG_SHELL_IS_POSIX" != "1" ]; then + PKG_CONFIG_SHELL_IS_POSIX=1 PATH=`getconf PATH` exec sh $0 "$@" +fi + +set -e + +. ${srcdir}/common + +v1=0.9.9 +v2=1.0.0 +v3=1.0.1 + +# exact version testing +ARGS="--exists --print-errors simple = $v1" +EXPECT_RETURN=1 +RESULT="Requested 'simple = $v1' but version of Simple test is $v2" +run_test + +ARGS="--exists --print-errors --exact-version=$v1 simple" +EXPECT_RETURN=1 +RESULT="Requested 'simple = $v1' but version of Simple test is $v2" +run_test + +ARGS="--exists --print-errors simple = $v2" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors --exact-version=$v2 simple" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors simple = $v3" +EXPECT_RETURN=1 +RESULT="Requested 'simple = $v3' but version of Simple test is $v2" +run_test + +ARGS="--exists --print-errors --exact-version=$v3 simple" +EXPECT_RETURN=1 +RESULT="Requested 'simple = $v3' but version of Simple test is $v2" +run_test + +# atleast version testing +ARGS="--exists --print-errors simple >= $v1" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors --atleast-version=$v1 simple" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors simple >= $v2" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors --atleast-version=$v2 simple" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors simple >= $v3" +EXPECT_RETURN=1 +RESULT="Requested 'simple >= $v3' but version of Simple test is $v2" +run_test + +ARGS="--exists --print-errors --atleast-version=$v3 simple" +EXPECT_RETURN=1 +RESULT="Requested 'simple >= $v3' but version of Simple test is $v2" +run_test + +# max version testing +ARGS="--exists --print-errors simple <= $v1" +EXPECT_RETURN=1 +RESULT="Requested 'simple <= $v1' but version of Simple test is $v2" +run_test + +ARGS="--exists --print-errors --max-version=$v1 simple" +EXPECT_RETURN=1 +RESULT="Requested 'simple <= $v1' but version of Simple test is $v2" +run_test + +ARGS="--exists --print-errors simple <= $v2" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors --max-version=$v2 simple" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors simple <= $v3" +EXPECT_RETURN=0 +RESULT="" +run_test + +ARGS="--exists --print-errors --max-version=$v3 simple" +EXPECT_RETURN=0 +RESULT="" +run_test @@ -469,6 +469,26 @@ main (int argc, char **argv) Package *req; RequiredVersion *ver = iter->data; + /* override requested versions with cmdline options */ + if (required_exact_version) + { + g_free (ver->version); + ver->comparison = EQUAL; + ver->version = g_strdup (required_exact_version); + } + else if (required_atleast_version) + { + g_free (ver->version); + ver->comparison = GREATER_THAN_EQUAL; + ver->version = g_strdup (required_atleast_version); + } + else if (required_max_version) + { + g_free (ver->version); + ver->comparison = LESS_THAN_EQUAL; + ver->version = g_strdup (required_max_version); + } + if (want_short_errors) req = get_package_quiet (ver->name); else @@ -656,34 +676,6 @@ main (int argc, char **argv) } } - if (required_exact_version) - { - Package *pkg = packages->data; - - if (compare_versions (pkg->version, required_exact_version) == 0) - return 0; - else - return 1; - } - else if (required_atleast_version) - { - Package *pkg = packages->data; - - if (compare_versions (pkg->version, required_atleast_version) >= 0) - return 0; - else - return 1; - } - else if (required_max_version) - { - Package *pkg = packages->data; - - if (compare_versions (pkg->version, required_max_version) <= 0) - return 0; - else - return 1; - } - /* Print all flags; then print a newline at the end. */ need_newline = FALSE; |