summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Pentchev <roam@ringlet.net>2019-01-02 15:03:57 +0200
committerPeter Pentchev <roam@ringlet.net>2019-01-02 20:39:29 +0200
commit997c32e396649b7b83d79a939e6731d75a4590dd (patch)
tree188f9b0d20073dda1fa317974fca37ba8dd6a0af
parent2f5e78512c7814578db992c0fe2ce060f9e95d00 (diff)
Test the Python code as a library, generate t/*.t.
Generate most of the t/*.t TAP-output shell scripts from Python data structure templates. Rename the t/*.t files that test some edge cases or that use some special shell constructs to *-bespoke-*.t. Where applicable, use the new data structures to run Python unit tests for the Python implementation as a library, not only as a command-line tool.
-rw-r--r--python/confget/backend/http_get.py12
-rw-r--r--python/confget/defs.py8
-rw-r--r--python/confget/format.py51
-rw-r--r--python/stubs/urllib/__init__.py0
-rw-r--r--python/stubs/urllib/__init__.pyi3
-rw-r--r--python/stubs/urllib/parse.pyi3
-rw-r--r--python/stubs/urllib/py.typed0
-rw-r--r--python/tox.ini73
-rw-r--r--python/unit_tests/__init__.py0
-rw-r--r--python/unit_tests/data/__init__.py7
-rw-r--r--python/unit_tests/data/data.py961
-rw-r--r--python/unit_tests/data/defs.py269
-rw-r--r--python/unit_tests/data/util.py21
-rw-r--r--python/unit_tests/test_run.py110
-rw-r--r--t/01-get-values.t86
-rw-r--r--t/02-check-values.t76
-rw-r--r--t/03-list-all.t51
-rw-r--r--t/04-bespoke-test-manpage.t (renamed from t/04-test-manpage.t)0
-rw-r--r--t/05-match-names.t30
-rw-r--r--t/06-get-default.t35
-rw-r--r--t/07-match-values.t43
-rw-r--r--t/08-bespoke-shell-quote.t (renamed from t/08-shell-quote.t)0
-rw-r--r--t/09-bespoke-regexp.t (renamed from t/09-regexp.t)0
-rw-r--r--t/10-bespoke-qsections.t (renamed from t/10-qsections.t)0
-rw-r--r--t/11-no-default.t53
-rw-r--r--t/12-last-value.t59
-rw-r--r--t/13-bespoke-features.t (renamed from t/13-features.t)0
-rw-r--r--t/14-bespoke-too-many.t (renamed from t/14-too-many.t)0
-rwxr-xr-xt/generate.py145
29 files changed, 1885 insertions, 211 deletions
diff --git a/python/confget/backend/http_get.py b/python/confget/backend/http_get.py
index de32c66..c9ca711 100644
--- a/python/confget/backend/http_get.py
+++ b/python/confget/backend/http_get.py
@@ -13,6 +13,14 @@ from .. import defs
from . import abstract
+try:
+ import urllib.parse # pylint: disable=ungrouped-imports
+
+ urllib_unquote = urllib.parse.unquote # pylint: disable=invalid-name
+except ImportError:
+ urllib_unquote = urllib.unquote # pylint: disable=invalid-name,no-member
+
+
_TYPING_USED = (defs, Dict, List)
RE_ENTITY = re.compile(r'^ (?P<full> [a-zA-Z0-9_]+ ; )', re.X)
@@ -39,8 +47,6 @@ class HTTPGetBackend(abstract.Backend):
def read_file(self):
# type: (HTTPGetBackend) -> defs.ConfigData
- unquote = getattr(urllib, 'parse', urllib).unquote
-
def split_by_amp(line):
# type: (str) -> List[str]
""" Split a line by "&" or "&amp;" tokens. """
@@ -72,6 +78,6 @@ class HTTPGetBackend(abstract.Backend):
elif len(fields) != 2:
raise ValueError('Invalid query string component: "{varval}"'
.format(varval=varval))
- data[unquote(fields[0])] = unquote(fields[1])
+ data[urllib_unquote(fields[0])] = urllib_unquote(fields[1])
return {self._cfg.section: data}
diff --git a/python/confget/defs.py b/python/confget/defs.py
index d098e25..da4b034 100644
--- a/python/confget/defs.py
+++ b/python/confget/defs.py
@@ -14,8 +14,12 @@ class Config(object):
# pylint: disable=too-few-public-methods
""" Base class for the internal confget configuration. """
- def __init__(self, filename, section, section_specified, varnames):
- # type: (Config, Optional[str], str, bool, List[str]) -> None
+ def __init__(self, # type: Config
+ varnames, # type: List[str]
+ filename=None, # type: Optional[str]
+ section='', # type: str
+ section_specified=False, # type: bool
+ ): # type: (...) -> None
""" Store the specified configuration values. """
self.filename = filename
self.section = section
diff --git a/python/confget/format.py b/python/confget/format.py
index fc2a012..55d3a0a 100644
--- a/python/confget/format.py
+++ b/python/confget/format.py
@@ -42,20 +42,20 @@ class FormatConfig(defs.Config):
the Bourne shell
"""
- def __init__(self, # type: FormatConfig
- filename, # type: Optional[str]
- list_all, # type: bool
- match_regex, # type: bool
- match_var_names, # type: bool
- match_var_values, # type: Optional[str]
- name_prefix, # type: Optional[str]
- section, # type: str
- section_override, # type: bool
- section_specified, # type: bool
- show_var_name, # type: bool
- shell_escape, # type: bool
- varnames # type: List[str]
- ): # type: (...) -> None
+ def __init__(self, # type: FormatConfig
+ varnames, # type: List[str]
+ filename=None, # type: Optional[str]
+ list_all=False, # type: bool
+ match_regex=False, # type: bool
+ match_var_names=False, # type: bool
+ match_var_values=None, # type: Optional[str]
+ name_prefix=None, # type: Optional[str]
+ section='', # type: str
+ section_override=False, # type: bool
+ section_specified=False, # type: bool
+ show_var_name=False, # type: bool
+ shell_escape=False, # type: bool
+ ): # type: (...) -> None
# pylint: disable=too-many-arguments
""" Store the specified configuration values. """
super(FormatConfig, self).__init__(
@@ -73,6 +73,29 @@ class FormatConfig(defs.Config):
self.shell_escape = shell_escape
self.show_var_name = show_var_name
+ def __repr__(self):
+ # type: (FormatConfig) -> str
+ return '{tname}({varnames}, {attrs})'.format(
+ tname=type(self).__name__,
+ varnames=repr(self.varnames),
+ attrs=', '.join([
+ '{name}={value}'.format(
+ name=name, value=repr(getattr(self, name)))
+ for name in [
+ 'filename',
+ 'list_all',
+ 'match_regex',
+ 'match_var_names',
+ 'match_var_values',
+ 'name_prefix',
+ 'section',
+ 'section_override',
+ 'section_specified',
+ 'show_var_name',
+ 'shell_escape',
+ ]
+ ]))
+
def get_check_function(cfg, patterns):
# type: (FormatConfig, List[str]) -> Callable[[str], bool]
diff --git a/python/stubs/urllib/__init__.py b/python/stubs/urllib/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python/stubs/urllib/__init__.py
diff --git a/python/stubs/urllib/__init__.pyi b/python/stubs/urllib/__init__.pyi
new file mode 100644
index 0000000..53948c5
--- /dev/null
+++ b/python/stubs/urllib/__init__.pyi
@@ -0,0 +1,3 @@
+def unquote(name):
+ # type: (str) -> str
+ ...
diff --git a/python/stubs/urllib/parse.pyi b/python/stubs/urllib/parse.pyi
new file mode 100644
index 0000000..53948c5
--- /dev/null
+++ b/python/stubs/urllib/parse.pyi
@@ -0,0 +1,3 @@
+def unquote(name):
+ # type: (str) -> str
+ ...
diff --git a/python/stubs/urllib/py.typed b/python/stubs/urllib/py.typed
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python/stubs/urllib/py.typed
diff --git a/python/tox.ini b/python/tox.ini
index a33bf53..aec8bff 100644
--- a/python/tox.ini
+++ b/python/tox.ini
@@ -1,5 +1,5 @@
[tox]
-envlist = pep8,mypy2,mypy3,pylint
+envlist = pep8,mypy2,mypy3,prove_2,prove_3,unit_tests_2,unit_tests_3,pylint
skipsdist = True
[testenv:pep8]
@@ -7,25 +7,90 @@ basepython = python3
deps =
flake8
commands =
- flake8 confget
+ flake8 confget unit_tests ../t/generate.py
[testenv:mypy2]
basepython = python3
deps =
mypy
+setenv =
+ MYPYPATH={toxinidir}/stubs
commands =
mypy --strict --py2 confget
+ mypy --strict --py2 --allow-untyped-decorators unit_tests
[testenv:mypy3]
basepython = python3
deps =
mypy
+setenv =
+ MYPYPATH={toxinidir}/stubs
commands =
- mypy --strict confget
+ mypy --strict confget ../t/generate.py
+ mypy --strict --allow-untyped-decorators unit_tests
[testenv:pylint]
basepython = python3
deps =
+ ddt
pylint
+ pytest
commands =
- pylint --disable=useless-object-inheritance,duplicate-code confget
+ pylint --disable=useless-object-inheritance,duplicate-code confget unit_tests ../t/generate.py
+
+[testenv:unit_tests_2]
+basepython = python2
+deps =
+ ddt
+ pytest
+ typing
+setenv =
+ TESTDIR={toxinidir}/../t
+commands =
+ pytest -s -vv unit_tests
+
+[testenv:unit_tests_3]
+basepython = python3
+deps =
+ ddt
+ pytest
+setenv =
+ TESTDIR={toxinidir}/../t
+commands =
+ pytest -s -vv unit_tests
+
+[testenv:generate]
+basepython = python3
+deps =
+ six
+whitelist_externals =
+ sh
+commands =
+ sh -c 'cd ../t && env PYTHONPATH={toxinidir} python generate.py'
+
+[testenv:prove_2]
+basepython = python2
+deps =
+ six
+ typing
+setenv =
+ CONFGET=python -m confget
+ MANPAGE={toxinidir}/../confget.1
+ TESTDIR={toxinidir}/../t
+whitelist_externals =
+ prove
+commands =
+ prove ../t
+
+[testenv:prove_3]
+basepython = python3
+deps =
+ six
+setenv =
+ CONFGET=python -m confget
+ MANPAGE={toxinidir}/../confget.1
+ TESTDIR={toxinidir}/../t
+whitelist_externals =
+ prove
+commands =
+ prove ../t
diff --git a/python/unit_tests/__init__.py b/python/unit_tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/python/unit_tests/__init__.py
diff --git a/python/unit_tests/data/__init__.py b/python/unit_tests/data/__init__.py
new file mode 100644
index 0000000..6bdc1ee
--- /dev/null
+++ b/python/unit_tests/data/__init__.py
@@ -0,0 +1,7 @@
+"""
+Data structures and definitions for the confget unit tests.
+"""
+
+from .defs import CMDLINE_OPTIONS, XFORM, TestDef # noqa: F401
+from .data import TESTS # noqa: F401
+from .util import shell_escape # noqa: F401
diff --git a/python/unit_tests/data/data.py b/python/unit_tests/data/data.py
new file mode 100644
index 0000000..0fede7c
--- /dev/null
+++ b/python/unit_tests/data/data.py
@@ -0,0 +1,961 @@
+"""
+Test data for the confget unit tests.
+"""
+
+from . import defs
+
+
+TESTS = {
+ '01-get-values': defs.TestFileDef(
+ setenv={
+ 'QUERY_STRING':
+ 'key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3',
+ 'Q1': 'key4&amp;key5=%09%09%20val%27ue5&key6',
+ 'Q2': '',
+ },
+ tests=[
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ },
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='value1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'show_var_name': '',
+ },
+ keys=['key2'],
+ output=defs.TestExactOutputDef(
+ exact='key2=value2',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ },
+ keys=['key3'],
+ output=defs.TestExactOutputDef(
+ exact="\t\t val'ue3",
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ },
+ keys=['key4'],
+ output=defs.TestExactOutputDef(
+ exact="v'alu'e4",
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'c',
+ },
+ keys=['key5'],
+ output=defs.TestExactOutputDef(
+ exact='\t\t# value5',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ },
+ keys=['key1', 'key2'],
+ xform='newline-to-space',
+ output=defs.TestExactOutputDef(
+ exact='key1=value1 key2=value2 ',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'hide_var_name': '',
+ },
+ keys=['key6', 'key2'],
+ xform='newline-to-space',
+ output=defs.TestExactOutputDef(
+ exact='value2 value6 ',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ },
+ keys=['key7'],
+ output=defs.TestExactOutputDef(
+ exact='value7',
+ ),
+ ),
+
+ defs.TestDef(
+ args={
+ 'section': 'b sect',
+ },
+ keys=['key7'],
+ output=defs.TestExactOutputDef(
+ exact='value7',
+ ),
+ stdin='t1.ini',
+ ),
+ defs.TestDef(
+ args={
+ 'section': 'b sect',
+ },
+ keys=['key77'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ stdin='t1.ini',
+ ),
+
+ defs.TestDef(
+ args={},
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='value1',
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'show_var_name': '',
+ },
+ keys=['key2'],
+ output=defs.TestExactOutputDef(
+ exact='key2==value2&',
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={},
+ keys=['key3'],
+ output=defs.TestExactOutputDef(
+ exact="\t\t val'ue3",
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'section': 'Q1',
+ },
+ keys=['key4'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'section': 'Q1',
+ },
+ keys=['key5'],
+ output=defs.TestExactOutputDef(
+ exact="\t\t val'ue5",
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'section': 'Q1',
+ },
+ keys=['key6'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'section': 'Q1',
+ },
+ keys=['key66'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'section': 'Q2',
+ },
+ keys=['key66'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ ],
+ ),
+
+ '02-check-values': defs.TestFileDef(
+ setenv={
+ 'QUERY_STRING':
+ 'key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3',
+ 'Q1': 'key4&amp;key5=%09%09%20val%27ue5&key6',
+ 'Q2': '',
+ },
+ tests=[
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'filename': 't1.ini',
+ 'section': 'a',
+ },
+ keys=['key1'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'filename': 't1.ini',
+ 'section': 'a',
+ },
+ keys=['key2'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'filename': 't1.ini',
+ 'section': 'a',
+ },
+ keys=['key3'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'filename': 't1.ini',
+ 'section': 'a',
+ },
+ keys=['key4'],
+ output=defs.TestExitOKOutputDef(
+ success=False,
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ },
+ keys=['key5'],
+ output=defs.TestExitOKOutputDef(
+ success=False,
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ },
+ keys=['key4'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'filename': 't1.ini',
+ 'section': 'c',
+ },
+ keys=['key5'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ ),
+
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ },
+ keys=['key1'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ },
+ keys=['key2'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ },
+ keys=['key3'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'section': 'Q1',
+ },
+ keys=['key4'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'section': 'Q1',
+ },
+ keys=['key6'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ },
+ keys=['key6'],
+ output=defs.TestExitOKOutputDef(
+ success=False,
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'section': 'Q1',
+ },
+ keys=['key1'],
+ output=defs.TestExitOKOutputDef(
+ success=False,
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ defs.TestDef(
+ args={
+ 'check_only': '',
+ 'section': 'Q2',
+ },
+ keys=['key1'],
+ output=defs.TestExitOKOutputDef(
+ success=False,
+ ),
+ backend='http_get',
+ setenv=True,
+ ),
+ ],
+ ),
+
+ '03-list-all': defs.TestFileDef(
+ setenv={
+ 'QUERY_STRING':
+ 'key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3',
+ 'Q1': 'key4&amp;key5=%09%09%20val%27ue5&key6',
+ 'Q2': '',
+ },
+ tests=[
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'list_all': '',
+ },
+ keys=[],
+ xform='count-lines',
+ output=defs.TestExactOutputDef(
+ exact='4',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ 'list_all': '',
+ 'show_var_name': '',
+ },
+ keys=[],
+ xform='count-lines-eq',
+ output=defs.TestExactOutputDef(
+ exact='2',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'c',
+ 'list_all': '',
+ 'hide_var_name': '',
+ },
+ keys=[],
+ xform='count-lines-non-eq',
+ output=defs.TestExactOutputDef(
+ exact='1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'd',
+ 'list_all': '',
+ },
+ keys=[],
+ xform='count-lines',
+ output=defs.TestExactOutputDef(
+ exact='0',
+ ),
+ ),
+
+ defs.TestDef(
+ args={
+ 'list_all': '',
+ },
+ keys=[],
+ backend='http_get',
+ setenv=True,
+ xform='count-lines',
+ output=defs.TestExactOutputDef(
+ exact='3',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'list_all': '',
+ 'section': 'Q1',
+ },
+ keys=[],
+ backend='http_get',
+ setenv=True,
+ xform='count-lines',
+ output=defs.TestExactOutputDef(
+ exact='3',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'list_all': '',
+ 'section': 'Q2',
+ },
+ keys=[],
+ backend='http_get',
+ setenv=True,
+ xform='count-lines',
+ output=defs.TestExactOutputDef(
+ exact='0',
+ ),
+ ),
+ ],
+ ),
+
+ '05-match-names': defs.TestFileDef(
+ tests=[
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'match_var_names': '',
+ },
+ keys=['*'],
+ xform='count-lines',
+ output=defs.TestExactOutputDef(
+ exact='4',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ 'match_var_names': '',
+ 'show_var_name': '',
+ },
+ keys=['*'],
+ xform='count-lines-eq',
+ output=defs.TestExactOutputDef(
+ exact='2',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'match_var_names': '',
+ 'hide_var_name': '',
+ },
+ keys=['*ey2'],
+ xform='count-lines-non-eq',
+ output=defs.TestExactOutputDef(
+ exact='1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'd',
+ 'match_var_names': '',
+ },
+ keys=['*ey2'],
+ xform='count-lines',
+ output=defs.TestExactOutputDef(
+ exact='0',
+ ),
+ ),
+ ],
+ ),
+
+ '06-get-default': defs.TestFileDef(
+ tests=[
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ },
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='value1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ },
+ keys=['key4'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ },
+ keys=['key6'],
+ output=defs.TestExactOutputDef(
+ exact='value6',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't2.ini',
+ },
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't2.ini',
+ },
+ keys=['key1', 'key2'],
+ xform='newline-to-space',
+ output=defs.TestExactOutputDef(
+ exact='key1=1 key2=2 ',
+ ),
+ ),
+ ],
+ ),
+
+ '07-match-values': defs.TestFileDef(
+ tests=[
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'match_var_values': 'value*',
+ },
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='value1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'match_var_values': '*ue2',
+ },
+ keys=['key2'],
+ output=defs.TestExactOutputDef(
+ exact='value2',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'match_var_values': "*val'ue*",
+ },
+ keys=['key3'],
+ output=defs.TestExactOutputDef(
+ exact=" val'ue3",
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ 'match_var_values': '*alu*',
+ },
+ keys=['key4'],
+ output=defs.TestExactOutputDef(
+ exact="v'alu'e4",
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'c',
+ },
+ keys=['key5'],
+ output=defs.TestExactOutputDef(
+ exact=' # value5',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'match_var_values': '*alu*',
+ },
+ keys=['key1', 'key2'],
+ xform='newline-to-space',
+ output=defs.TestExactOutputDef(
+ exact='key1=value1 key2=value2 ',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'a',
+ 'match_var_values': '*7',
+ },
+ keys=['key6'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ 'check_only': '',
+ 'match_var_values': '*7',
+ },
+ keys=['key7'],
+ output=defs.TestExitOKOutputDef(
+ success=True,
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': 'b sect',
+ 'check_only': '',
+ 'match_var_values': '*7',
+ },
+ keys=['key6'],
+ output=defs.TestExitOKOutputDef(
+ success=False,
+ ),
+ ),
+ ],
+ ),
+
+ '11-no-default': defs.TestFileDef(
+ tests=[
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ },
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='value1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ },
+ keys=['key4'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ },
+ keys=['key6'],
+ output=defs.TestExactOutputDef(
+ exact='value6',
+ ),
+ ),
+
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': '',
+ 'section_specified': '',
+ },
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': '',
+ 'section_specified': '',
+ },
+ keys=['key4'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't1.ini',
+ 'section': '',
+ 'section_specified': '',
+ },
+ keys=['key6'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+
+ defs.TestDef(
+ args={
+ 'filename': 't2.ini',
+ },
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't2.ini',
+ },
+ keys=['key1', 'key2'],
+ xform='newline-to-space',
+ output=defs.TestExactOutputDef(
+ exact='key1=1 key2=2 ',
+ ),
+ ),
+
+ defs.TestDef(
+ args={
+ 'filename': 't2.ini',
+ 'section': '',
+ 'section_specified': '',
+ },
+ keys=['key1'],
+ output=defs.TestExactOutputDef(
+ exact='1',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't2.ini',
+ 'section': '',
+ 'section_specified': '',
+ },
+ keys=['key1', 'key2'],
+ xform='newline-to-space',
+ output=defs.TestExactOutputDef(
+ exact='key1=1 key2=2 ',
+ ),
+ ),
+ ],
+ ),
+
+ '12-last-value': defs.TestFileDef(
+ tests=[
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ },
+ keys=['both'],
+ output=defs.TestExactOutputDef(
+ exact='default',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ },
+ keys=['defonly'],
+ output=defs.TestExactOutputDef(
+ exact='default',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ },
+ keys=['aonly'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': '',
+ },
+ keys=['both'],
+ output=defs.TestExactOutputDef(
+ exact='default',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': '',
+ },
+ keys=['defonly'],
+ output=defs.TestExactOutputDef(
+ exact='default',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': '',
+ },
+ keys=['aonly'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': 'a',
+ },
+ keys=['both'],
+ output=defs.TestExactOutputDef(
+ exact='a',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': 'a',
+ },
+ keys=['defonly'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': 'a',
+ },
+ keys=['aonly'],
+ output=defs.TestExactOutputDef(
+ exact='a',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': 'a',
+ 'section_override': '',
+ },
+ keys=['both'],
+ output=defs.TestExactOutputDef(
+ exact='a',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': 'a',
+ 'section_override': '',
+ },
+ keys=['defonly'],
+ output=defs.TestExactOutputDef(
+ exact='default',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'section': 'a',
+ 'section_override': '',
+ },
+ keys=['aonly'],
+ output=defs.TestExactOutputDef(
+ exact='a',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'match_var_values': 'def*',
+ 'section': 'a',
+ 'section_override': '',
+ },
+ keys=['both'],
+ output=defs.TestExactOutputDef(
+ exact='',
+ ),
+ ),
+ defs.TestDef(
+ args={
+ 'filename': 't3.ini',
+ 'match_var_values': 'a*',
+ 'section': 'a',
+ 'section_override': '',
+ },
+ keys=['both'],
+ output=defs.TestExactOutputDef(
+ exact='a',
+ ),
+ ),
+ ],
+ ),
+}
diff --git a/python/unit_tests/data/defs.py b/python/unit_tests/data/defs.py
new file mode 100644
index 0000000..f4f67b7
--- /dev/null
+++ b/python/unit_tests/data/defs.py
@@ -0,0 +1,269 @@
+"""
+Class definitions for the confget test suite.
+"""
+
+import abc
+import os
+
+import six
+
+from confget import backend as cbackend
+from confget import format as cformat
+
+from . import util
+
+
+try:
+ from typing import Any, Dict, Iterable, List, Optional, Type
+
+ _TYPING_USED = (Any, Dict, Iterable, List, Optional, Type)
+except ImportError:
+ pass
+
+
+CMDLINE_OPTIONS = {
+ 'check_only': ('-c', False),
+ 'filename': ('-f', True),
+ 'hide_var_name': ('-n', False),
+ 'list_all': ('-l', False),
+ 'match_var_names': ('-L', False),
+ 'match_var_values': ('-m', True),
+ 'section': ('-s', True),
+ 'section_override': ('-O', False),
+ 'section_specified': ('', False),
+ 'show_var_name': ('-N', False),
+}
+
+
+@six.add_metaclass(abc.ABCMeta)
+class XFormType(object):
+ """ Transform something to something else with great prejudice. """
+
+ @abc.abstractproperty
+ def command(self):
+ # type: (XFormType) -> str
+ """ Get the shell command to transform the confget output. """
+ raise NotImplementedError(
+ '{tname}.command'.format(tname=type(self).__name__))
+
+ @abc.abstractmethod
+ def do_xform(self, res):
+ # type: (XFormType, Iterable[cformat.FormatOutput]) -> str
+ """ Transform the Python representation of the result. """
+ raise NotImplementedError(
+ '{tname}.do_xform()'.format(tname=type(self).__name__))
+
+
+class XFormNone(XFormType):
+ """ No transformation, newlines preserved. """
+
+ @property
+ def command(self):
+ # type: (XFormNone) -> str
+ return ''
+
+ def do_xform(self, res):
+ # type: (XFormNone, Iterable[cformat.FormatOutput]) -> str
+ return '\n'.join([line.output_full for line in res])
+
+
+class XFormNewlineToSpace(XFormType):
+ """ Translate newlines to spaces. """
+
+ @property
+ def command(self):
+ # type: (XFormNewlineToSpace) -> str
+ return '| tr "\\n" " "'
+
+ def do_xform(self, res):
+ # type: (XFormNewlineToSpace, Iterable[cformat.FormatOutput]) -> str
+ return ''.join([line.output_full + ' ' for line in res])
+
+
+class XFormCountLines(XFormType):
+ """ Count the lines output by confget. """
+
+ def __init__(self, sought=None, sought_in=True):
+ # type: (XFormCountLines, Optional[str], bool) -> None
+ super(XFormCountLines, self).__init__()
+ self.sought = sought
+ self.sought_in = sought_in
+
+ @property
+ def command(self):
+ # type: (XFormCountLines) -> str
+ if self.sought:
+ prefix = '| fgrep -{inv}e {sought} '.format(
+ inv='' if self.sought_in else 'v',
+ sought=util.shell_escape(self.sought))
+ else:
+ prefix = ''
+ return prefix + "| wc -l | tr -d ' '"
+
+ def do_xform(self, res):
+ # type: (XFormCountLines, Iterable[cformat.FormatOutput]) -> str
+ if self.sought:
+ return str(len(
+ [line for line in res
+ if self.sought_in == (self.sought in line.output_full)]))
+ return str(len([line for line in res]))
+
+
+XFORM = {
+ '': XFormNone(),
+ 'count-lines': XFormCountLines(),
+ 'count-lines-eq': XFormCountLines(sought='='),
+ 'count-lines-non-eq': XFormCountLines(sought='=', sought_in=False),
+ 'newline-to-space': XFormNewlineToSpace(),
+}
+
+
+@six.add_metaclass(abc.ABCMeta)
+class TestOutputDef(object):
+ """ A definition for a single test's output. """
+
+ def __init(self):
+ # type: (TestOutputDef) -> None
+ """ No initialization at all for the base class. """
+
+ @abc.abstractmethod
+ def get_check(self):
+ # type: (TestOutputDef) -> str
+ """ Get the check string as a shell command. """
+ raise NotImplementedError(
+ '{name}.get_check()'.format(name=type(self).__name__))
+
+ @abc.abstractproperty
+ def var_name(self):
+ # type: (TestOutputDef) -> str
+ """ Get the variable name to display. """
+ raise NotImplementedError(
+ '{name}.var_name'.format(name=type(self).__name__))
+
+ @abc.abstractmethod
+ def check_result(self, _res):
+ # type: (TestOutputDef, str) -> None
+ """ Check whether the processed confget result is correct. """
+ raise NotImplementedError(
+ '{name}.check_result()'.format(name=type(self).__name__))
+
+
+class TestExactOutputDef(TestOutputDef):
+ """ Check that the program output this exact string. """
+
+ def __init__(self, exact):
+ # type: (TestExactOutputDef, str) -> None
+ """ Initialize an exact test output object. """
+ self.exact = exact
+
+ def get_check(self):
+ # type: (TestExactOutputDef) -> str
+ return '[ "$v" = ' + util.shell_escape(self.exact) + ' ]'
+
+ @property
+ def var_name(self):
+ # type: (TestExactOutputDef) -> str
+ return 'v'
+
+ def check_result(self, res):
+ # type: (TestExactOutputDef, str) -> None
+ assert res == self.exact
+
+
+class TestExitOKOutputDef(TestOutputDef):
+ """ Check that the program succeeded or failed as expected. """
+
+ def __init__(self, success):
+ # type: (TestExitOKOutputDef, bool) -> None
+ """ Initialize an "finished successfully" test output object. """
+ self.success = success
+
+ def get_check(self):
+ # type: (TestExitOKOutputDef) -> str
+ return '[ "$res" {compare} 0 ]'.format(
+ compare="=" if self.success else "!=")
+
+ @property
+ def var_name(self):
+ # type: (TestExitOKOutputDef) -> str
+ return 'res'
+
+ def check_result(self, res):
+ # type: (TestExitOKOutputDef, str) -> None
+ # pylint: disable=useless-super-delegation
+ super(TestExitOKOutputDef, self).check_result(res)
+
+
+class TestDef:
+ # pylint: disable=too-few-public-methods
+ """ A definition for a single test. """
+
+ def __init__(self, # type: TestDef
+ args, # type: Dict[str, str]
+ keys, # type: List[str]
+ output, # type: TestOutputDef
+ xform='', # type: str
+ backend='ini', # type: str
+ setenv=False, # type: bool
+ stdin=None, # type: Optional[str]
+ ): # type: (...) -> None
+ # pylint: disable=too-many-arguments
+ """ Initialize a test object. """
+
+ self.args = args
+ self.keys = keys
+ self.xform = xform
+ self.output = output
+ self.backend = backend
+ self.setenv = setenv
+ self.stdin = stdin
+
+ def get_backend(self):
+ # type: (TestDef) -> Type[cbackend.abstract.Backend]
+ """ Get the appropriate confget backend type. """
+ return cbackend.BACKENDS[self.backend]
+
+ def get_config(self):
+ # type: (TestDef) -> cformat.FormatConfig
+ """ Convert the test's data to a config object. """
+ data = {} # type: Dict[str, Any]
+ for name, value in self.args.items():
+ if name == 'hide_var_name':
+ continue
+
+ opt = CMDLINE_OPTIONS[name]
+ if opt[1]:
+ data[name] = value
+ else:
+ data[name] = True
+
+ if 'filename' in data:
+ data['filename'] = os.environ['TESTDIR'] + '/' + data['filename']
+ elif self.stdin:
+ data['filename'] = '-'
+
+ data['show_var_name'] = 'show_var_name' in self.args or \
+ (('match_var_names' in self.args or
+ 'list_all' in self.args or
+ len(self.keys) > 1) and
+ 'hide_var_name' not in self.args)
+
+ return cformat.FormatConfig(self.keys, **data)
+
+ def do_xform(self, res):
+ # type: (TestDef, Iterable[cformat.FormatOutput]) -> str
+ """ Return the output delimiter depending on the xform property. """
+ return XFORM[self.xform].do_xform(res)
+
+
+class TestFileDef:
+ # pylint: disable=too-few-public-methods
+ """ A definition for a file defining related tests. """
+
+ def __init__(self, # type: TestFileDef
+ tests, # type: List[TestDef]
+ setenv=None, # type: Optional[Dict[str, str]]
+ ): # type: (...) -> None
+ """ Initialize a test file object. """
+ self.tests = tests
+ self.setenv = {} if setenv is None else setenv
diff --git a/python/unit_tests/data/util.py b/python/unit_tests/data/util.py
new file mode 100644
index 0000000..79305c4
--- /dev/null
+++ b/python/unit_tests/data/util.py
@@ -0,0 +1,21 @@
+"""
+Utility functions for the confget test cases.
+"""
+
+import re
+
+
+_RE_APOS = re.compile("(?P<pre> [^']* ) (?P<apos> '+ ) (?P<post> .* )", re.X)
+
+
+def shell_escape(value):
+ # type: (str) -> str
+ """ Escape a value for the shell. """
+ res = "'"
+ while True:
+ match = _RE_APOS.match(value)
+ if not match:
+ return res + value + "'"
+
+ res += match.group('pre') + '\'"' + match.group('apos') + '"\''
+ value = match.group('post')
diff --git a/python/unit_tests/test_run.py b/python/unit_tests/test_run.py
new file mode 100644
index 0000000..6c10656
--- /dev/null
+++ b/python/unit_tests/test_run.py
@@ -0,0 +1,110 @@
+"""
+Run the confget tests using the Python methods.
+
+Load the test data, then run the tests using the objects provided by
+the Python library, not by executing the command-line tool.
+"""
+
+from __future__ import print_function
+
+import itertools
+import os
+import sys
+import unittest
+
+import ddt # type: ignore
+import pytest # type: ignore
+
+from confget import format as cformat
+
+pytest.register_assert_rewrite('unit_tests.data.defs')
+
+from . import data as tdata # noqa: E402 pylint: disable=wrong-import-position
+
+
+try:
+ from typing import Dict
+
+ _TYPING_USED = (Dict,)
+except ImportError:
+ pass
+
+
+FULL_TEST_DATA = sorted(itertools.chain(*[
+ [
+ (
+ tfile[0],
+ idx,
+ tfile[1].setenv,
+ test,
+ )
+ for idx, test in enumerate(tfile[1].tests)
+ ]
+ for tfile in tdata.TESTS.items()
+]))
+
+SKIP_ARGS = set(['check_only'])
+
+
+@ddt.ddt
+class TestStuff(unittest.TestCase):
+ # pylint: disable=no-self-use
+ """ Run the tests using the Python library. """
+
+ @ddt.data(
+ *FULL_TEST_DATA
+ )
+ @ddt.unpack
+ def test_run(self, # type: TestStuff
+ fname, # type: str
+ idx, # type: int
+ setenv, # type: Dict[str, str]
+ test, # type: tdata.TestDef
+ ): # type: (...) -> None
+ """ Instantiate a confget object, load the data, check it. """
+ print('')
+
+ save_env = dict(os.environ)
+ try:
+ print('fname {fname} {idx:2} setenv {count} keys {kkk}'
+ .format(fname=fname, idx=idx, count=len(setenv.keys()),
+ kkk=test.keys))
+ if set(test.args.keys()) & SKIP_ARGS:
+ print('- skipping: {skip}'.format(
+ skip=' '.join(sorted(set(test.args.keys()) & SKIP_ARGS))))
+ return
+
+ backend = test.get_backend()
+ print('- backend {back}'.format(back=backend))
+ config = test.get_config()
+ print('- config {cfg}'.format(cfg=config))
+ if test.setenv:
+ os.environ.update(setenv)
+
+ if test.stdin:
+ fname = os.environ['TESTDIR'] + '/' + test.stdin
+ print('- reopening {fname} as stdin'.format(fname=fname))
+ with open(fname, mode='r') as stdin:
+ save_stdin = sys.stdin
+ try:
+ sys.stdin = stdin
+ obj = backend(config)
+ print('- obj {obj}'.format(obj=obj))
+ data = obj.read_file()
+ finally:
+ sys.stdin = save_stdin
+ else:
+ obj = backend(config)
+ print('- obj {obj}'.format(obj=obj))
+ data = obj.read_file()
+
+ print('- sections: {sect}'.format(sect=sorted(data.keys())))
+ res = cformat.filter_vars(config, data)
+ print('- result: {res}'.format(res=res))
+ output = test.do_xform(res)
+ print('- transformed: {output}'.format(output=repr(output)))
+ test.output.check_result(output)
+ finally:
+ if test.setenv:
+ os.environ.clear()
+ os.environ.update(save_env)
diff --git a/t/01-get-values.t b/t/01-get-values.t
index d259bf1..e109db1 100644
--- a/t/01-get-values.t
+++ b/t/01-get-values.t
@@ -27,54 +27,64 @@
[ -z "$CONFGET" ] && CONFGET='./confget'
[ -z "$TESTDIR" ] && TESTDIR='t'
-T1="$TESTDIR/t1.ini"
-
echo '1..18'
-if [ ! -f "$T1" ]; then
- echo "Bail out! No test file $T1"
- exit 255
-fi
-v=`$CONFGET -f "$T1" -s a key1`
+if [ ! -f "$TESTDIR/t1.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t1.ini"
+ exit 255
+fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' 'key1' `
+res="$?"
if [ "$v" = 'value1' ]; then echo 'ok 1'; else echo "not ok 1 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -N -s a key2`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-N' 'key2' `
+res="$?"
if [ "$v" = 'key2=value2' ]; then echo 'ok 2'; else echo "not ok 2 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s a key3`
-if [ "$v" = " val'ue3" ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s 'b sect' key4`
-if [ "$v" = "v'alu'e4" ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s c key5`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' 'key3' `
+res="$?"
+if [ "$v" = ' val'"'"'ue3' ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'b sect' 'key4' `
+res="$?"
+if [ "$v" = 'v'"'"'alu'"'"'e4' ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'c' 'key5' `
+res="$?"
if [ "$v" = ' # value5' ]; then echo 'ok 5'; else echo "not ok 5 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s a key1 key2 | tr "\n" ' '`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' 'key1' 'key2' | tr "\n" " "`
+res="$?"
if [ "$v" = 'key1=value1 key2=value2 ' ]; then echo 'ok 6'; else echo "not ok 6 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s a -n key6 key2 | tr "\n" ' '`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-n' 'key6' 'key2' | tr "\n" " "`
+res="$?"
if [ "$v" = 'value2 value6 ' ]; then echo 'ok 7'; else echo "not ok 7 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s 'b sect' key7`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'b sect' 'key7' `
+res="$?"
if [ "$v" = 'value7' ]; then echo 'ok 8'; else echo "not ok 8 v is '$v'"; fi
-v=`$CONFGET -f - -s 'b sect' key7 < "$T1"`
+v=`$CONFGET '-s' 'b sect' -f - 'key7' < "$TESTDIR/t1.ini" `
+res="$?"
if [ "$v" = 'value7' ]; then echo 'ok 9'; else echo "not ok 9 v is '$v'"; fi
-v=`$CONFGET -f - -s 'b sect' key77 < "$T1"`
+v=`$CONFGET '-s' 'b sect' -f - 'key77' < "$TESTDIR/t1.ini" `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 10'; else echo "not ok 10 v is '$v'"; fi
-
-QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3'
-Q1='key4&amp;key5=%09%09%20val%27ue5&key6'
-Q2=''
-export QUERY_STRING Q1 Q2
-
-v=`$CONFGET -t http_get key1`
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get 'key1' `
+res="$?"
if [ "$v" = 'value1' ]; then echo 'ok 11'; else echo "not ok 11 v is '$v'"; fi
-v=`$CONFGET -t http_get -N key2`
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-N' 'key2' `
+res="$?"
if [ "$v" = 'key2==value2&' ]; then echo 'ok 12'; else echo "not ok 12 v is '$v'"; fi
-v=`$CONFGET -t http_get key3`
-if [ "$v" = " val'ue3" ]; then echo 'ok 13'; else echo "not ok 13 v is '$v'"; fi
-v=`$CONFGET -t http_get -s Q1 key4`
-if [ "$v" = "" ]; then echo 'ok 14'; else echo "not ok 14 v is '$v'"; fi
-v=`$CONFGET -t http_get -s Q1 key5`
-if [ "$v" = " val'ue5" ]; then echo 'ok 15'; else echo "not ok 15 v is '$v'"; fi
-v=`$CONFGET -t http_get -s Q1 key6`
-if [ "$v" = "" ]; then echo 'ok 16'; else echo "not ok 16 v is '$v'"; fi
-v=`$CONFGET -t http_get -s Q1 key66`
-if [ "$v" = "" ]; then echo 'ok 17'; else echo "not ok 17 v is '$v'"; fi
-v=`$CONFGET -t http_get -s Q2 key66`
-if [ "$v" = "" ]; then echo 'ok 18'; else echo "not ok 18 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get 'key3' `
+res="$?"
+if [ "$v" = ' val'"'"'ue3' ]; then echo 'ok 13'; else echo "not ok 13 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-s' 'Q1' 'key4' `
+res="$?"
+if [ "$v" = '' ]; then echo 'ok 14'; else echo "not ok 14 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-s' 'Q1' 'key5' `
+res="$?"
+if [ "$v" = ' val'"'"'ue5' ]; then echo 'ok 15'; else echo "not ok 15 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-s' 'Q1' 'key6' `
+res="$?"
+if [ "$v" = '' ]; then echo 'ok 16'; else echo "not ok 16 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-s' 'Q1' 'key66' `
+res="$?"
+if [ "$v" = '' ]; then echo 'ok 17'; else echo "not ok 17 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-s' 'Q2' 'key66' `
+res="$?"
+if [ "$v" = '' ]; then echo 'ok 18'; else echo "not ok 18 v is '$v'"; fi
diff --git a/t/02-check-values.t b/t/02-check-values.t
index fd29a4c..d6c8d5a 100644
--- a/t/02-check-values.t
+++ b/t/02-check-values.t
@@ -27,33 +27,55 @@
[ -z "$CONFGET" ] && CONFGET='./confget'
[ -z "$TESTDIR" ] && TESTDIR='t'
-T1="$TESTDIR/t1.ini"
-
echo '1..15'
-if [ ! -f "$T1" ]; then
- echo "Bail out! No test file $T1"
- exit 255
-fi
-
-if $CONFGET -f "$T1" -s a -c key1; then echo 'ok 1 '; else echo "not ok 1 $?"; fi
-if $CONFGET -f "$T1" -s a -c key2; then echo 'ok 2 '; else echo "not ok 2 $?"; fi
-if $CONFGET -f "$T1" -s a -c key3; then echo 'ok 3 '; else echo "not ok 3 $?"; fi
-if ! $CONFGET -f "$T1" -s a -c key4; then echo 'ok 4 '; else echo "not ok 4 $?"; fi
-if ! $CONFGET -f "$T1" -s 'b sect' -c key5; then echo 'ok 5 '; else echo "not ok 5 $?"; fi
-if $CONFGET -f "$T1" -s 'b sect' -c key4; then echo 'ok 6 '; else echo "not ok 6 $?"; fi
-if $CONFGET -f "$T1" -s c -c key5; then echo 'ok 7 '; else echo "not ok 7 $?"; fi
-QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3'
-Q1='key4&amp;key5=%09%09%20val%27ue5&key6'
-Q2=''
-export QUERY_STRING Q1 Q2
-
-if $CONFGET -t http_get -c key1; then echo 'ok 8 '; else echo "not ok 8 $?"; fi
-if $CONFGET -t http_get -c key2; then echo 'ok 9 '; else echo "not ok 9 $?"; fi
-if $CONFGET -t http_get -c key3; then echo 'ok 10 '; else echo "not ok 10 $?"; fi
-if $CONFGET -t http_get -s Q1 -c key4; then echo 'ok 11 '; else echo "not ok 11 $?"; fi
-if $CONFGET -t http_get -s Q1 -c key6; then echo 'ok 12 '; else echo "not ok 12 $?"; fi
-if ! $CONFGET -t http_get -c key6; then echo 'ok 13 '; else echo "not ok 13 $?"; fi
-if ! $CONFGET -t http_get -s Q1 -c key1; then echo 'ok 14 '; else echo "not ok 14 $?"; fi
-if ! $CONFGET -t http_get -s Q2 -c key1; then echo 'ok 15 '; else echo "not ok 15 $?"; fi
+if [ ! -f "$TESTDIR/t1.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t1.ini"
+ exit 255
+fi
+v=`$CONFGET '-c' '-f' "$TESTDIR/t1.ini" '-s' 'a' 'key1' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 1'; else echo "not ok 1 res is '$res'"; fi
+v=`$CONFGET '-c' '-f' "$TESTDIR/t1.ini" '-s' 'a' 'key2' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 2'; else echo "not ok 2 res is '$res'"; fi
+v=`$CONFGET '-c' '-f' "$TESTDIR/t1.ini" '-s' 'a' 'key3' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 3'; else echo "not ok 3 res is '$res'"; fi
+v=`$CONFGET '-c' '-f' "$TESTDIR/t1.ini" '-s' 'a' 'key4' `
+res="$?"
+if [ "$res" != 0 ]; then echo 'ok 4'; else echo "not ok 4 res is '$res'"; fi
+v=`$CONFGET '-c' '-f' "$TESTDIR/t1.ini" '-s' 'b sect' 'key5' `
+res="$?"
+if [ "$res" != 0 ]; then echo 'ok 5'; else echo "not ok 5 res is '$res'"; fi
+v=`$CONFGET '-c' '-f' "$TESTDIR/t1.ini" '-s' 'b sect' 'key4' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 6'; else echo "not ok 6 res is '$res'"; fi
+v=`$CONFGET '-c' '-f' "$TESTDIR/t1.ini" '-s' 'c' 'key5' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 7'; else echo "not ok 7 res is '$res'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-c' 'key1' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 8'; else echo "not ok 8 res is '$res'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-c' 'key2' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 9'; else echo "not ok 9 res is '$res'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-c' 'key3' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 10'; else echo "not ok 10 res is '$res'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-c' '-s' 'Q1' 'key4' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 11'; else echo "not ok 11 res is '$res'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-c' '-s' 'Q1' 'key6' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 12'; else echo "not ok 12 res is '$res'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-c' 'key6' `
+res="$?"
+if [ "$res" != 0 ]; then echo 'ok 13'; else echo "not ok 13 res is '$res'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-c' '-s' 'Q1' 'key1' `
+res="$?"
+if [ "$res" != 0 ]; then echo 'ok 14'; else echo "not ok 14 res is '$res'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-c' '-s' 'Q2' 'key1' `
+res="$?"
+if [ "$res" != 0 ]; then echo 'ok 15'; else echo "not ok 15 res is '$res'"; fi
diff --git a/t/03-list-all.t b/t/03-list-all.t
index e3b525b..60a8053 100644
--- a/t/03-list-all.t
+++ b/t/03-list-all.t
@@ -27,32 +27,31 @@
[ -z "$CONFGET" ] && CONFGET='./confget'
[ -z "$TESTDIR" ] && TESTDIR='t'
-T1="$TESTDIR/t1.ini"
-
echo '1..7'
-if [ ! -f "$T1" ]; then
- echo "Bail out! No test file $T1"
- exit 255
-fi
-
-l=`$CONFGET -f "$T1" -s a -l | wc -l | tr -d ' '`
-if [ "$l" = '4' ]; then echo 'ok 1'; else echo "not ok 1 '$l'"; fi
-l=`$CONFGET -f "$T1" -N -s 'b sect' -l | fgrep -e '=' | wc -l | tr -d ' '`
-if [ "$l" = '2' ]; then echo 'ok 2'; else echo "not ok 2 '$l'"; fi
-l=`$CONFGET -f "$T1" -n -s c -l | fgrep -ve '=' | wc -l | tr -d ' '`
-if [ "$l" = '1' ]; then echo 'ok 3'; else echo "not ok 3 '$l'"; fi
-l=`$CONFGET -f "$T1" -s d -l | wc -l | tr -d ' '`
-if [ "$l" = '0' ]; then echo 'ok 4'; else echo "not ok 4 '$l'"; fi
-QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3'
-Q1='key4&amp;key5=%09%09%20val%27ue5&key6'
-Q2=''
-export QUERY_STRING Q1 Q2
-
-l=`$CONFGET -t http_get -l | wc -l | tr -d ' '`
-if [ "$l" = '3' ]; then echo 'ok 5'; else echo "not ok 5 '$l'"; fi
-l=`$CONFGET -t http_get -s Q1 -l | wc -l | tr -d ' '`
-if [ "$l" = '3' ]; then echo 'ok 6'; else echo "not ok 6 '$l'"; fi
-l=`$CONFGET -t http_get -s Q2 -l | wc -l | tr -d ' '`
-if [ "$l" = '0' ]; then echo 'ok 7'; else echo "not ok 7 '$l'"; fi
+if [ ! -f "$TESTDIR/t1.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t1.ini"
+ exit 255
+fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-l' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '4' ]; then echo 'ok 1'; else echo "not ok 1 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'b sect' '-l' '-N' | fgrep -e '=' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '2' ]; then echo 'ok 2'; else echo "not ok 2 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'c' '-l' '-n' | fgrep -ve '=' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '1' ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'd' '-l' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '0' ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-l' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '3' ]; then echo 'ok 5'; else echo "not ok 5 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-l' '-s' 'Q1' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '3' ]; then echo 'ok 6'; else echo "not ok 6 v is '$v'"; fi
+v=`env Q1='key4&amp;key5=%09%09%20val%27ue5&key6' Q2='' QUERY_STRING='key1=value1&key2=%3Dvalue2%26&amp;key3=%09%09%20val%27ue3' $CONFGET -t http_get '-l' '-s' 'Q2' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '0' ]; then echo 'ok 7'; else echo "not ok 7 v is '$v'"; fi
diff --git a/t/04-test-manpage.t b/t/04-bespoke-test-manpage.t
index ddc0607..ddc0607 100644
--- a/t/04-test-manpage.t
+++ b/t/04-bespoke-test-manpage.t
diff --git a/t/05-match-names.t b/t/05-match-names.t
index be7d78a..e028e8f 100644
--- a/t/05-match-names.t
+++ b/t/05-match-names.t
@@ -27,20 +27,22 @@
[ -z "$CONFGET" ] && CONFGET='./confget'
[ -z "$TESTDIR" ] && TESTDIR='t'
-T1="$TESTDIR/t1.ini"
-
echo '1..4'
-if [ ! -f "$T1" ]; then
- echo "Bail out! No test file $T1"
- exit 255
-fi
-l=`$CONFGET -f "$T1" -s a -L '*' | wc -l | tr -d ' '`
-if [ "$l" = '4' ]; then echo 'ok 1'; else echo "not ok 1 '$l'"; fi
-l=`$CONFGET -f "$T1" -N -s 'b sect' -L '*' | fgrep -e '=' | wc -l | tr -d ' '`
-if [ "$l" = '2' ]; then echo 'ok 2'; else echo "not ok 2 '$l'"; fi
-l=`$CONFGET -f "$T1" -n -s a -L '*ey2' | fgrep -ve '=' | wc -l | tr -d ' '`
-if [ "$l" = '1' ]; then echo 'ok 3'; else echo "not ok 3 '$l'"; fi
-l=`$CONFGET -f "$T1" -s d -L '*ey2' | wc -l | tr -d ' '`
-if [ "$l" = '0' ]; then echo 'ok 4'; else echo "not ok 4 '$l'"; fi
+if [ ! -f "$TESTDIR/t1.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t1.ini"
+ exit 255
+fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-L' '*' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '4' ]; then echo 'ok 1'; else echo "not ok 1 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'b sect' '-L' '-N' '*' | fgrep -e '=' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '2' ]; then echo 'ok 2'; else echo "not ok 2 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-L' '-n' '*ey2' | fgrep -ve '=' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '1' ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'd' '-L' '*ey2' | wc -l | tr -d ' '`
+res="$?"
+if [ "$v" = '0' ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
diff --git a/t/06-get-default.t b/t/06-get-default.t
index 6755248..d15341f 100644
--- a/t/06-get-default.t
+++ b/t/06-get-default.t
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# Copyright (c) 2008 Peter Pentchev
+# Copyright (c) 2008, 2011 Peter Pentchev
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -27,27 +27,30 @@
[ -z "$CONFGET" ] && CONFGET='./confget'
[ -z "$TESTDIR" ] && TESTDIR='t'
-T1="$TESTDIR/t1.ini"
-T2="$TESTDIR/t2.ini"
-
echo '1..5'
-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
+
+if [ ! -f "$TESTDIR/t1.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t1.ini"
+ exit 255
fi
-v=`$CONFGET -f "$T1" key1`
+if [ ! -f "$TESTDIR/t2.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t2.ini"
+ exit 255
+fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" 'key1' `
+res="$?"
if [ "$v" = 'value1' ]; then echo 'ok 1'; else echo "not ok 1 v is '$v'"; fi
-v=`$CONFGET -f "$T1" key4`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" 'key4' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 2'; else echo "not ok 2 v is '$v'"; fi
-v=`$CONFGET -f "$T1" key6`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" 'key6' `
+res="$?"
if [ "$v" = 'value6' ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
-v=`$CONFGET -f "$T2" key1`
+v=`$CONFGET '-f' "$TESTDIR/t2.ini" 'key1' `
+res="$?"
if [ "$v" = '1' ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
-v=`$CONFGET -f "$T2" key1 key2 | tr "\n" ' '`
+v=`$CONFGET '-f' "$TESTDIR/t2.ini" 'key1' 'key2' | tr "\n" " "`
+res="$?"
if [ "$v" = 'key1=1 key2=2 ' ]; then echo 'ok 5'; else echo "not ok 5 v is '$v'"; fi
diff --git a/t/07-match-values.t b/t/07-match-values.t
index bfcda6f..37f5238 100644
--- a/t/07-match-values.t
+++ b/t/07-match-values.t
@@ -27,28 +27,37 @@
[ -z "$CONFGET" ] && CONFGET='./confget'
[ -z "$TESTDIR" ] && TESTDIR='t'
-T1="$TESTDIR/t1.ini"
-
echo '1..9'
-if [ ! -f "$T1" ]; then
- echo "Bail out! No test file $T1"
- exit 255
-fi
-v=`$CONFGET -f "$T1" -m 'value*' -s a key1`
+if [ ! -f "$TESTDIR/t1.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t1.ini"
+ exit 255
+fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-m' 'value*' 'key1' `
+res="$?"
if [ "$v" = 'value1' ]; then echo 'ok 1'; else echo "not ok 1 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -m '*ue2' -s a key2`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-m' '*ue2' 'key2' `
+res="$?"
if [ "$v" = 'value2' ]; then echo 'ok 2'; else echo "not ok 2 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -m "*val'ue*" -s a key3`
-if [ "$v" = " val'ue3" ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -m '*alu*' -s 'b sect' key4`
-if [ "$v" = "v'alu'e4" ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s c key5`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-m' '*val'"'"'ue*' 'key3' `
+res="$?"
+if [ "$v" = ' val'"'"'ue3' ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'b sect' '-m' '*alu*' 'key4' `
+res="$?"
+if [ "$v" = 'v'"'"'alu'"'"'e4' ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'c' 'key5' `
+res="$?"
if [ "$v" = ' # value5' ]; then echo 'ok 5'; else echo "not ok 5 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -m '*alu*' -s a key1 key2 | tr "\n" ' '`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-m' '*alu*' 'key1' 'key2' | tr "\n" " "`
+res="$?"
if [ "$v" = 'key1=value1 key2=value2 ' ]; then echo 'ok 6'; else echo "not ok 6 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s a -m '*7' key6`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'a' '-m' '*7' 'key6' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 7'; else echo "not ok 7 v is '$v'"; fi
-if $CONFGET -f "$T1" -s 'b sect' -c -m '*7' key7; then echo 'ok 8'; else echo "not ok 8 code '$?'"; fi
-if ! $CONFGET -f "$T1" -s 'b sect' -c -m '*7' key6; then echo 'ok 9'; else echo "not ok 9 code '$?'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'b sect' '-c' '-m' '*7' 'key7' `
+res="$?"
+if [ "$res" = 0 ]; then echo 'ok 8'; else echo "not ok 8 res is '$res'"; fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' 'b sect' '-c' '-m' '*7' 'key6' `
+res="$?"
+if [ "$res" != 0 ]; then echo 'ok 9'; else echo "not ok 9 res is '$res'"; fi
diff --git a/t/08-shell-quote.t b/t/08-bespoke-shell-quote.t
index 49264ad..49264ad 100644
--- a/t/08-shell-quote.t
+++ b/t/08-bespoke-shell-quote.t
diff --git a/t/09-regexp.t b/t/09-bespoke-regexp.t
index 684de13..684de13 100644
--- a/t/09-regexp.t
+++ b/t/09-bespoke-regexp.t
diff --git a/t/10-qsections.t b/t/10-bespoke-qsections.t
index 7b7804a..7b7804a 100644
--- a/t/10-qsections.t
+++ b/t/10-bespoke-qsections.t
diff --git a/t/11-no-default.t b/t/11-no-default.t
index 82b96e4..07b3dba 100644
--- a/t/11-no-default.t
+++ b/t/11-no-default.t
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# Copyright (c) 2008, 2016 Peter Pentchev
+# Copyright (c) 2008, 2011 Peter Pentchev
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -27,40 +27,45 @@
[ -z "$CONFGET" ] && CONFGET='./confget'
[ -z "$TESTDIR" ] && TESTDIR='t'
-T1="$TESTDIR/t1.ini"
-T2="$TESTDIR/t2.ini"
-
echo '1..10'
-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
+
+if [ ! -f "$TESTDIR/t1.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t1.ini"
+ exit 255
fi
-v=`$CONFGET -f "$T1" key1`
+if [ ! -f "$TESTDIR/t2.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t2.ini"
+ exit 255
+fi
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" 'key1' `
+res="$?"
if [ "$v" = 'value1' ]; then echo 'ok 1'; else echo "not ok 1 v is '$v'"; fi
-v=`$CONFGET -f "$T1" key4`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" 'key4' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 2'; else echo "not ok 2 v is '$v'"; fi
-v=`$CONFGET -f "$T1" key6`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" 'key6' `
+res="$?"
if [ "$v" = 'value6' ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
-
-v=`$CONFGET -f "$T1" -s '' key1`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' '' 'key1' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s '' key4`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' '' 'key4' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 5'; else echo "not ok 5 v is '$v'"; fi
-v=`$CONFGET -f "$T1" -s '' key6`
+v=`$CONFGET '-f' "$TESTDIR/t1.ini" '-s' '' 'key6' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 6'; else echo "not ok 6 v is '$v'"; fi
-
-v=`$CONFGET -f "$T2" key1`
+v=`$CONFGET '-f' "$TESTDIR/t2.ini" 'key1' `
+res="$?"
if [ "$v" = '1' ]; then echo 'ok 7'; else echo "not ok 7 v is '$v'"; fi
-v=`$CONFGET -f "$T2" key1 key2 | tr "\n" ' '`
+v=`$CONFGET '-f' "$TESTDIR/t2.ini" 'key1' 'key2' | tr "\n" " "`
+res="$?"
if [ "$v" = 'key1=1 key2=2 ' ]; then echo 'ok 8'; else echo "not ok 8 v is '$v'"; fi
-
-v=`$CONFGET -f "$T2" -s '' key1`
+v=`$CONFGET '-f' "$TESTDIR/t2.ini" '-s' '' 'key1' `
+res="$?"
if [ "$v" = '1' ]; then echo 'ok 9'; else echo "not ok 9 v is '$v'"; fi
-v=`$CONFGET -f "$T2" -s '' key1 key2 | tr "\n" ' '`
+v=`$CONFGET '-f' "$TESTDIR/t2.ini" '-s' '' 'key1' 'key2' | tr "\n" " "`
+res="$?"
if [ "$v" = 'key1=1 key2=2 ' ]; then echo 'ok 10'; else echo "not ok 10 v is '$v'"; fi
diff --git a/t/12-last-value.t b/t/12-last-value.t
index a4623bb..3ee2950 100644
--- a/t/12-last-value.t
+++ b/t/12-last-value.t
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# Copyright (c) 2008, 2016 Peter Pentchev
+# Copyright (c) 2008, 2011 Peter Pentchev
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -27,45 +27,52 @@
[ -z "$CONFGET" ] && CONFGET='./confget'
[ -z "$TESTDIR" ] && TESTDIR='t'
-T3="$TESTDIR/t3.ini"
-
echo '1..14'
-if [ ! -f "$T3" ]; then
- echo "Bail out! No test file $T3"
- exit 255
-fi
-v=`$CONFGET -f "$T3" both`
+if [ ! -f "$TESTDIR/t3.ini" ]; then
+ echo "Bail out! No test file $TESTDIR/t3.ini"
+ exit 255
+fi
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" 'both' `
+res="$?"
if [ "$v" = 'default' ]; then echo 'ok 1'; else echo "not ok 1 v is '$v'"; fi
-v=`$CONFGET -f "$T3" defonly`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" 'defonly' `
+res="$?"
if [ "$v" = 'default' ]; then echo 'ok 2'; else echo "not ok 2 v is '$v'"; fi
-v=`$CONFGET -f "$T3" aonly`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" 'aonly' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 3'; else echo "not ok 3 v is '$v'"; fi
-
-v=`$CONFGET -f "$T3" -s '' both`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' '' 'both' `
+res="$?"
if [ "$v" = 'default' ]; then echo 'ok 4'; else echo "not ok 4 v is '$v'"; fi
-v=`$CONFGET -f "$T3" -s '' defonly`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' '' 'defonly' `
+res="$?"
if [ "$v" = 'default' ]; then echo 'ok 5'; else echo "not ok 5 v is '$v'"; fi
-v=`$CONFGET -f "$T3" -s '' aonly`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' '' 'aonly' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 6'; else echo "not ok 6 v is '$v'"; fi
-
-v=`$CONFGET -f "$T3" -s 'a' both`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' 'a' 'both' `
+res="$?"
if [ "$v" = 'a' ]; then echo 'ok 7'; else echo "not ok 7 v is '$v'"; fi
-v=`$CONFGET -f "$T3" -s 'a' defonly`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' 'a' 'defonly' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 8'; else echo "not ok 8 v is '$v'"; fi
-v=`$CONFGET -f "$T3" -s 'a' aonly`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' 'a' 'aonly' `
+res="$?"
if [ "$v" = 'a' ]; then echo 'ok 9'; else echo "not ok 9 v is '$v'"; fi
-
-v=`$CONFGET -f "$T3" -O -s 'a' both`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' 'a' '-O' 'both' `
+res="$?"
if [ "$v" = 'a' ]; then echo 'ok 10'; else echo "not ok 10 v is '$v'"; fi
-v=`$CONFGET -f "$T3" -O -s 'a' defonly`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' 'a' '-O' 'defonly' `
+res="$?"
if [ "$v" = 'default' ]; then echo 'ok 11'; else echo "not ok 11 v is '$v'"; fi
-v=`$CONFGET -f "$T3" -O -s 'a' aonly`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-s' 'a' '-O' 'aonly' `
+res="$?"
if [ "$v" = 'a' ]; then echo 'ok 12'; else echo "not ok 12 v is '$v'"; fi
-
-# A non-matching value should override a matching one and nothing should be displayed.
-v=`$CONFGET -f "$T3" -O -s 'a' -m 'def*' both`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-m' 'def*' '-s' 'a' '-O' 'both' `
+res="$?"
if [ "$v" = '' ]; then echo 'ok 13'; else echo "not ok 13 v is '$v'"; fi
-v=`$CONFGET -f "$T3" -O -s 'a' -m 'a*' both`
+v=`$CONFGET '-f' "$TESTDIR/t3.ini" '-m' 'a*' '-s' 'a' '-O' 'both' `
+res="$?"
if [ "$v" = 'a' ]; then echo 'ok 14'; else echo "not ok 14 v is '$v'"; fi
diff --git a/t/13-features.t b/t/13-bespoke-features.t
index 4ed1088..4ed1088 100644
--- a/t/13-features.t
+++ b/t/13-bespoke-features.t
diff --git a/t/14-too-many.t b/t/14-bespoke-too-many.t
index 5c1be63..5c1be63 100644
--- a/t/14-too-many.t
+++ b/t/14-bespoke-too-many.t
diff --git a/t/generate.py b/t/generate.py
new file mode 100755
index 0000000..370c925
--- /dev/null
+++ b/t/generate.py
@@ -0,0 +1,145 @@
+#!/usr/bin/python3
+#
+# Copyright (c) 2018 Peter Pentchev <roam@ringlet.net>
+# 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.
+
+"""
+Generate shell scripts with TAP output for the confget tests.
+"""
+
+from typing import List
+
+from unit_tests import data as t_data
+
+
+PRELUDE = r'''#!/bin/sh
+#
+# Copyright (c) 2008, 2011 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'
+
+echo '1..{count}'
+'''
+
+CHECK_TESTFILE = r'''
+if [ ! -f "$TESTDIR/{fname}" ]; then
+ echo "Bail out! No test file $TESTDIR/{fname}"
+ exit 255
+fi'''
+
+
+def add_cmdline_options(cmdline: List[str], test: t_data.defs.TestDef
+ ) -> None:
+ """ Add the options from test.args into cmdline. """
+ for name, value in test.args.items():
+ option = t_data.CMDLINE_OPTIONS[name]
+ if option[0] == '':
+ continue
+ cmdline.append(f"'{option[0]}'")
+ if option[1]:
+ if name == 'filename':
+ cmdline.append(f'"$TESTDIR/{value}"')
+ else:
+ cmdline.append(t_data.shell_escape(value))
+
+
+def main() -> None:
+ """ Main function: generate the test files. """
+ for fname, data in sorted(t_data.TESTS.items()):
+ print(f'Generating {fname}.t with {len(data.tests)} tests')
+ with open(f'{fname}.t', mode='w') as testf:
+ print(PRELUDE.format(count=len(data.tests)), file=testf)
+
+ filenames = sorted({
+ test.args['filename'] for test in data.tests
+ if 'filename' in test.args
+ })
+ for filename in filenames:
+ print(CHECK_TESTFILE.format(fname=filename), file=testf)
+
+ for idx, test in enumerate(data.tests):
+ tap_idx = idx + 1
+
+ cmdline: List[str] = []
+ if test.setenv:
+ cmdline.append('env')
+ for name, value in sorted(data.setenv.items()):
+ cmdline.append(f'{name}={t_data.shell_escape(value)}')
+
+ cmdline.append('$CONFGET')
+ if test.backend != 'ini':
+ cmdline.extend(['-t', test.backend])
+
+ add_cmdline_options(cmdline, test)
+
+ if test.stdin is not None:
+ cmdline.extend([
+ t_data.CMDLINE_OPTIONS['filename'][0],
+ '-'
+ ])
+
+ cmdline.extend([f"'{key}'" for key in test.keys])
+
+ if test.stdin is not None:
+ cmdline.extend(['<', f'"$TESTDIR/{test.stdin}"'])
+
+ xform = t_data.XFORM[test.xform].command
+ print(f'- {tap_idx}: {" ".join(cmdline)} {xform}')
+
+ print(f'v=`{" ".join(cmdline)} {xform}`', file=testf)
+ print('res="$?"', file=testf)
+
+ check = test.output.get_check()
+ print(f' - {check}')
+ print(f"if {check}; then echo 'ok {tap_idx}'; else "
+ f'echo "not ok {tap_idx} {test.output.var_name} is '
+ f"'${test.output.var_name}'\"; fi",
+ file=testf)
+
+
+if __name__ == '__main__':
+ main()