summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Pentchev <roam@ringlet.net>2018-11-27 10:53:44 +0200
committerPeter Pentchev <roam@ringlet.net>2018-11-27 10:53:44 +0200
commit313ced740550619a706aff18a1ada05a3a14f9dc (patch)
tree1ee7111aeae47a8a0138712dd91c61cb3c814eb3
parentdae624c8eadfd6ef22523754c4a9ea21326bddd4 (diff)
Fix the check for more than one query type.
-rw-r--r--CHANGES1
-rw-r--r--confget.c3
-rw-r--r--t/14-too-many.t62
3 files changed, 65 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 97f21b0..7d64bc1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,7 @@
Change log for confget, the configuration file variable extractor
2.1.1 not yet ;)
+ - fix the check for more than one requested query type
2.1.0 2017/11/11
- allow the installation commands to be overridden, e.g. for
diff --git a/confget.c b/confget.c
index 3c07852..054c765 100644
--- a/confget.c
+++ b/confget.c
@@ -337,7 +337,8 @@ init(const int argc, char * const * const argv)
{ "BASE", "2.1" },
{ NULL, NULL },
};
- if (qsections + qfeature + qfeatures > 1) {
+ if (qsections + qfeature + qfeatures + lflag + Lflag +
+ (margc > 0 && !(Lflag || qfeature)) > 1) {
errx(1, "Only a single query at a time, please!");
} else if (qfeatures) {
if (margc > 0)
diff --git a/t/14-too-many.t b/t/14-too-many.t
new file mode 100644
index 0000000..5949fe3
--- /dev/null
+++ b/t/14-too-many.t
@@ -0,0 +1,62 @@
+#!/bin/sh
+#
+# Copyright (c) 2018 Peter Pentchev
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+[ -z "$CONFGET" ] && CONFGET='./confget'
+[ -z "$TESTDIR" ] && TESTDIR='t'
+
+T1="$TESTDIR/t1.ini"
+T2="$TESTDIR/t2.ini"
+
+echo '1..13'
+
+if [ ! -f "$T1" ]; then
+ echo "Bail out! No test file $T1"
+ exit 255
+fi
+if [ ! -f "$T2" ]; then
+ echo "Bail out! No test file $T2"
+ exit 255
+fi
+
+idx=1
+for args in \
+ '-l -L k' \
+ '-l -q sections' \
+ '-l -q features' \
+ '-l -q feature BASE' \
+ '-l key1' \
+ '-L -q sections k' \
+ '-L -q features k' \
+ '-L -q feature BASE k' \
+ '-q sections -q features' \
+ '-q sections -q feature BASE' \
+ '-q sections key1' \
+ '-q features -q feature BASE' \
+ '-q features key1'; do
+ v=`$CONFGET -f "$T2" $args 2>&1`
+ if expr "x$v" : 'x.*Only a single ' > /dev/null; then echo "ok $idx $args"; else echo "not ok $idx args $args v is $v"; fi
+ idx="$((idx + 1))"
+done