forked from ariadne/pkgconf
Compare commits
No commits in common. "0ce072cb6494c900651245ad2645e98732f39f42" and "68e3f24000726b72757ff19bef5a7837f4c08d94" have entirely different histories.
0ce072cb64
...
68e3f24000
137
tests/basic.toml
137
tests/basic.toml
|
@ -1,137 +0,0 @@
|
||||||
[noargs]
|
|
||||||
exitcode = 1
|
|
||||||
|
|
||||||
[libs]
|
|
||||||
stdout = "-L/test/lib -lfoo\n"
|
|
||||||
args = ["--libs", "foo"]
|
|
||||||
|
|
||||||
[libs.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[lib_cflags]
|
|
||||||
stdout = "-fPIC -I/test/include/foo -L/test/lib -lfoo\n"
|
|
||||||
args = ["--cflags", "--libs", "foo"]
|
|
||||||
|
|
||||||
[lib_cflags.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[lib_cflags_version]
|
|
||||||
stdout = "-fPIC -I/test/include/foo -L/test/lib -lfoo\n"
|
|
||||||
args = ["--cflags", "--libs", "foo > 1.2"]
|
|
||||||
|
|
||||||
[lib_cflags_version.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[lib_cflags_version_multiple]
|
|
||||||
stdout = "-fPIC -I/test/include/foo -L/test/lib -lbar -lfoo\n"
|
|
||||||
args = ["--cflags", "--libs", "foo > 1.2 bar >= 1.3"]
|
|
||||||
|
|
||||||
[lib_cflags_version_multiple.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[lib_cflags_version_multiple_comma]
|
|
||||||
stdout = "-fPIC -I/test/include/foo -L/test/lib -lbar -lfoo\n"
|
|
||||||
args = ["--cflags", "--libs", "foo > 1.2,bar >= 1.3"]
|
|
||||||
|
|
||||||
[lib_cflags_version_multiple_comma.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[lib_cflags_version_alt]
|
|
||||||
stdout = "-fPIC -I/test/include/foo -L/test/lib -lfoo\n"
|
|
||||||
args = ["--cflags", "--libs", "foo", ">", "1.2"]
|
|
||||||
|
|
||||||
[lib_cflags_version_alt.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[lib_cflags_version_different]
|
|
||||||
stdout = "-fPIC -I/test/include/foo -L/test/lib -lfoo\n"
|
|
||||||
args = ["--cflags", "--libs", "foo", "!=", "1.3"]
|
|
||||||
|
|
||||||
[lib_cflags_version_different.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[lib_cflags_version_different_bad]
|
|
||||||
exitcode = 1
|
|
||||||
stderr = "Package dependency requirement 'foo != 1.2.3' could not be satisfied.\nPackage 'foo' has version '1.2.3', required version is '!= 1.2.3'\n"
|
|
||||||
args = ["--cflags", "--libs", "foo", "!=", "1.2.3"]
|
|
||||||
|
|
||||||
[lib_cflags_version_different_bad.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists_nonexistent]
|
|
||||||
exitcode = 1
|
|
||||||
args = ["--exists", "nonexistant"]
|
|
||||||
|
|
||||||
[exists_nonexistent.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[nonexistent]
|
|
||||||
exitcode = 1
|
|
||||||
args = ["nonexistant"]
|
|
||||||
|
|
||||||
[nonexistent.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists_version]
|
|
||||||
args = ["--exists", "foo > 1.2"]
|
|
||||||
|
|
||||||
[exists_version.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists_version_alt]
|
|
||||||
args = ["--exists", "foo", ">", "1.2"]
|
|
||||||
|
|
||||||
[exists_version_alt.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists_version_bad]
|
|
||||||
exitcode = 1
|
|
||||||
args = ["--exists", "foo > 1.2.3"]
|
|
||||||
|
|
||||||
[exists_version_bad.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[uninstalled_bad]
|
|
||||||
exitcode = 1
|
|
||||||
args = ["--uninstalled", "foo"]
|
|
||||||
|
|
||||||
[uninstalled_bad.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[uninstalled]
|
|
||||||
args = ["--uninstalled", "omg"]
|
|
||||||
|
|
||||||
[uninstalled.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists_version_bad2]
|
|
||||||
exitcode = 1
|
|
||||||
args = ["--exists", "foo >= "]
|
|
||||||
|
|
||||||
[exists_version_bad2.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists_version_bad3]
|
|
||||||
exitcode = 1
|
|
||||||
args = ["--exists", "tilde >= 1.0.0"]
|
|
||||||
|
|
||||||
[exists_version_bad3.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists]
|
|
||||||
args = ["--exists", "tilde >= 1.0.0"]
|
|
||||||
|
|
||||||
[exists.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists2]
|
|
||||||
args = ["--exists", "tilde >= 1.0.0~rc1"]
|
|
||||||
|
|
||||||
[exists2.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
||||||
|
|
||||||
[exists3]
|
|
||||||
args = ["--exists", "", "foo"]
|
|
||||||
|
|
||||||
[exists3.env]
|
|
||||||
PKG_CONFIG_PATH="{test_root}/lib1"
|
|
125
tests/runner.py
125
tests/runner.py
|
@ -1,125 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
# Copyright (c) 2016 pkgconf authors (see AUTHORS).
|
|
||||||
#
|
|
||||||
# Permission to use, copy, modify, and/or distribute this software for any
|
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
|
||||||
# copyright notice and this permission notice appear in all copies.
|
|
||||||
#
|
|
||||||
# This software is provided 'as is' and without any warranty, express or
|
|
||||||
# implied. In no event shall the authors be liable for any damages arising
|
|
||||||
# from the use of this software.
|
|
||||||
|
|
||||||
"""Simple runner for test cases."""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
import argparse
|
|
||||||
import asyncio
|
|
||||||
import dataclasses
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import typing
|
|
||||||
|
|
||||||
try:
|
|
||||||
import tomllib
|
|
||||||
except ImportError:
|
|
||||||
import tomli as tomllib
|
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
|
||||||
|
|
||||||
class TestDefinition(typing.TypedDict, total=False):
|
|
||||||
exitcode: int
|
|
||||||
stdout: str
|
|
||||||
stderr: str
|
|
||||||
args: typing.List[str]
|
|
||||||
env: typing.Dict[str, str]
|
|
||||||
|
|
||||||
class Arguments(typing.Protocol):
|
|
||||||
suites: typing.List[str]
|
|
||||||
pkgconf: str
|
|
||||||
verbose: bool
|
|
||||||
|
|
||||||
|
|
||||||
TEST_ROOT = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass
|
|
||||||
class Result:
|
|
||||||
|
|
||||||
name: str
|
|
||||||
success: bool = False
|
|
||||||
reason: typing.Optional[str] = None
|
|
||||||
|
|
||||||
|
|
||||||
def interpolate(input: str) -> str:
|
|
||||||
return input.format(
|
|
||||||
test_root=TEST_ROOT,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def run_test(pkgconf: str, name: str, test: TestDefinition, verbose: bool) -> Result:
|
|
||||||
|
|
||||||
env: typing.Dict[str, str] = {}
|
|
||||||
if (renv := test.get('env', None)) is not None:
|
|
||||||
env = {k: interpolate(v) for k, v in renv.items()}
|
|
||||||
|
|
||||||
proc = await asyncio.create_subprocess_exec(
|
|
||||||
pkgconf, *test.get('args', []),
|
|
||||||
stdout=asyncio.subprocess.PIPE if 'stdout' in test is not None else asyncio.subprocess.DEVNULL,
|
|
||||||
stderr=asyncio.subprocess.PIPE if 'stderr' in test is not None else asyncio.subprocess.DEVNULL,
|
|
||||||
env=env)
|
|
||||||
|
|
||||||
rout, rerr = await proc.communicate()
|
|
||||||
out = rout.decode() if rout is not None else ''
|
|
||||||
err = rerr.decode() if rerr is not None else ''
|
|
||||||
|
|
||||||
result = Result(name)
|
|
||||||
|
|
||||||
if (ret := test.get('exitcode', 0)) and proc.returncode != ret:
|
|
||||||
result.reason = f"Return code was {proc.returncode}, but expected {ret}"
|
|
||||||
elif (exp := test.get('stdout')) is not None and out != exp:
|
|
||||||
result.reason = f"Stdout was {out}, but expected {exp}"
|
|
||||||
elif (exp := test.get('stderr')) is not None and err != exp:
|
|
||||||
result.reason = f"Stdout was {err}, but expected {err}"
|
|
||||||
else:
|
|
||||||
result.success = True
|
|
||||||
|
|
||||||
if verbose:
|
|
||||||
if result.success:
|
|
||||||
print(f"{name}: passed")
|
|
||||||
else:
|
|
||||||
print(f"{name}: failed\n reason: {result.reason}")
|
|
||||||
|
|
||||||
return result
|
|
||||||
|
|
||||||
|
|
||||||
async def run(args: Arguments) -> None:
|
|
||||||
tests: typing.List[typing.Coroutine[typing.Any, typing.Any, Result]] = []
|
|
||||||
for suite in args.suites:
|
|
||||||
with open(suite, 'rb') as f:
|
|
||||||
suite: typing.Dict[str, TestDefinition] = tomllib.load(f)
|
|
||||||
|
|
||||||
tests.extend(
|
|
||||||
[run_test(args.pkgconf, n, s, args.verbose) for n, s in suite.items()])
|
|
||||||
|
|
||||||
results = await asyncio.gather(*tests)
|
|
||||||
|
|
||||||
return all(r.success for r in results)
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
|
||||||
parser = argparse.ArgumentParser()
|
|
||||||
parser.add_argument('pkgconf', help="Path to built pkgconf executable")
|
|
||||||
parser.add_argument('suites', nargs="+", help="One or more toml test suite definition")
|
|
||||||
parser.add_argument('-v', '--verbose', action='store_true',
|
|
||||||
help="Print more information while running")
|
|
||||||
args: Arguments = parser.parse_args()
|
|
||||||
|
|
||||||
loop = asyncio.new_event_loop()
|
|
||||||
success = loop.run_until_complete(run(args))
|
|
||||||
|
|
||||||
sys.exit(int(not success))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
Loading…
Reference in New Issue