Skip to content

Commit d3ec92e

Browse files
Move tests/rustdoc testsuite to //@ syntax
1 parent 2c243d9 commit d3ec92e

2 files changed

Lines changed: 283 additions & 37 deletions

File tree

‎src/etc/htmldocck.py‎

Lines changed: 249 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,236 @@ def concat_multi_lines(f):
241241

242242

243243
LINE_PATTERN=re.compile(r'''
244-
(?<=(?<!\S))(?P<invalid>!?)@(?P<negated>!?)
245-
(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
244+
//@\s+
245+
(?P<negated>!?)(?P<cmd>[A-Za-z]+(?:-[A-Za-z]+)*)
246246
(?P<args>.*)$
247247
''', re.X|re.UNICODE)
248248

249+
# Equivalent to `src/tools/compiletest/src/header.rs` constant of the same name.
250+
KNOWN_DIRECTIVE_NAMES= [
251+
# tidy-alphabetical-start
252+
"assembly-output",
253+
"aux-bin",
254+
"aux-build",
255+
"aux-codegen-backend",
256+
"aux-crate",
257+
"build-aux-docs",
258+
"build-fail",
259+
"build-pass",
260+
"check-fail",
261+
"check-pass",
262+
"check-run-results",
263+
"check-stdout",
264+
"check-test-line-numbers-match",
265+
"compare-output-lines-by-subset",
266+
"compile-flags",
267+
"dont-check-compiler-stderr",
268+
"dont-check-compiler-stdout",
269+
"dont-check-failure-status",
270+
"edition",
271+
"error-pattern",
272+
"exec-env",
273+
"failure-status",
274+
"filecheck-flags",
275+
"forbid-output",
276+
"force-host",
277+
"ignore-16bit",
278+
"ignore-32bit",
279+
"ignore-64bit",
280+
"ignore-aarch64",
281+
"ignore-aarch64-unknown-linux-gnu",
282+
"ignore-android",
283+
"ignore-apple",
284+
"ignore-arm",
285+
"ignore-avr",
286+
"ignore-beta",
287+
"ignore-cdb",
288+
"ignore-compare-mode-next-solver",
289+
"ignore-compare-mode-polonius",
290+
"ignore-cross-compile",
291+
"ignore-debug",
292+
"ignore-eabi",
293+
"ignore-emscripten",
294+
"ignore-endian-big",
295+
"ignore-freebsd",
296+
"ignore-fuchsia",
297+
"ignore-gdb",
298+
"ignore-gdb-version",
299+
"ignore-gnu",
300+
"ignore-haiku",
301+
"ignore-horizon",
302+
"ignore-i686-pc-windows-msvc",
303+
"ignore-ios",
304+
"ignore-linux",
305+
"ignore-lldb",
306+
"ignore-llvm-version",
307+
"ignore-loongarch64",
308+
"ignore-macabi",
309+
"ignore-macos",
310+
"ignore-mode-assembly",
311+
"ignore-mode-codegen",
312+
"ignore-mode-codegen-units",
313+
"ignore-mode-coverage-map",
314+
"ignore-mode-coverage-run",
315+
"ignore-mode-crashes",
316+
"ignore-mode-debuginfo",
317+
"ignore-mode-incremental",
318+
"ignore-mode-js-doc-test",
319+
"ignore-mode-mir-opt",
320+
"ignore-mode-pretty",
321+
"ignore-mode-run-make",
322+
"ignore-mode-run-pass-valgrind",
323+
"ignore-mode-rustdoc",
324+
"ignore-mode-rustdoc-json",
325+
"ignore-mode-ui",
326+
"ignore-mode-ui-fulldeps",
327+
"ignore-msp430",
328+
"ignore-msvc",
329+
"ignore-musl",
330+
"ignore-netbsd",
331+
"ignore-nightly",
332+
"ignore-none",
333+
"ignore-nto",
334+
"ignore-nvptx64",
335+
"ignore-nvptx64-nvidia-cuda",
336+
"ignore-openbsd",
337+
"ignore-pass",
338+
"ignore-remote",
339+
"ignore-riscv64",
340+
"ignore-s390x",
341+
"ignore-sgx",
342+
"ignore-spirv",
343+
"ignore-stable",
344+
"ignore-stage1",
345+
"ignore-stage2",
346+
"ignore-test",
347+
"ignore-thumb",
348+
"ignore-thumbv8m.base-none-eabi",
349+
"ignore-thumbv8m.main-none-eabi",
350+
"ignore-tvos",
351+
"ignore-unix",
352+
"ignore-unknown",
353+
"ignore-uwp",
354+
"ignore-visionos",
355+
"ignore-vxworks",
356+
"ignore-wasi",
357+
"ignore-wasm",
358+
"ignore-wasm32",
359+
"ignore-wasm32-bare",
360+
"ignore-wasm64",
361+
"ignore-watchos",
362+
"ignore-windows",
363+
"ignore-windows-gnu",
364+
"ignore-x32",
365+
"ignore-x86",
366+
"ignore-x86_64",
367+
"ignore-x86_64-unknown-linux-gnu",
368+
"incremental",
369+
"known-bug",
370+
"llvm-cov-flags",
371+
"min-cdb-version",
372+
"min-gdb-version",
373+
"min-lldb-version",
374+
"min-llvm-version",
375+
"min-system-llvm-version",
376+
"needs-asm-support",
377+
"needs-dlltool",
378+
"needs-dynamic-linking",
379+
"needs-force-clang-based-tests",
380+
"needs-git-hash",
381+
"needs-llvm-components",
382+
"needs-profiler-support",
383+
"needs-relocation-model-pic",
384+
"needs-run-enabled",
385+
"needs-rust-lld",
386+
"needs-rust-lldb",
387+
"needs-sanitizer-address",
388+
"needs-sanitizer-cfi",
389+
"needs-sanitizer-dataflow",
390+
"needs-sanitizer-hwaddress",
391+
"needs-sanitizer-kcfi",
392+
"needs-sanitizer-leak",
393+
"needs-sanitizer-memory",
394+
"needs-sanitizer-memtag",
395+
"needs-sanitizer-safestack",
396+
"needs-sanitizer-shadow-call-stack",
397+
"needs-sanitizer-support",
398+
"needs-sanitizer-thread",
399+
"needs-threads",
400+
"needs-unwind",
401+
"needs-wasmtime",
402+
"needs-xray",
403+
"no-auto-check-cfg",
404+
"no-prefer-dynamic",
405+
"normalize-stderr-32bit",
406+
"normalize-stderr-64bit",
407+
"normalize-stderr-test",
408+
"normalize-stdout-test",
409+
"only-16bit",
410+
"only-32bit",
411+
"only-64bit",
412+
"only-aarch64",
413+
"only-apple",
414+
"only-arm",
415+
"only-avr",
416+
"only-beta",
417+
"only-bpf",
418+
"only-cdb",
419+
"only-gnu",
420+
"only-i686-pc-windows-msvc",
421+
"only-ios",
422+
"only-linux",
423+
"only-loongarch64",
424+
"only-loongarch64-unknown-linux-gnu",
425+
"only-macos",
426+
"only-mips",
427+
"only-mips64",
428+
"only-msp430",
429+
"only-msvc",
430+
"only-nightly",
431+
"only-nvptx64",
432+
"only-riscv64",
433+
"only-sparc",
434+
"only-sparc64",
435+
"only-stable",
436+
"only-thumb",
437+
"only-tvos",
438+
"only-unix",
439+
"only-visionos",
440+
"only-wasm32",
441+
"only-wasm32-bare",
442+
"only-wasm32-wasip1",
443+
"only-watchos",
444+
"only-windows",
445+
"only-x86",
446+
"only-x86_64",
447+
"only-x86_64-fortanix-unknown-sgx",
448+
"only-x86_64-pc-windows-gnu",
449+
"only-x86_64-pc-windows-msvc",
450+
"only-x86_64-unknown-linux-gnu",
451+
"pp-exact",
452+
"pretty-compare-only",
453+
"pretty-expanded",
454+
"pretty-mode",
455+
"regex-error-pattern",
456+
"remap-src-base",
457+
"revisions",
458+
"run-fail",
459+
"run-flags",
460+
"run-pass",
461+
"run-rustfix",
462+
"rustc-env",
463+
"rustfix-only-machine-applicable",
464+
"should-fail",
465+
"should-ice",
466+
"stderr-per-bitwidth",
467+
"test-mir-pass",
468+
"unset-exec-env",
469+
"unset-rustc-env",
470+
# Used by the tidy check `unknown_revision`.
471+
"unused-revision-names",
472+
# tidy-alphabetical-end
473+
]
249474

