Imply --exists when --atleast/exact/max-version passed

The --atleast/exact/max-version help description implied that it would
return as --exists does. However, this would only occur if no other
output options were set.

Freedesktop #54389 (https://bugs.freedesktop.org/show_bug.cgi?id=54389)
This commit is contained in:
Dan Nicholson 2012-12-11 11:01:59 -08:00
parent ec11c93ef8
commit 548ba5b223
3 changed files with 49 additions and 21 deletions

View file

@ -52,3 +52,9 @@ RESULT="public-dep >= 1
private-dep >= 1"
run_test --print-requires --print-requires-private requires-test
run_test --print-requires-private --print-requires requires-test
# --exists and --atleast/exact/max-version can be mixed
RESULT=""
run_test --exists --atleast-version=1.0.0 simple
run_test --exists --exact-version=1.0.0 simple
run_test --exists --max-version=1.0.0 simple

View file

@ -19,74 +19,74 @@ v3=1.0.1
# exact version testing
EXPECT_RETURN=1
RESULT="Requested 'simple = $v1' but version of Simple test is $v2"
run_test --exists --print-errors simple = $v1
run_test --print-errors simple = $v1
EXPECT_RETURN=1
RESULT="Requested 'simple = $v1' but version of Simple test is $v2"
run_test --exists --print-errors --exact-version=$v1 simple
run_test --print-errors --exact-version=$v1 simple
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors simple = $v2
run_test --print-errors simple = $v2
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors --exact-version=$v2 simple
run_test --print-errors --exact-version=$v2 simple
EXPECT_RETURN=1
RESULT="Requested 'simple = $v3' but version of Simple test is $v2"
run_test --exists --print-errors simple = $v3
run_test --print-errors simple = $v3
EXPECT_RETURN=1
RESULT="Requested 'simple = $v3' but version of Simple test is $v2"
run_test --exists --print-errors --exact-version=$v3 simple
run_test --print-errors --exact-version=$v3 simple
# atleast version testing
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors simple \>= $v1
run_test --print-errors simple \>= $v1
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors --atleast-version=$v1 simple
run_test --print-errors --atleast-version=$v1 simple
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors simple \>= $v2
run_test --print-errors simple \>= $v2
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors --atleast-version=$v2 simple
run_test --print-errors --atleast-version=$v2 simple
EXPECT_RETURN=1
RESULT="Requested 'simple >= $v3' but version of Simple test is $v2"
run_test --exists --print-errors simple \>= $v3
run_test --print-errors simple \>= $v3
EXPECT_RETURN=1
RESULT="Requested 'simple >= $v3' but version of Simple test is $v2"
run_test --exists --print-errors --atleast-version=$v3 simple
run_test --print-errors --atleast-version=$v3 simple
# max version testing
EXPECT_RETURN=1
RESULT="Requested 'simple <= $v1' but version of Simple test is $v2"
run_test --exists --print-errors simple \<= $v1
run_test --print-errors simple \<= $v1
EXPECT_RETURN=1
RESULT="Requested 'simple <= $v1' but version of Simple test is $v2"
run_test --exists --print-errors --max-version=$v1 simple
run_test --print-errors --max-version=$v1 simple
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors simple \<= $v2
run_test --print-errors simple \<= $v2
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors --max-version=$v2 simple
run_test --print-errors --max-version=$v2 simple
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors simple \<= $v3
run_test --print-errors simple \<= $v3
EXPECT_RETURN=0
RESULT=""
run_test --exists --print-errors --max-version=$v3 simple
run_test --print-errors --max-version=$v3 simple

28
main.c
View file

@ -177,6 +177,13 @@ output_opt_cb (const char *opt, const char *arg, gpointer data,
(want_requires_private && strcmp (opt, "--print-requires") == 0))
bad_opt = FALSE;
/* --exists allowed with --atleast/exact/max-version */
if (want_exists &&
(strcmp (opt, "--atleast-version") == 0 ||
strcmp (opt, "--exact-version") == 0 ||
strcmp (opt, "--max-version") == 0))
bad_opt = FALSE;
if (bad_opt)
{
fprintf (stderr, "Ignoring incompatible output option \"%s\"\n",
@ -211,6 +218,21 @@ output_opt_cb (const char *opt, const char *arg, gpointer data,
want_variable_list = TRUE;
else if (strcmp (opt, "--uninstalled") == 0)
want_uninstalled = TRUE;
else if (strcmp (opt, "--atleast-version") == 0)
{
required_atleast_version = g_strdup (arg);
want_exists = TRUE;
}
else if (strcmp (opt, "--exact-version") == 0)
{
required_exact_version = g_strdup (arg);
want_exists = TRUE;
}
else if (strcmp (opt, "--max-version") == 0)
{
required_max_version = g_strdup (arg);
want_exists = TRUE;
}
else if (strcmp (opt, "--list-all") == 0)
want_list = TRUE;
else if (strcmp (opt, "--print-provides") == 0)
@ -406,11 +428,11 @@ static const GOptionEntry options_table[] = {
{ "uninstalled", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
&output_opt_cb, "return 0 if the uninstalled version of one or more "
"module(s) or their dependencies will be used", NULL },
{ "atleast-version", 0, 0, G_OPTION_ARG_STRING, &required_atleast_version,
{ "atleast-version", 0, 0, G_OPTION_ARG_CALLBACK, &output_opt_cb,
"return 0 if the module is at least version VERSION", "VERSION" },
{ "exact-version", 0, 0, G_OPTION_ARG_STRING, &required_exact_version,
{ "exact-version", 0, 0, G_OPTION_ARG_CALLBACK, &output_opt_cb,
"return 0 if the module is at exactly version VERSION", "VERSION" },
{ "max-version", 0, 0, G_OPTION_ARG_STRING, &required_max_version,
{ "max-version", 0, 0, G_OPTION_ARG_CALLBACK, &output_opt_cb,
"return 0 if the module is at no newer than version VERSION", "VERSION" },
{ "list-all", 0, G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
&output_opt_cb, "list all known packages", NULL },