Skip to content

Commit 06c072f

Browse files
committed
Auto merge of #126788 - GuillaumeGomez:migrate-rustdoc-tests-syntax, r=fmease,oli-obk
Migrate rustdoc tests syntax to `//@` (for coherency) Part of #125813. cc `@jieyouxu` r? `@fmease` try-job: aarch64-apple
2 parents 2c243d9 + 6909fea commit 06c072f

631 files changed

Lines changed: 4702 additions & 4644 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/etc/htmldocck.py‎

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,37 @@ def concat_multi_lines(f):
240240
print_err(lineno, line, 'Trailing backslash at the end of the file')
241241

242242

243+
defget_known_directive_names():
244+
deffilter_line(line):
245+
line=line.strip()
246+
returnline.startswith('"') and (line.endswith('",') orline.endswith('"'))
247+
248+
# Equivalent to `src/tools/compiletest/src/header.rs` constant of the same name.
249+
withopen(
250+
os.path.join(
251+
# We go back to `src`.
252+
os.path.dirname(os.path.dirname(__file__)),
253+
"tools/compiletest/src/command-list.rs",
254+
),
255+
"r",
256+
encoding="utf8"
257+
) asfd:
258+
content=fd.read()
259+
return [
260+
line.strip().replace('",', '').replace('"', '')
261+
forlineincontent.split('\n')
262+
iffilter_line(line)
263+
]
264+
265+
266+
# To prevent duplicating the list of commmands between `compiletest` and `htmldocck`, we put
267+
# it into a common file which is included in rust code and parsed here.
268+
# FIXME: This setup is temporary until we figure out how to improve this situation.
269+
KNOWN_DIRECTIVE_NAMES=get_known_directive_names()
270+
243271
LINE_PATTERN=re.compile(r'''
244-
(?<=(?<!\S))(?P<invalid>!?)@(?P<negated>!?)
245-
(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
272+
//@\s+
273+
(?P<negated>!?)(?P<cmd>[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)
246274
(?P<args>.*)$
247275
''', re.X|re.UNICODE)
248276

@@ -254,17 +282,9 @@ def get_commands(template):
254282
ifnotm:
255283
continue
256284

257-
negated= (m.group('negated') =='!')
258285
cmd=m.group('cmd')
259-
ifm.group('invalid') =='!':
260-
print_err(
261-
lineno,
262-
line,
263-
'Invalid command: `!@{0}{1}`, (help: try with `@!{1}`)'.format(
264-
'!'ifnegatedelse'',
265-
cmd,
266-
),
267-
)
286+
negated= (m.group('negated') =='!')
287+
ifnotnegatedandcmdinKNOWN_DIRECTIVE_NAMES:
268288
continue
269289
args=m.group('args')
270290
ifargsandnotargs[:1].isspace():
@@ -549,7 +569,7 @@ def get_nb_matching_elements(cache, c, regexp, stop_at_first):
549569
defcheck_files_in_folder(c, cache, folder, files):
550570
files=files.strip()
551571
ifnotfiles.startswith('[') ornotfiles.endswith(']'):
552-
raiseInvalidCheck("Expected list as second argument of @{} (ie '[]')".format(c.cmd))
572+
raiseInvalidCheck("Expected list as second argument of {} (ie '[]')".format(c.cmd))
553573

554574
folder=cache.get_absolute_path(folder)
555575

@@ -558,7 +578,7 @@ def check_files_in_folder(c, cache, folder, files):
558578
files_set=set()
559579
forfileinfiles:
560580
iffileinfiles_set:
561-
raiseInvalidCheck("Duplicated file `{}` in @{}".format(file, c.cmd))
581+
raiseInvalidCheck("Duplicated file `{}` in {}".format(file, c.cmd))
562582
files_set.add(file)
563583
folder_set=set([fforfinos.listdir(folder) iff!="."andf!=".."])
564584

@@ -590,48 +610,48 @@ def check_command(c, cache):
590610
ifc.cmdin ['has', 'hasraw', 'matches', 'matchesraw']: # string test
591611
regexp=c.cmd.startswith('matches')
592612

