Add a basic cramtest runner draft
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Fri, 20 Jan 2017 11:15:25 -0500
changeset 470456 a331fd0135a6d53370059da0501eee65a2eeac88
parent 470455 c318da6eafabf5f6a09d27b2e63ec59919c4331e
child 470457 80a82ba136538d231071d7e703f517d3fb0afc33
push id44031
push userahalberstadt@mozilla.com
push dateFri, 03 Feb 2017 19:02:40 +0000
milestone54.0a1
Add a basic cramtest runner MozReview-Commit-ID: 67jYHfYQjWu
testing/mach_commands.py
--- a/testing/mach_commands.py
+++ b/testing/mach_commands.py
@@ -1,15 +1,16 @@
 # 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 json
+import logging
 import os
 import sys
 import tempfile
 import subprocess
 import shutil
 from collections import defaultdict
 
 from mach.decorators import (
@@ -464,16 +465,17 @@ class CheckSpiderMonkeyCommand(MachComma
         print('running check-js-msg-encoding')
         check_js_msg_cmd = [sys.executable, os.path.join(self.topsrcdir, 'config', 'check_js_msg_encoding.py')]
         check_js_msg_result = subprocess.call(check_js_msg_cmd, cwd=self.topsrcdir)
 
         all_passed = jittest_result and jstest_result and jsapi_tests_result and check_style_result and check_masm_result and check_js_msg_result
 
         return all_passed
 
+
 @CommandProvider
 class JsapiTestsCommand(MachCommandBase):
     @Command('jsapi-tests', category='testing', description='Run jsapi tests (JavaScript engine).')
     @CommandArgument('test_name', nargs='?', metavar='N',
         help='Test to run. Can be a prefix or omitted. If omitted, the entire ' \
              'test suite is executed.')
 
     def run_jsapitests(self, **params):
@@ -487,16 +489,62 @@ class JsapiTestsCommand(MachCommandBase)
         jsapi_tests_cmd = [os.path.join(self.bindir, executable_name('jsapi-tests'))]
         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.")
+    def cramtest(self, test_paths=None, test_objects=None):
+        self._activate_virtualenv()
+        import mozinfo
+        from manifestparser import TestManifest
+        from mozprocess import ProcessHandler
+
+        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)
+
+        def _line_handler(line):
+            self.log(logging.INFO, 'cramtest', {'line': line.rstrip()}, '{line}')
+
+        basecmd = ['cram']
+        status = 0
+        for test in tests:
+            cmd = basecmd + [test['path']]
+            proc = ProcessHandler(cmd, processOutputLine=_line_handler)
+            proc.run()
+            status = proc.wait() or status
+        return status
+
+
 def autotry_parser():
     from autotry import arg_parser
     return arg_parser()
 
 @CommandProvider
 class PushToTry(MachCommandBase):
     def normalise_list(self, items, allow_subitems=False):
         from autotry import parse_arg