Bug 1311991 - Add a basic cramtest mach command, r=gps
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 20 Jan 2017 11:15:25 -0500
changeset 375715 2758400034173a86bc52590ec36eda353a03718e
parent 375714 eeca48a18e59f7e9f13428b51af35a35467666f4
child 375716 a7d586922755362c6ea6b2ad2049625d49af254f
push id32361
push userphilringnalda@gmail.com
push dateSat, 19 Aug 2017 22:28:34 +0000
treeherdermozilla-central@c40774ced661 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs1311991
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1311991 - Add a basic cramtest mach command, r=gps This is a pretty bad runner. My goal for now is to get something really basic working and then improve it over time as more tests get added. Run tests with: ./mach cramtest path/to/dir Any extra args will be forwarded to the cram binary, e.g: ./mach cramtest -i path/to/dir Cram help can be seen with: ./mach python -m cram -- -h MozReview-Commit-ID: 67jYHfYQjWu
testing/mach_commands.py
--- a/testing/mach_commands.py
+++ b/testing/mach_commands.py
@@ -1,16 +1,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import argparse
 import json
+import logging
 import os
 import sys
 import tempfile
 import subprocess
 import shutil
 
 from mach.decorators import (
     CommandArgument,
@@ -506,16 +507,55 @@ class JsapiTestsCommand(MachCommandBase)
         if params['test_name']:
             jsapi_tests_cmd.append(params['test_name'])
 
         jsapi_tests_result = subprocess.call(jsapi_tests_cmd)
 
         return jsapi_tests_result
 
 
+@CommandProvider
+class CramTest(MachCommandBase):
+    @Command('cramtest', category='testing',
+             description="Mercurial style .t tests for command line applications.")
+    @CommandArgument('test_paths', nargs='*', metavar='N',
+                     help="Test paths to run. Each path can be a test file or directory. "
+                          "If omitted, the entire suite will be run.")
+    @CommandArgument('cram_args', nargs=argparse.REMAINDER,
+                     help="Extra arguments to pass down to the cram binary. See "
+                          "'./mach python -m cram -- -h' for a list of available options.")
+    def cramtest(self, cram_args=None, test_paths=None, test_objects=None):
+        self._activate_virtualenv()
+        import mozinfo
+        from manifestparser import TestManifest
+
+        if test_objects is None:
+            from mozbuild.testing import TestResolver
+            resolver = self._spawn(TestResolver)
+            if test_paths:
+                # If we were given test paths, try to find tests matching them.
+                test_objects = resolver.resolve_tests(paths=test_paths, flavor='cram')
+            else:
+                # Otherwise just run everything in CRAMTEST_MANIFESTS
+                test_objects = resolver.resolve_tests(flavor='cram')
+
+        if not test_objects:
+            message = 'No tests were collected, check spelling of the test paths.'
+            self.log(logging.WARN, 'cramtest', {}, message)
+            return 1
+
+        mp = TestManifest()
+        mp.tests.extend(test_objects)
+        tests = mp.active_tests(disabled=False, **mozinfo.info)
+
+        python = self.virtualenv_manager.python_path
+        cmd = [python, '-m', 'cram'] + cram_args + [t['relpath'] for t in tests]
+        return subprocess.call(cmd, cwd=self.topsrcdir)
+
+
 def get_parser(argv=None):
     parser = ArgumentParser()
     parser.add_argument(dest="suite_name",
                         nargs=1,
                         choices=['mochitest'],
                         type=str,
                         help="The test for which chunk should be found. It corresponds "
                              "to the mach test invoked (only 'mochitest' currently).")