593-
# @has <path> = file existence
613+
# has <path> = file existence
594614
iflen(c.args) ==1andnotregexpand'raw'notinc.cmd:
595615
try:
596616
cache.get_file(c.args[0])
597617
ret=True
598618
exceptFailedCheckaserr:
599619
cerr=str(err)
600620
ret=False
601-
# @hasraw/matchesraw <path> <pat> = string test
621+
# hasraw/matchesraw <path> <pat> = string test
602622
eliflen(c.args) ==2and'raw'inc.cmd:
603623
cerr="`PATTERN` did not match"
604624
ret=check_string(cache.get_file(c.args[0]), c.args[1], regexp)
605-
# @has/matches <path> <pat> <match> = XML tree test
625+
# has/matches <path> <pat> <match> = XML tree test
606626
eliflen(c.args) ==3and'raw'notinc.cmd:
607627
cerr="`XPATH PATTERN` did not match"
608628
ret=get_nb_matching_elements(cache, c, regexp, True) !=0
609629
else:
610-
raiseInvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
630+
raiseInvalidCheck('Invalid number of {} arguments'.format(c.cmd))
611631

612632
elifc.cmd=='files': # check files in given folder
613-
iflen(c.args) !=2: # @files <folder path> <file list>
614-
raiseInvalidCheck("Invalid number of @{} arguments".format(c.cmd))
633+
iflen(c.args) !=2: # files <folder path> <file list>
634+
raiseInvalidCheck("Invalid number of {} arguments".format(c.cmd))
615635
elifc.negated:
616-
raiseInvalidCheck("@{} doesn't support negative check".format(c.cmd))
636+
raiseInvalidCheck("{} doesn't support negative check".format(c.cmd))
617637
ret=check_files_in_folder(c, cache, c.args[0], c.args[1])
618638

619639
elifc.cmd=='count': # count test
620-
iflen(c.args) ==3: # @count <path> <pat> <count> = count test
640+
iflen(c.args) ==3: # count <path> <pat> <count> = count test
621641
expected=int(c.args[2])
622642
found=get_tree_count(cache.get_tree(c.args[0]), c.args[1])
623643
cerr="Expected {} occurrences but found {}".format(expected, found)
624644
ret=expected==found
625-
eliflen(c.args) ==4: # @count <path> <pat> <text> <count> = count test
645+
eliflen(c.args) ==4: # count <path> <pat> <text> <count> = count test
626646
expected=int(c.args[3])
627647
found=get_nb_matching_elements(cache, c, False, False)
628648
cerr="Expected {} occurrences but found {}".format(expected, found)
629649
ret=found==expected
630650
else:
631-
raiseInvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
651+
raiseInvalidCheck('Invalid number of {} arguments'.format(c.cmd))
632652

633653
elifc.cmd=='snapshot': # snapshot test
634-
iflen(c.args) ==3: # @snapshot <snapshot-name> <html-path> <xpath>
654+
iflen(c.args) ==3: # snapshot <snapshot-name> <html-path> <xpath>
635655
[snapshot_name, html_path, pattern] =c.args
636656
tree=cache.get_tree(html_path)
637657
xpath=normalize_xpath(pattern)
@@ -654,33 +674,33 @@ def check_command(c, cache):
654674
else:
655675
raiseFailedCheck('Expected 1 match, but found {}'.format(len(subtrees)))
656676
else:
657-
raiseInvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
677+
raiseInvalidCheck('Invalid number of {} arguments'.format(c.cmd))
658678

659679
elifc.cmd=='has-dir': # has-dir test
660-
iflen(c.args) ==1: # @has-dir <path> = has-dir test
680+
iflen(c.args) ==1: # has-dir <path> = has-dir test
661681
try:
662682
cache.get_dir(c.args[0])
663683
ret=True
664684
exceptFailedCheckaserr:
665685
cerr=str(err)
666686
ret=False
667687
else:
668-
raiseInvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
688+
raiseInvalidCheck('Invalid number of {} arguments'.format(c.cmd))
669689

670690
elifc.cmd=='valid-html':
671-
raiseInvalidCheck('Unimplemented @valid-html')
691+
raiseInvalidCheck('Unimplemented valid-html')
672692

673693
elifc.cmd=='valid-links':
674-
raiseInvalidCheck('Unimplemented @valid-links')
694+
raiseInvalidCheck('Unimplemented valid-links')
675695

676696
else:
677-
raiseInvalidCheck('Unrecognized @{}'.format(c.cmd))
697+
raiseInvalidCheck('Unrecognized {}'.format(c.cmd))
678698

679699
ifret==c.negated:
680700
raiseFailedCheck(cerr)
681701

682702
exceptFailedCheckaserr:
683-
message='@{}{} check failed'.format('!'ifc.negatedelse'', c.cmd)
703+
message='{}{} check failed'.format('!'ifc.negatedelse'', c.cmd)
684704
print_err(c.lineno, c.context, str(err), message)
685705
exceptInvalidCheckaserr:
686706
print_err(c.lineno, c.context, str(err))

0 commit comments

Comments
 (0)