[pacman-dev] [PATCH 1/3] pactest: parse options before environment setup
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/pacman/pactest.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/pacman/pactest.py b/test/pacman/pactest.py index 0e06f17..b2b9c28 100755 --- a/test/pacman/pactest.py +++ b/test/pacman/pactest.py @@ -82,12 +82,14 @@ def create_parser(): tap.bail("Python versions before 2.7 are not supported.") sys.exit(1) - # instantiate env and parser objects - root_path = tempfile.mkdtemp(prefix='pactest-') - env = pmenv.pmenv(root=root_path) + # parse options opt_parser = create_parser() (opts, args) = opt_parser.parse_args() + # instantiate env + root_path = tempfile.mkdtemp(prefix='pactest-') + env = pmenv.pmenv(root=root_path) + # add parsed options to env object util.verbose = opts.verbose env.pacman["debug"] = opts.debug -- 2.0.1
Using fakeroot or fakechroot as the command with subprocess.call prevents the detection and reporting of a missing pacman binary. Some tests even pass when run with a non-existent binary. Checking manually allows us to provide a meaningful error message and prevent the false positives. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/pacman/pactest.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/pacman/pactest.py b/test/pacman/pactest.py index b2b9c28..cba439c 100755 --- a/test/pacman/pactest.py +++ b/test/pacman/pactest.py @@ -49,7 +49,7 @@ def create_parser(): help = "set debug level for pacman") parser.add_option("-p", "--pacman", action = "callback", callback = resolve_binary_path, type = "string", - dest = "bin", default = "pacman", + dest = "bin", default = util.which("pacman"), help = "specify location of the pacman binary") parser.add_option("--keep-root", action = "store_true", dest = "keeproot", default = False, @@ -86,6 +86,10 @@ def create_parser(): opt_parser = create_parser() (opts, args) = opt_parser.parse_args() + if opts.bin is None or not os.access(opts.bin, os.X_OK): + tap.bail("cannot locate pacman binary") + sys.exit(2) + # instantiate env root_path = tempfile.mkdtemp(prefix='pactest-') env = pmenv.pmenv(root=root_path) -- 2.0.1
Setting up the temporary directory and environment is pointless if there are no tests to run. Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com> --- test/pacman/pactest.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/pacman/pactest.py b/test/pacman/pactest.py index cba439c..58c14f6 100755 --- a/test/pacman/pactest.py +++ b/test/pacman/pactest.py @@ -90,6 +90,10 @@ def create_parser(): tap.bail("cannot locate pacman binary") sys.exit(2) + if args is None or len(args) == 0: + tap.bail("no tests defined, nothing to do") + sys.exit(2) + # instantiate env root_path = tempfile.mkdtemp(prefix='pactest-') env = pmenv.pmenv(root=root_path) @@ -105,11 +109,6 @@ def create_parser(): env.pacman["scriptlet-shell"] = opts.scriptletshell env.pacman["ldconfig"] = opts.ldconfig - if args is None or len(args) == 0: - tap.bail("no tests defined, nothing to do") - os.rmdir(root_path) - sys.exit(2) - try: for i in args: env.addtest(i) -- 2.0.1
participants (1)
-
Andrew Gregory