From d35328b5061be5ba7b4a551a3b41af173025d4a9 Mon Sep 17 00:00:00 2001 From: "jlal@mozilla.com" Date: Mon, 8 Jun 2015 10:57:24 -0700 Subject: [PATCH] Bug 1136028 - Escape whitespace inside of platform filters r=garndt --HG-- extra : rebase_source : 8093174bd51c9d677e8dc29bcd499ffa71d38fbc --- .../taskcluster_graph/commit_parser.py | 30 ++++++++++++++++++- .../taskcluster/tests/test_commit_parser.py | 5 ++-- .../taskcluster/tests/test_try_test_parser.py | 6 +++- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/testing/taskcluster/taskcluster_graph/commit_parser.py b/testing/taskcluster/taskcluster_graph/commit_parser.py index 9fb6322cc512..acca47239716 100644 --- a/testing/taskcluster/taskcluster_graph/commit_parser.py +++ b/testing/taskcluster/taskcluster_graph/commit_parser.py @@ -23,6 +23,34 @@ BUILD_TYPE_ALIASES = { class InvalidCommitException(Exception): pass +def escape_whitspace_in_brackets(input_str): + ''' + In tests you may restrict them by platform [] inside of the brackets + whitespace may occur this is typically invalid shell syntax so we escape it + with backslash sequences . + ''' + result = "" + in_brackets = False + for char in input_str: + if char == '[': + in_brackets = True + result += char + continue + + if char == ']': + in_brackets = False + result += char + continue + + if char == ' ' and in_brackets: + result += '\ ' + continue + + result += char + + return result + + def normalize_platform_list(alias, all_builds, build_list): if build_list == 'all': return all_builds @@ -178,7 +206,7 @@ def parse_commit(message, jobs): ''' # shlex used to ensure we split correctly when giving values to argparse. - parts = shlex.split(message) + parts = shlex.split(escape_whitspace_in_brackets(message)) try_idx = None for idx, part in enumerate(parts): if part == TRY_DELIMITER: diff --git a/testing/taskcluster/tests/test_commit_parser.py b/testing/taskcluster/tests/test_commit_parser.py index 23d3fb51e64d..b934b7f21eec 100755 --- a/testing/taskcluster/tests/test_commit_parser.py +++ b/testing/taskcluster/tests/test_commit_parser.py @@ -260,8 +260,9 @@ class TestCommitParser(unittest.TestCase): def test_specific_test_platforms(self): ''' This test cases covers the platform specific test exclusion options. + Intentionally includes platforms with spaces. ''' - commit = 'try: -b od -p all -u all[windows,b2g] -t none' + commit = 'try: -b od -p all -u all[Windows XP,b2g] -t none' jobs = { 'flags': { 'builds': ['linux', 'win32'], @@ -279,7 +280,7 @@ class TestCommitParser(unittest.TestCase): } }, 'win32': { - 'platforms': ['windows'], + 'platforms': ['Windows XP'], 'types': { 'opt': { 'task': 'task/win32', diff --git a/testing/taskcluster/tests/test_try_test_parser.py b/testing/taskcluster/tests/test_try_test_parser.py index 0caeb81531b0..528412cbdd17 100755 --- a/testing/taskcluster/tests/test_try_test_parser.py +++ b/testing/taskcluster/tests/test_try_test_parser.py @@ -5,6 +5,11 @@ from taskcluster_graph.try_test_parser import parse_test_opts class TryTestParserTest(unittest.TestCase): def test_parse_opts_valid(self): + self.assertEquals( + parse_test_opts('all[Mulet Linux]'), + [{ 'test': 'all', 'platforms': ['Mulet Linux'] }] + ) + self.assertEquals( parse_test_opts('all[Amazing, Foobar woot,yeah]'), [{ 'test': 'all', 'platforms': ['Amazing', 'Foobar woot', 'yeah'] }] @@ -48,4 +53,3 @@ class TryTestParserTest(unittest.TestCase): if __name__ == '__main__': mozunit.main() -