[reprotest] 02/03: Make it possible to omit "auto" when building packages

Ximin Luo infinity0 at debian.org
Thu Aug 31 21:17:19 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository reprotest.

commit f3d2dde75721d145db1790a5cd8e85a221117d7a
Author: Ximin Luo <infinity0 at debian.org>
Date:   Thu Aug 31 22:51:54 2017 +0200

    Make it possible to omit "auto" when building packages
---
 README.rst            |  95 ++++++++++++------------
 debian/NEWS           |   5 +-
 debian/TODO           |  15 +---
 doc/reprotest.h2m.0   |   8 +--
 reprotest/__init__.py | 194 +++++++++++++++++++++++++++++++++-----------------
 reprotest/presets.py  |   3 +-
 tests/tests.py        |  44 ++++++++++++
 7 files changed, 227 insertions(+), 137 deletions(-)

diff --git a/README.rst b/README.rst
index 67f6b13..9ae7fb5 100644
--- a/README.rst
+++ b/README.rst
@@ -1,49 +1,49 @@
 Command-line examples
 =====================
 
-The easiest way to run reprotest is via our presets:
-
-::
+The easiest way to run reprotest is via our presets::
 
     # Build the current directory in a null server (/tmp)
-    $ reprotest auto .
-    $ reprotest auto . -- null -d # for more verbose output
+    $ reprotest .
+    $ reprotest . -- null -d # for more verbose output
 
     # Build the given Debian source package in an schroot
     # See https://wiki.debian.org/sbuild for instructions on setting that up.
-    $ reprotest auto reprotest_0.3.3.dsc -- schroot unstable-amd64-sbuild
+    $ reprotest reprotest_0.3.3.dsc -- schroot unstable-amd64-sbuild
 
 Currently, we only support this for Debian packages, but are keen on
 adding more. If we don't have knowledge on how to build your file or
 directory, you can send a patch to us on adding this intelligence - see
 the reprotest.presets python module, and adapt the existing logic.
 
-In the meantime, you can use the more advanced CLI to build arbitrary
-things. This takes two mandatory arguments, the build command to run and
-the build artifact file/pattern to test after running the build. For
-example:
-
-::
+In the meantime, you can use other parts of the CLI to build arbitrary things.
+You'll need to give two mandatory arguments, the build command to run and the
+build artifact file/pattern to test after running the build. For example::
 
     $ reprotest 'python3 setup.py bdist' 'dist/*.tar.gz'
 
-When using this from a shell:
+This runs the command on ``.``, the current working directory. To run it on a
+project located elsewhere::
 
-If the build command has spaces, you will need to quote them, e.g.
-``reprotest "debuild -b -uc -us" [..]``.
+    $ reprotest -s ../path/to/other/project 'python3 setup.py bdist' 'dist/*.tar.gz'
+    $ reprotest -c 'python3 setup.py bdist' ../path/to/other/project 'dist/*.tar.gz'
 
-If you want to use several build artifact patterns, or if you want to
-use shell wildcards as a pattern, you will also need to quote them, e.g.
-``reprotest [..] "*.tar.gz *.tar.xz"``.
+These two invocations are equivalent; you can pick the most convenient one
+for your use-case. When using these from a shell:
 
-If your build artifacts have spaces in their names, you will need to
-quote these twice, e.g. ``'"a file with spaces.gz"'`` for a single
-artifact or ``'"dir 1"/* "dir 2"/*'`` for multiple patterns.
+  * If the build command has spaces, you will need to quote them, e.g.
+    ``reprotest "debuild -b -uc -us" [..]``.
 
-To get more help for the CLI, including documentation on optional
-arguments and what they do, run:
+  * If you want to use several build artifact patterns, or if you want to
+    use shell wildcards as a pattern, you will also need to quote them, e.g.
+    ``reprotest [..] "*.tar.gz *.tar.xz"``.
 
-::
+  * If your build artifacts have spaces in their names, you will need to
+    quote these twice, e.g. ``'"a file with spaces.gz"'`` for a single
+    artifact or ``'"dir 1"/* "dir 2"/*'`` for multiple patterns.
+
+To get more help for the CLI, including documentation on optional
+arguments and what they do, run::
 
     $ reprotest --help
 