250475
defget_commands(template):
251476
withio.open(template, encoding='utf-8') asf:
@@ -254,17 +479,9 @@ def get_commands(template):
254479
ifnotm:
255480
continue
256481

257-
negated= (m.group('negated') =='!')
258482
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-
)
483+
negated= (m.group('negated') =='!')
484+
ifnotnegatedandcmdinKNOWN_DIRECTIVE_NAMES:
268485
continue
269486
args=m.group('args')
270487
ifargsandnotargs[:1].isspace():
@@ -549,7 +766,7 @@ def get_nb_matching_elements(cache, c, regexp, stop_at_first):
549766
defcheck_files_in_folder(c, cache, folder, files):
550767
files=files.strip()
551768
ifnotfiles.startswith('[') ornotfiles.endswith(']'):
552-
raiseInvalidCheck("Expected list as second argument of @{} (ie '[]')".format(c.cmd))
769+
raiseInvalidCheck("Expected list as second argument of {} (ie '[]')".format(c.cmd))
553770

554771
folder=cache.get_absolute_path(folder)
555772

@@ -558,7 +775,7 @@ def check_files_in_folder(c, cache, folder, files):
558775
files_set=set()
559776
forfileinfiles:
560777
iffileinfiles_set:
561-
raiseInvalidCheck("Duplicated file `{}` in @{}".format(file, c.cmd))
778+
raiseInvalidCheck("Duplicated file `{}` in {}".format(file, c.cmd))
562779
files_set.add(file)
563780
folder_set=set([fforfinos.listdir(folder) iff!="."andf!=".."])
564781

