Use warning code in xkeyboard-config test
[platform/upstream/libxkbcommon.git] / test / xkeyboard-config-test.py.in
index 222f8c5..77cff1f 100755 (executable)
@@ -23,7 +23,7 @@ def escape(s):
 
 # The function generating the progress bar (if any).
 def create_progress_bar(verbose):
-    def noop_progress_bar(x, total):
+    def noop_progress_bar(x, total, file=None):
         return x
 
     progress_bar = noop_progress_bar
@@ -112,6 +112,8 @@ class XkbCompInvocation(Invocation):
 
 
 class XkbcommonInvocation(Invocation):
+    UNRECOGNIZED_KEYSYM_ERROR = "XKB-107"
+
     def run(self):
         r, m, l, v, o = self.rmlvo
         args = [
@@ -130,9 +132,9 @@ class XkbcommonInvocation(Invocation):
         try:
             output = subprocess.check_output(args, stderr=subprocess.STDOUT,
                                              universal_newlines=True)
-            if "unrecognized keysym" in output:
+            if self.UNRECOGNIZED_KEYSYM_ERROR in output:
                 for line in output.split('\n'):
-                    if "unrecognized keysym" in line:
+                    if self.UNRECOGNIZED_KEYSYM_ERROR in line:
                         self.error = line
                 self.exitstatus = 99  # tool doesn't generate this one
             else:
@@ -211,7 +213,7 @@ def run(combos, tool, njobs, keymap_output_dir):
     failed = False
     with multiprocessing.Pool(njobs) as p:
         results = p.imap_unordered(tool, combos)
-        for invocation in progress_bar(results, total=len(combos)):
+        for invocation in progress_bar(results, total=len(combos), file=sys.stdout):
             if invocation.exitstatus != 0:
                 failed = True
                 target = sys.stderr
@@ -252,7 +254,12 @@ def main(args):
     }
 
     parser = argparse.ArgumentParser(
-        description='Tool to test all layout/variant/option combinations.'
+        description='''
+                    This tool compiles a keymap for each layout, variant and
+                    options combination in the given rules XML file. The output
+                    of this tool is YAML, use your favorite YAML parser to
+                    extract error messages. Errors are printed to stderr.
+                    '''
     )
     parser.add_argument('path', metavar='/path/to/evdev.xml',
                         nargs='?', type=str,
@@ -267,6 +274,13 @@ def main(args):
     parser.add_argument('--verbose', '-v', default=False, action="store_true")
     parser.add_argument('--keymap-output-dir', default=None, type=str,
                         help='Directory to print compiled keymaps to')
+    parser.add_argument('--layout', default=None, type=str,
+                        help='Only test the given layout')
+    parser.add_argument('--variant', default=None, type=str,
+                        help='Only test the given variant')
+    parser.add_argument('--option', default=None, type=str,
+                        help='Only test the given option')
+
     args = parser.parse_args()
 
     verbose = args.verbose
@@ -275,7 +289,14 @@ def main(args):
 
     tool = tools[args.tool]
 
-    combos = parse(args.path)
+    if any([args.layout, args.variant, args.option]):
+        combos = [{
+            'l': args.layout,
+            'v': args.variant,
+            'o': args.option,
+        }]
+    else:
+        combos = parse(args.path)
     failed = run(combos, tool, args.jobs, keymapdir)
     sys.exit(failed)