@@ -52,40 +52,37 @@ Running in a virtual server
 ===========================
 
 You can also run the build inside what is called a "virtual server".
-This could be a container, a chroot, etc. You run them like this:
+This could be a container, a chroot, etc. You run them like this::
 
-::
-
-    $ reprotest 'python3 setup.py bdist_wheel' 'dist/*.whl' qemu    /path/to/qemu.img
-    $ reprotest 'debuild -b -uc -us'           '../*.deb'   schroot unstable-amd64
+    $ reprotest 'python3 setup.py bdist_wheel' 'dist/*.whl' -- qemu    /path/to/qemu.img
+    $ reprotest 'debuild -b -uc -us'           '../*.deb'   -- schroot unstable-amd64
 
 There are different server types available. See ``--help`` for a list of
 them, which appears near the top, in the "virtual\_server\_args" part of
 the "positional arguments" section.
 
 For each virtual server (e.g. "schroot"), you see which extra arguments
-it supports:
-
-::
+it supports::
 
     $ reprotest --help schroot
 
 When running builds inside a virtual server, you will probably have to
 give extra commands, in order to set up your build dependencies inside
 the virtual server. For example, to take you through what the "Debian
-directory" preset would look like, if we ran it via the advanced CLI:
-
-::
+directory" preset would look like, if we ran it using the full CLI::
 
     # "Debian directory" preset
-    $ reprotest auto . -- schroot unstable-amd64-sbuild
-    # In the advanced CLI, this is equivalent to roughly:
+    $ reprotest . -- schroot unstable-amd64-sbuild
+    # This is exactly equivalent to this:
+    $ reprotest -c auto . -- schroot unstable-amd64-sbuild
+    # In the non-preset full CLI, this is roughly similar to:
     $ reprotest \
         --testbed-init 'apt-get -y --no-install-recommends install \
                         util-linux disorderfs 2>/dev/null; \
                         test -c /dev/fuse || mknod -m 666 /dev/fuse c 10 229' \
-        'PATH=/sbin:/usr/sbin:$PATH apt-get -y --no-install-recommends build-dep ./; \
-         dpkg-buildpackage -uc -us -b' \
+        --build-command 'PATH=/sbin:/usr/sbin:$PATH apt-get -y --no-install-recommends build-dep ./; \
+                         dpkg-buildpackage -uc -us -b' \
+        . \
         '../*.deb' \
         -- \
         schroot unstable-amd64-sbuild
@@ -95,12 +92,12 @@ reprotest needs in order to make the variations in the first place. This
 should be the same regardless of what package is being built, but might
 differ depending on what virtual\_server is being used.
 
-Next, we have the build\_command. For our Debian directory, we install
-build-dependencies using apt-get, then we run the actual build command
-itself using dpkg-buildpackage(1).
+Next, we have ``--build-command`` (or ``-c``). For our Debian directory, we
+install build-dependencies using ``apt-get``, then we run the actual build
+command itself using ``dpkg-buildpackage(1)``.
 
-Then, we have the artifact pattern. For reproducibility, we're only
-interested in the binary packages.
+Then, we have the ``source_root`` and the ``artifact_pattern``. For
+reproducibility, we're only interested in the binary packages.
 
 Finally, we specify that this is to take place in the "schroot"
 virtual\_server with arguments "unstable-amd64-sbuild".
@@ -112,16 +109,14 @@ be good.
 Here is a more complex example. It tells reprotest to store the build products
 into ``./artifacts`` to analyse later; and also tweaks the "Debian dsc" preset
 so that it uses our `experimental toolchain
-<https://wiki.debian.org/ReproducibleBuilds/ExperimentalToolchain>`__.
-
-::
+<https://wiki.debian.org/ReproducibleBuilds/ExperimentalToolchain>`__::
 
     $ reprotest --store-dir=artifacts \
         --auto-preset-expr '_.prepend.testbed_init("apt-get install -y wget 2>/dev/null; \
             echo deb http://reproducible.alioth.debian.org/debian/ ./ >> /etc/apt/sources.list; \
             wget -q -O- https://reproducible.alioth.debian.org/reproducible.asc | apt-key add -; \
             apt-get update; apt-get upgrade -y 2>/dev/null; ")' \