@@ -590,48 +807,48 @@ def check_command(c, cache):
590807
ifc.cmdin ['has', 'hasraw', 'matches', 'matchesraw']: # string test
591808
regexp=c.cmd.startswith('matches')
592809

593-
# @has <path> = file existence
810+
# has <path> = file existence
594811
iflen(c.args) ==1andnotregexpand'raw'notinc.cmd:
595812
try:
596813
cache.get_file(c.args[0])
597814
ret=True
598815
exceptFailedCheckaserr:
599816
cerr=str(err)
600817
ret=False
601-
# @hasraw/matchesraw <path> <pat> = string test
818+
# hasraw/matchesraw <path> <pat> = string test
602819
eliflen(c.args) ==2and'raw'inc.cmd:
603820
cerr="`PATTERN` did not match"
604821
ret=check_string(cache.get_file(c.args[0]), c.args[1], regexp)
605-
# @has/matches <path> <pat> <match> = XML tree test
822+
# has/matches <path> <pat> <match> = XML tree test
606823
eliflen(c.args) ==3and'raw'notinc.cmd:
607824
cerr="`XPATH PATTERN` did not match"
608825
ret=get_nb_matching_elements(cache, c, regexp, True) !=0
609826
else:
610-
raiseInvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
827+
raiseInvalidCheck('Invalid number of {} arguments'.format(c.cmd))
611828

