This is an archive of the discontinued LLVM Phabricator instance.

[tools] Update update_test_prefix.py to handle %s after prefixes
ClosedPublic

Authored by mtrofin on Dec 2 2020, 9:38 PM.

Details

Summary

Sometimes the check-prefixes is followed by %s, and we want to keep a
white space before it.

Diff Detail

Event Timeline

mtrofin created this revision.Dec 2 2020, 9:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 2 2020, 9:38 PM
pengfei added inline comments.Dec 2 2020, 10:55 PM
llvm/utils/update_test_prefix.py
21

I checked it and find it didn't work. It seems \w in [] loses its function.
I also think the * after [\s] (you can use \s without []) is problematical for --check-prefixes=A,B. Besides, changing to + is still problematical for it may consume extera blank lines.
It's hard to modify regular expression correctly without lots of checks, I think you can use my previous patch as a test:

git reset --hard c22dc71b120b066c0066b8517014149a001cc2b0^1
git show c22dc71b120b066c0066b8517014149a001cc2b0 --stat | grep "llvm/test" | cut -d " " -f 2 | xargs llvm/utils/update_test_prefix.py

Check if the outputs are identical to the patch.

mtrofin updated this revision to Diff 309272.Dec 3 2020, 8:54 AM

removed space

mtrofin marked an inline comment as done.Dec 3 2020, 9:02 AM
mtrofin added inline comments.
llvm/utils/update_test_prefix.py
21

The problem seems to have been a spurious space. I tried small unittests, like this:

import re

test = ['-check-prefixes=abc123', '-check-prefixes=abc123-def', '-check-prefixes=abc %s', """-check-prefixes=abc
        def""", '-check-prefixes=abc,def', '-check-prefixes=abc,def %s']

for t in test:
  print(t, re.sub('-?-check-prefixes=([\w-]+[\s]*)', '--check-prefix=\\1', t))
$ python test.py
('-check-prefixes=abc123', '--check-prefix=abc123')
('-check-prefixes=abc123-def', '--check-prefix=abc123-def')
('-check-prefixes=abc %s', '--check-prefix=abc %s')
('-check-prefixes=abc\n        def', '--check-prefix=abc\n        def')
('-check-prefixes=abc,def', '--check-prefix=abc,def')
('-check-prefixes=abc,def %s', '--check-prefix=abc,def %s')
pengfei added inline comments.Dec 3 2020, 5:21 PM
llvm/utils/update_test_prefix.py
21

Ah, that's it. The unittest is awesome. But the last 2 test results are wrong. The expected results are:

('-check-prefixes=abc,def', '--check-prefixes=abc,def')
('-check-prefixes=abc,def %s', '--check-prefixes=abc,def %s')

We can remove the es when there is only one prefix. You can add one more test:

('-check-prefixes=abc\n\n        def', '--check-prefix=abc\n\n        def')

to see using + instead of * is also problematic.

mtrofin marked 2 inline comments as done.Dec 3 2020, 7:27 PM
mtrofin added inline comments.
llvm/utils/update_test_prefix.py
21

One more try:

print(t, re.sub('-?-check-prefixes=([\w-]+)(\Z|[ \t\n])', '--check-prefix=\\1\\2', t))

('-check-prefixes=abc123', '--check-prefix=abc123')
('-check-prefixes=abc123-def', '--check-prefix=abc123-def')
('-check-prefixes=abc %s', '--check-prefix=abc %s')
('-check-prefixes=abc\n        def', '--check-prefix=abc\n        def')
('-check-prefixes=abc,def', '-check-prefixes=abc,def')
('-check-prefixes=abc,def %s', '-check-prefixes=abc,def %s')
mtrofin marked an inline comment as done.Dec 3 2020, 7:32 PM
mtrofin added inline comments.
llvm/utils/update_test_prefix.py
21

oh, and (for the test you suggested)

('-check-prefixes=abc\n\n def', '--check-prefix=abc\n\n def')

pengfei added inline comments.Dec 3 2020, 7:58 PM
llvm/utils/update_test_prefix.py
21

It looks good to me. Thanks Mircea!
I know why you are using such expression now. I missed the cases 1, 2 which aren't end up with '\n' or space, there may exist such cases in real tests.

mtrofin updated this revision to Diff 309448.Dec 3 2020, 8:06 PM

updated with last regexp

mtrofin marked an inline comment as done.Dec 3 2020, 8:06 PM
This revision was not accepted when it landed; it landed in state Needs Review.Dec 3 2020, 8:11 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.