-        auto ./bash_4.4-4.0~reproducible1.dsc \
+        ./bash_4.4-4.0~reproducible1.dsc \
         -- \
         schroot unstable-amd64-sbuild
 
@@ -146,9 +141,7 @@ Reprotest by default does not load any config file. You can tell it to load one
 with the ``--config-file`` or ``-f`` command line options. If you give it a
 directory such as ``.``, it will load ``.reprotestrc`` within that directory.
 
-A sample config file is below.
-
-::
+A sample config file is below::
 
     [basics]
     verbosity = 1
diff --git a/debian/NEWS b/debian/NEWS
index 7419f9d..b32ca83 100644
--- a/debian/NEWS
+++ b/debian/NEWS
@@ -1,7 +1,8 @@
 reprotest (0.7) UNRELEASED; urgency=medium
 
   BACKWARDS INCOMPATIBLE CHANGES:
-  * The reprotest config file (-f <FILE>) no longer supports the
-    build_command, artifact, or virtual_server_args keys.
+  * The reprotest config file (-f <FILE>) no longer supports the artifact or
+    virtual_server_args keys. The build_command key is now only supported if
+    there is no source_root key at the same time.
 
  -- Ximin Luo <infinity0 at debian.org>  Thu, 31 Aug 2017 18:38:47 +0200
diff --git a/debian/TODO b/debian/TODO
index 48276d4..3d12054 100644
--- a/debian/TODO
+++ b/debian/TODO
@@ -1,19 +1,8 @@
 Make the CLI nicer
 ==================
 
-Current:
-reprotest [options] --source-root <source_file_or_dir>   <build_command>      [<artifact>]
-reprotest [options]                                      auto                 [<artifact>]
-reprotest [options]                                      auto                  <source_file_or_dir>  # if the given artifact already exists
-
-Add:
-(if the given build_command already exists)
-reprotest [options] --build-command <build_command>      <source_file_or_dir> [<artifact>]
-reprotest [options]                                      <source_file_or_dir> [<artifact>]
-
-After this, we can add a "auto-sbuild" pseudo-command that selects sbuild to
-build .dsc files (and guess the command artefact output), this should help with
-#847805.
+Add a "auto-sbuild" pseudo-command that selects sbuild to build .dsc files (and
+guess the command artifact output), this should help with #847805.
 
 Refactoring
 ===========
diff --git a/doc/reprotest.h2m.0 b/doc/reprotest.h2m.0
index a01e2e5..286dd85 100644
--- a/doc/reprotest.h2m.0
+++ b/doc/reprotest.h2m.0
@@ -3,10 +3,10 @@ reprotest \- Build packages and check them for reproducibility.
 [SYNOPSIS]
 .nf
 \fBreprotest\fR \-\-help\ [<virtual_server_name>]
-\fBreprotest\fR [options] \fIauto\fR  <source_file_or_dir> [[more options] --|--] \
-[<virtual_server_args> [<virtual_server_args> ...]]
-\fBreprotest\fR [options] <build_command> <artifact> [[more options] --|--] \
-[<virtual_server_args> [<virtual_server_args> ...]]
+\fBreprotest\fR [options] [\-c <build_command>] <source_root> [<artifact_pattern>] \
+[-- <virtual_server_args> [<virtual_server_args> ...]]
+\fBreprotest\fR [options] [\-s <source_root>] <build_command> [<artifact_pattern>] \
+[-- <virtual_server_args> [<virtual_server_args> ...]]
 .fi
 [<DESCRIPTION]
 .B reprotest