612829
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))
830+
iflen(c.args) !=2: # files <folder path> <file list>
831+
raiseInvalidCheck("Invalid number of {} arguments".format(c.cmd))
615832
elifc.negated:
616-
raiseInvalidCheck("@{} doesn't support negative check".format(c.cmd))
833+
raiseInvalidCheck("{} doesn't support negative check".format(c.cmd))
617834
ret=check_files_in_folder(c, cache, c.args[0], c.args[1])
618835

619836
elifc.cmd=='count': # count test
620-
iflen(c.args) ==3: # @count <path> <pat> <count> = count test
837+
iflen(c.args) ==3: # count <path> <pat> <count> = count test
621838
expected=int(c.args[2])
622839
found=get_tree_count(cache.get_tree(c.args[0]), c.args[1])
623840
cerr="Expected {} occurrences but found {}".format(expected, found)
624841
ret=expected==found
625-
eliflen(c.args) ==4: # @count <path> <pat> <text> <count> = count test
842+
eliflen(c.args) ==4: # count <path> <pat> <text> <count> = count test
626843
expected=int(c.args[3])
627844
found=get_nb_matching_elements(cache, c, False, False)
628845
cerr="Expected {} occurrences but found {}".format(expected, found)
629846
ret=found==expected
630847
else:
631-
raiseInvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
848+
raiseInvalidCheck('Invalid number of {} arguments'.format(c.cmd))
632849

633850
elifc.cmd=='snapshot': # snapshot test
634-
iflen(c.args) ==3: # @snapshot <snapshot-name> <html-path> <xpath>
851+
iflen(c.args) ==3: # snapshot <snapshot-name> <html-path> <xpath>
635852
[snapshot_name, html_path, pattern] =c.args
636853
tree=cache.get_tree(html_path)
637854
xpath=normalize_xpath(pattern)
@@ -654,33 +871,33 @@ def check_command(c, cache):
654871
else:
655872
raiseFailedCheck('Expected 1 match, but found {}'.format(len(subtrees)))
656873
else:
657-
raiseInvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
874+
raiseInvalidCheck('Invalid number of {} arguments'.format(c.cmd))
658875

659876
elifc.cmd=='has-dir': # has-dir test
660-
iflen(c.args) ==1: # @has-dir <path> = has-dir test
877+
iflen(c.args) ==1: # has-dir <path> = has-dir test
661878
try:
662879
cache.get_dir(c.args[0])
663880
ret=True
664881
exceptFailedCheckaserr:
665882
cerr=str(err)
666883
ret=False
667884
else:
668-
raiseInvalidCheck('Invalid number of @{} arguments'.format(c.cmd))
885+
raiseInvalidCheck('Invalid number of {} arguments'.format(c.cmd))
669886

670887
elifc.cmd=='valid-html':
671-
raiseInvalidCheck('Unimplemented @valid-html')
888+
raiseInvalidCheck('Unimplemented valid-html')
672889

673890
elifc.cmd=='valid-links':
674-
raiseInvalidCheck('Unimplemented @valid-links')
891+
raiseInvalidCheck('Unimplemented valid-links')
675892

676893
else:
677-
raiseInvalidCheck('Unrecognized @{}'.format(c.cmd))
894+
raiseInvalidCheck('Unrecognized {}'.format(c.cmd))
678895

679896
ifret==c.negated:
680897
raiseFailedCheck(cerr)
681898

682899
exceptFailedCheckaserr:
683-
message='@{}{} check failed'.format('!'ifc.negatedelse'', c.cmd)
900+
message='{}{} check failed'.format('!'ifc.negatedelse'', c.cmd)
684901
print_err(c.lineno, c.context, str(err), message)
685902
exceptInvalidCheckaserr:
686903
print_err(c.lineno, c.context, str(err))

0 commit comments

Comments
 (0)