Skip to content

Commit 308fcdb

Browse files
authored
Fix other.test_argument_match with new clang error message. NFC (#19969)
As part of this I pushed support for the `regex` argument down into the lower level `assertContained` test method.
1 parent bb233ad commit 308fcdb

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

test/common.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,12 +1169,21 @@ def assertFileContents(self, filename, contents):
11691169
self.assertTextDataIdentical(expected_content, contents, message,
11701170
filename, filename + '.new')
11711171

1172-
def assertContained(self, values, string, additional_info=''):
1173-
if type(values) not in [list, tuple]:
1174-
values = [values]
1172+
def assertContained(self, values, string, additional_info='', regex=False):
11751173
if callable(string):
11761174
string = string()
11771175

1176+
if regex:
1177+
if type(values) == str:
1178+
self.assertTrue(re.search(values, string), 'Expected regex "%s" to match on:\n%s' % (values, string))
1179+
else:
1180+
match_any = any(re.search(o, string) for o in values)
1181+
self.assertTrue(match_any, 'Expected at least one of "%s" to match on:\n%s' % (values, string))
1182+
return
1183+
1184+
if type(values) not in [list, tuple]:
1185+
values = [values]
1186+
11781187
if not any(v in string for v in values):
11791188
diff = difflib.unified_diff(values[0].split('\n'), string.split('\n'), fromfile='expected', tofile='actual')
11801189
diff = ''.join(a.rstrip() + '\n' for a in diff)
@@ -1507,16 +1516,9 @@ def _build_and_run(self, filename, expected_output, args=None, output_nicerizer=
15071516
self.assertIdentical(expected_output, js_output)
15081517
elif assert_all or len(expected_output) == 1:
15091518
for o in expected_output:
1510-
if regex:
1511-
self.assertTrue(re.search(o, js_output), 'Expected regex "%s" to match on:\n%s' % (o, js_output))
1512-
else:
1513-
self.assertContained(o, js_output)
1519+
self.assertContained(o, js_output, regex=regex)
15141520
else:
1515-
if regex:
1516-
match_any = any(re.search(o, js_output) for o in expected_output)
1517-
self.assertTrue(match_any, 'Expected at least one of "%s" to match on:\n%s' % (expected_output, js_output))
1518-
else:
1519-
self.assertContained(expected_output, js_output)
1521+
self.assertContained(expected_output, js_output, regex=regex)
15201522
if assert_returncode == 0 and check_for_error:
15211523
self.assertNotContained('ERROR', js_output)
15221524
except Exception:

test/test_other.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11372,7 +11372,9 @@ def test_argument_match(self):
1137211372
# was matched
1137311373
self.run_process([EMCC, test_file('hello_world.c'), '--minify=0'])
1137411374
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--minifyXX'])
11375-
self.assertContained("error: unsupported option '--minifyXX'", err)
11375+
# The clang error message changed from 'unsupported' to 'unknown' so
11376+
# for now handle both options.
11377+
self.assertContained("clang: error: (unsupported option|unknown argument:) '--minifyXX'", err, regex=True)
1137611378

1137711379
def test_argument_missing(self):
1137811380
err = self.expect_fail([EMCC, test_file('hello_world.c'), '--minify'])

0 commit comments

Comments
 (0)