diff --git a/reprotest/__init__.py b/reprotest/__init__.py
index c495ff1..a87fe1d 100644
--- a/reprotest/__init__.py
+++ b/reprotest/__init__.py
@@ -451,6 +451,8 @@ def check(build_command, artifact_pattern, virtual_server_args, source_root,
     # default argument [] is safe here because we never mutate it.
     if not source_root:
         raise ValueError("invalid source root: %s" % source_root)
+    if os.path.isfile(source_root):
+        source_root = os.path.normpath(os.path.dirname(source_root))
     if store_dir:
         store_dir = str(store_dir)
         if not os.path.exists(store_dir):
@@ -583,27 +585,31 @@ def cli_parser():
     parser = argparse.ArgumentParser(
         prog='reprotest',
         usage='''%(prog)s --help [<virtual_server_name>]
-       %(prog)s [options] auto  <source_file_or_dir> [[more options] --|--]
-                 [<virtual_server_args> [<virtual_server_args> ...]]
-       %(prog)s [options] <build_command> <artifact> [[more options] --|--]
-                 [<virtual_server_args> [<virtual_server_args> ...]]''',
+       %(prog)s [options] [-c <build-command>] <source_root> [<artifact_pattern>]
+                 [-- <virtual_server_args> [<virtual_server_args> ...]]
+       %(prog)s [options] [-s <source_root>] <build_command> [<artifact_pattern>]
+                 [-- <virtual_server_args> [<virtual_server_args> ...]]''',
         description='Build packages and check them for reproducibility.',
         formatter_class=argparse.RawDescriptionHelpFormatter, add_help=False)
 
-    parser.add_argument('build_command', default=None, nargs='?',
-        help='Build command to execute, or "auto" to guess this. In '
-        'the latter case, the next argument \'artifact\' will not be '
-        'interpreted that way but instead as the source to build, '
-        'e.g. "." or some other path.'),
-    parser.add_argument('artifact', default=None, nargs= '?',
+    parser.add_argument('source_root|build_command', default=None, nargs='?',
+        help='The first argument is treated either as a source_root (see the '
+        '-s option) or as a build-command (see the -c option) depending on '
+        'some heuristics. Specifically: if neither -c nor -s are given, then: '
+        'if this exists as a file or directory and is not "auto", then this is '
+        'treated as a source_root, else as a build_command. Otherwise, if one '
+        'of -c or -s is given, then this is treated as the other one. If both '
+        'are given, then this is a command-line syntax error and we exit code 2.'),
+    parser.add_argument('artifact', default=None, nargs='?',
         help='Build artifact to test for reproducibility. May be a shell '
              'pattern such as "*.deb *.changes".'),
-    parser.add_argument('virtual_server_args', default=None, nargs= '*',
+    parser.add_argument('virtual_server_args', default=None, nargs='*',
         help='Arguments to pass to the virtual_server, the first argument '
              'being the name of the server. If this itself contains options '
-             '(of the form -xxx or --xxx) you should put a "--" between '
-             'these arguments and reprotest\'s own options. '
-             'Default: "null", to run directly in /tmp. Choices: %s' %
+             '(of the form -xxx or --xxx), or if any of the previous arguments '
+             'are omitted, you should put a "--" between these arguments and '
+             'reprotest\'s own options. Default: "null", to run directly in '
+             '/tmp. Choices: %s' %
              ''.join(get_all_servers()))
 
     parser.add_argument('--help', default=None, const=True, nargs='?',
@@ -618,9 +624,15 @@ def cli_parser():
         help='An integer.  Control which messages are displayed.')
     group1.add_argument('--host-distro', default='debian',
         help='The distribution that will run the tests (Default: %(default)s)')
-    group1.add_argument('--source-root',
-        type=pathlib.Path, default=pathlib.Path.cwd(),
-        help='Root of the source tree. Default: current working directory.')
+    group1.add_argument('-s', '--source-root', default=None,
+        help='Root of the source tree, that is copied to the virtual server '
+        'and made available during the build. If a file is given here, then '
+        'all files in its parent directory are available during the build. '
+        'Default: "." (current working directory).')
+    group1.add_argument('-c', '--build-command', default=None,
+        help='Build command to execute. If this is "auto" then reprotest will '
+        'guess how to build the given source_root, in which case various other '
+        'options may be automatically set-if-unset. Default: auto'),
     group1.add_argument('--store-dir', default=None, type=pathlib.Path,
         help='Save the artifacts in this directory, which must be empty or '
         'non-existent. Otherwise, the artifacts will be deleted and you only '
@@ -668,24 +680,39 @@ def cli_parser():
         help='Don\'t clean the virtual_server if there was an error. '
         'Useful for debugging, but WARNING: this is currently not '
         'implemented very well and may leave cruft on your system.')
+    group3.add_argument('--dry-run', action='store_true', default=False,
+        help='Don\'t run the builds, just print what would happen.')
 
     return parser
 
 
-def command_line(parser, *argv):
-    args, remainder = parser.parse_known_args(*argv)
+def command_line(parser, argv):
+    # parse_known_args does not exactly do what we want - we want everything
+    # after '--' to belong to virtual_server_args, but parse_known_args instead
+    # treats them as any positional argument (e.g. ones that go before
+    # virtual_server_args). so, work around that here.
+    if '--' in argv:
+        idx = argv.index('--')
+        postargv = argv[idx:]
+        argv = argv[:idx]
+    else:
+        postargv = []
+
     # work around python issue 14191; this allows us to accept command lines like
     # $ reprotest build stuff --option=val --option=val -- schroot unstable-amd64-sbuild
     # where optional args appear in between positional args, but there must be a '--'
+    args, remainder = parser.parse_known_args(argv)
+    remainder += postargv
+
     if remainder:
         if remainder[0] != '--':
             # however we disallow split command lines that don't have '--', e.g.:
             # $ reprotest build stuff --option=val --option=val schroot unstable-amd64-sbuild
             # since it's too complex to support that in a way that's not counter-intuitive
-            parser.parse_args(*argv)
+            parser.parse_args(argv)
+            assert False # previous function should have raised an error
         args.virtual_server_args = (args.virtual_server_args or []) + remainder[1:]
     args.virtual_server_args = args.virtual_server_args or ["null"]
-    # print(args)
 
     if args.help:
         if args.help:
@@ -697,70 +724,105 @@ def command_line(parser, *argv):
     return args
 
 
-def main():
+def run(argv, check):
     # Argparse exits with status code 2 if something goes wrong, which
     # is already the right status exit code for reprotest.
     parser = cli_parser()
-    parsed_args = command_line(parser, sys.argv[1:])
+    parsed_args = command_line(parser, argv)
     config_args = config_to_args(parser, parsed_args.config_file)
     # Command-line arguments override config file settings.
-    parsed_args = command_line(parser, config_args + sys.argv[1:])
-
-    build_command = parsed_args.build_command
-    artifact = parsed_args.artifact
-    virtual_server_args = parsed_args.virtual_server_args
-    host_distro = parsed_args.host_distro
-
-    # Reprotest will copy this tree and then run the build command.
-    # If a source root isn't provided, assume it's the current working
-    # directory.
-    source_root = str(parsed_args.source_root)
-    no_clean_on_error = parsed_args.no_clean_on_error
-    diffoscope_args = parsed_args.diffoscope_arg
-    if parsed_args.no_diffoscope:
-        diffoscope_args = None
+    parsed_args = command_line(parser, config_args + argv)
 
     verbosity = parsed_args.verbosity
     adtlog.verbosity = verbosity
-
-    variations = parsed_args.variations - parsed_args.dont_vary
-    _ = VariationContext.default()
-    _ = _._replace(verbosity=verbosity)
-    _ = _._replace(user_groups=_.user_groups | parsed_args.user_groups)
-    variation_context = _
-
-    if not build_command:
-        print("No build command provided. See --help for options.")
-        sys.exit(2)
-    if not artifact:
-        print("No build artifact to test for differences provided.")
-        sys.exit(2)
-    if not virtual_server_args:
-        print("No virtual_server to run the build in specified.")
-        sys.exit(2)
     logging.basicConfig(
         format='%(message)s', level=30-10*verbosity, stream=sys.stdout)
     logging.debug('%r', parsed_args)
 
-    store_dir = parsed_args.store_dir
+    # Decide which form of the CLI we're using
+    build_command, source_root = None, None
+    first_arg = parsed_args.__dict__['source_root|build_command']
+    if parsed_args.build_command:
+        if parsed_args.source_root:
+            print("Both -c and -s were given; abort")
+            sys.exit(2)
+        else:
+            source_root = first_arg
+    else:
+        if parsed_args.source_root:
+            build_command = first_arg
+        elif not first_arg:
+            print("No <source_root> or <build_command> provided. See --help for options.")
+            sys.exit(2)
+        elif first_arg == "auto":
+            build_command = first_arg
+            if parsed_args.artifact:
+                logging.warn("old CLI form `reprotest auto <source_root>` detected, "
+                    "setting source_root to the second argument: %s", parsed_args.artifact)
+                logging.warn("to avoid this warning, use instead `reprotest <source_root>` "
+                    "or (if really necessary) `reprotest -s <source_root> auto <artifact>`")
+                source_root = parsed_args.artifact
+                parsed_args.artifact = None
+        elif os.path.exists(first_arg):
+            source_root = first_arg
+        else:
+            build_command = first_arg
+    build_command = build_command or parsed_args.build_command or "auto"
+    source_root = source_root or parsed_args.source_root or '.'
+
+    # Args that might be affected by presets
+    virtual_server_args = parsed_args.virtual_server_args
+    artifact_pattern = parsed_args.artifact
     testbed_pre = parsed_args.testbed_pre
     testbed_init = parsed_args.testbed_init
+    diffoscope_args = parsed_args.diffoscope_arg
 
+    # Do presets
     if build_command == 'auto':
-        source_root = os.path.normpath(os.path.dirname(artifact)) if os.path.isfile(artifact) else artifact
         auto_preset_expr = parsed_args.auto_preset_expr
-        values = presets.get_presets(artifact, virtual_server_args[0])
-        values = eval(auto_preset_expr, {'_':values}, {})
+        values = presets.get_presets(source_root, virtual_server_args[0])
+        values = eval(auto_preset_expr, {'_': values}, {})
         logging.info("preset auto-selected: %r", values)
         build_command = values.build_command
-        artifact = values.artifact
-        testbed_pre = values.testbed_pre
-        testbed_init = values.testbed_init
+        artifact_pattern = artifact_pattern or values.artifact
+        testbed_pre = testbed_pre or values.testbed_pre
+        testbed_init = testbed_init or values.testbed_init
         if diffoscope_args is not None:
             diffoscope_args = values.diffoscope_args + diffoscope_args
 
-    # print(build_command, artifact, virtual_server_args)
-    return check(build_command, artifact, virtual_server_args, source_root,
-                 no_clean_on_error, store_dir, diffoscope_args,
-                 variations, variation_context,
-                 testbed_pre, testbed_init, host_distro)
+    # Variations args
+    variations = parsed_args.variations - parsed_args.dont_vary
+    _ = VariationContext.default()
+    _ = _._replace(verbosity=verbosity)
+    _ = _._replace(user_groups=_.user_groups | parsed_args.user_groups)
+    variation_context = _
+
+    # Remaining args
+    host_distro = parsed_args.host_distro
+    store_dir = parsed_args.store_dir
+    no_clean_on_error = parsed_args.no_clean_on_error
+    if parsed_args.no_diffoscope:
+        diffoscope_args = None
+
+    if not artifact_pattern:
+        print("No <artifact> to test for differences provided. See --help for options.")
+        sys.exit(2)
+
+    check_args_keys = (
+        "build_command", "artifact_pattern", "virtual_server_args", "source_root",
+        "no_clean_on_error", "store_dir", "diffoscope_args",
+        "variations", "variation_context",
+        "testbed_pre", "testbed_init", "host_distro")
+    l = locals()
+    check_args = collections.OrderedDict([(k, l[k]) for k in check_args_keys])
+    if parsed_args.dry_run:
+        return check_args
+    else:
+        return check(**check_args)
+
+def main():
+    r = run(sys.argv[1:], check)
+    if isinstance(r, collections.OrderedDict):
+        print("check(%s)" % ", ".join("%s=%r" % (k, v) for k, v in r.items()))
+    else:
+        return r
diff --git a/reprotest/presets.py b/reprotest/presets.py
index 1a8c703..a3f5fdc 100644
--- a/reprotest/presets.py
+++ b/reprotest/presets.py
@@ -92,4 +92,5 @@ def get_presets(buildfile, virtual_server):
                 return preset_deb_dsc(fn)
             else:
                 return preset_deb_schroot(preset_deb_dsc(fn))
-    raise ValueError("unrecognised file type: %s" % buildfile)
+    raise ValueError('unrecognised file type: "%s"; try giving '
+                     'an appropriate --build-command' % buildfile)
diff --git a/tests/tests.py b/tests/tests.py
index c453185..480b721 100755
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -28,6 +28,20 @@ def check_return_code(command, virtual_server, code):
         else:
             assert(retcode in code)
 
+def check_command_line(command_line, code=None):
+    try:
+        retcode = 0
+        return reprotest.run(command_line, lambda **x: x)
+    except SystemExit as system_exit:
+        retcode = system_exit.args[0]
+    finally:
+        if code is None:
+            assert(retcode == 0)
+        elif isinstance(code, int):
+            assert(retcode == code)
+        else:
+            assert(retcode in code)
+
 @pytest.fixture(scope='module', params=REPROTEST_TEST_SERVERS)
 def virtual_server(request):
     if request.param == 'null':
@@ -59,6 +73,36 @@ def test_self_build(virtual_server):
     assert(1 == subprocess.call(REPROTEST + ['python3 setup.py sdist; sleep 2', 'dist/*.tar.gz'] + virtual_server))
     assert(1 == subprocess.call(REPROTEST + ['python3 setup.py bdist_wheel', 'dist/*.whl'] + virtual_server))
 
+def test_command_lines():
+    r = check_command_line(".".split(), 0)
+    assert r['artifact_pattern'] is not None
+    r = check_command_line(". -- null -d".split(), 0)
+    assert r['artifact_pattern'] is not None
+    check_command_line("--dry-run . --verbosity 2 -- null -d".split(), 0)
+    assert r['artifact_pattern'] is not None
+    check_command_line(". null -d".split(), 2)
+    check_command_line(". --verbosity 2 null -d".split(), 2)
+    check_command_line("--dry-run . --verbosity 2 null -d".split(), 2)
+    check_command_line("--dry-run . null -d".split(), 2)
+
+    r = check_command_line("auto".split(), 0)
+    assert r['artifact_pattern'] is not None
+    r = check_command_line("auto -- null -d".split(), 0)
+    assert r['artifact_pattern'] is not None
+    check_command_line("--dry-run auto --verbosity 2 -- null -d".split(), 0)
+    assert r['artifact_pattern'] is not None
+    check_command_line("auto null -d".split(), 2)
+    check_command_line("auto --verbosity 2 null -d".split(), 2)
+    check_command_line("--dry-run auto --verbosity 2 null -d".split(), 2)
+    check_command_line("--dry-run auto null -d".split(), 2)
+
+    r = check_command_line("auto -- schroot unstable-amd64-sbuild".split(), 0)
+    assert r['virtual_server_args'] == ['schroot', 'unstable-amd64-sbuild']
+    r = check_command_line(". -- schroot unstable-amd64-sbuild".split(), 0)
+    assert r['virtual_server_args'] == ['schroot', 'unstable-amd64-sbuild']
+    r = check_command_line("auto . schroot unstable-amd64-sbuild".split(), 0)
+    assert r['virtual_server_args'] == ['schroot', 'unstable-amd64-sbuild']
+
 # TODO: don't call it if we don't have debian/, e.g. for other distros
 def test_debian_build(virtual_server):
     # This is a bit dirty though it works - when building the debian package,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/reprotest.git



More information about the Reproducible-commits mailing list