@@ -241,11 +241,236 @@ def concat_multi_lines(f):
241241
242242
243243LINE_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
250475def  get_commands (template ):
251476    with  io .open (template , encoding = 'utf-8' ) as  f :
@@ -254,17 +479,9 @@ def get_commands(template):
254479            if  not  m :
255480                continue 
256481
257-             negated  =  (m .group ('negated' ) ==  '!' )
258482            cmd  =  m .group ('cmd' )
259-             if  m .group ('invalid' ) ==  '!' :
260-                 print_err (
261-                     lineno ,
262-                     line ,
263-                     'Invalid command: `!@{0}{1}`, (help: try with `@!{1}`)' .format (
264-                         '!'  if  negated  else  '' ,
265-                         cmd ,
266-                     ),
267-                 )
483+             negated  =  (m .group ('negated' ) ==  '!' )
484+             if  not  negated  and  cmd  in  KNOWN_DIRECTIVE_NAMES :
268485                continue 
269486            args  =  m .group ('args' )
270487            if  args  and  not  args [:1 ].isspace ():
@@ -549,7 +766,7 @@ def get_nb_matching_elements(cache, c, regexp, stop_at_first):
549766def  check_files_in_folder (c , cache , folder , files ):
550767    files  =  files .strip ()
551768    if  not  files .startswith ('[' ) or  not  files .endswith (']' ):
552-         raise  InvalidCheck ("Expected list as second argument of @ {} (ie '[]')" .format (c .cmd ))
769+         raise  InvalidCheck ("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    for  file  in  files :
560777        if  file  in  files_set :
561-             raise  InvalidCheck ("Duplicated file `{}` in @ {}" .format (file , c .cmd ))
778+             raise  InvalidCheck ("Duplicated file `{}` in {}" .format (file , c .cmd ))
562779        files_set .add (file )
563780    folder_set  =  set ([f  for  f  in  os .listdir (folder ) if  f  !=  "."  and  f  !=  ".." ])
564781
@@ -590,48 +807,48 @@ def check_command(c, cache):
590807        if  c .cmd  in  ['has' , 'hasraw' , 'matches' , 'matchesraw' ]:  # string test 
591808            regexp  =  c .cmd .startswith ('matches' )
592809
593-             # @ has <path> = file existence 
810+             # has <path> = file existence 
594811            if  len (c .args ) ==  1  and  not  regexp  and  'raw'  not  in   c .cmd :
595812                try :
596813                    cache .get_file (c .args [0 ])
597814                    ret  =  True 
598815                except  FailedCheck  as  err :
599816                    cerr  =  str (err )
600817                    ret  =  False 
601-             # @ hasraw/matchesraw <path> <pat> = string test 
818+             # hasraw/matchesraw <path> <pat> = string test 
602819            elif  len (c .args ) ==  2  and  'raw'  in  c .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            elif  len (c .args ) ==  3  and  'raw'  not  in   c .cmd :
607824                cerr  =  "`XPATH PATTERN` did not match" 
608825                ret  =  get_nb_matching_elements (cache , c , regexp , True ) !=  0 
609826            else :
610-                 raise  InvalidCheck ('Invalid number of @ {} arguments' .format (c .cmd ))
827+                 raise  InvalidCheck ('Invalid number of {} arguments' .format (c .cmd ))
611828
612829        elif  c .cmd  ==  'files' : # check files in given folder 
613-             if  len (c .args ) !=  2 : # @ files <folder path> <file list> 
614-                 raise  InvalidCheck ("Invalid number of @ {} arguments" .format (c .cmd ))
830+             if  len (c .args ) !=  2 : # files <folder path> <file list> 
831+                 raise  InvalidCheck ("Invalid number of {} arguments" .format (c .cmd ))
615832            elif  c .negated :
616-                 raise  InvalidCheck ("@ {} doesn't support negative check" .format (c .cmd ))
833+                 raise  InvalidCheck ("{} doesn't support negative check" .format (c .cmd ))
617834            ret  =  check_files_in_folder (c , cache , c .args [0 ], c .args [1 ])
618835
619836        elif  c .cmd  ==  'count' :  # count test 
620-             if  len (c .args ) ==  3 :  # @ count <path> <pat> <count> = count test 
837+             if  len (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-             elif  len (c .args ) ==  4 :  # @ count <path> <pat> <text> <count> = count test 
842+             elif  len (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-                 raise  InvalidCheck ('Invalid number of @ {} arguments' .format (c .cmd ))
848+                 raise  InvalidCheck ('Invalid number of {} arguments' .format (c .cmd ))
632849
633850        elif  c .cmd  ==  'snapshot' :  # snapshot test 
634-             if  len (c .args ) ==  3 :  # @ snapshot <snapshot-name> <html-path> <xpath> 
851+             if  len (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                    raise  FailedCheck ('Expected 1 match, but found {}' .format (len (subtrees )))
656873            else :
657-                 raise  InvalidCheck ('Invalid number of @ {} arguments' .format (c .cmd ))
874+                 raise  InvalidCheck ('Invalid number of {} arguments' .format (c .cmd ))
658875
659876        elif  c .cmd  ==  'has-dir' :  # has-dir test 
660-             if  len (c .args ) ==  1 :  # @ has-dir <path> = has-dir test 
877+             if  len (c .args ) ==  1 :  # has-dir <path> = has-dir test 
661878                try :
662879                    cache .get_dir (c .args [0 ])
663880                    ret  =  True 
664881                except  FailedCheck  as  err :
665882                    cerr  =  str (err )
666883                    ret  =  False 
667884            else :
668-                 raise  InvalidCheck ('Invalid number of @ {} arguments' .format (c .cmd ))
885+                 raise  InvalidCheck ('Invalid number of {} arguments' .format (c .cmd ))
669886
670887        elif  c .cmd  ==  'valid-html' :
671-             raise  InvalidCheck ('Unimplemented @ valid-html' )
888+             raise  InvalidCheck ('Unimplemented valid-html' )
672889
673890        elif  c .cmd  ==  'valid-links' :
674-             raise  InvalidCheck ('Unimplemented @ valid-links' )
891+             raise  InvalidCheck ('Unimplemented valid-links' )
675892
676893        else :
677-             raise  InvalidCheck ('Unrecognized @ {}' .format (c .cmd ))
894+             raise  InvalidCheck ('Unrecognized {}' .format (c .cmd ))
678895
679896        if  ret  ==  c .negated :
680897            raise  FailedCheck (cerr )
681898
682899    except  FailedCheck  as  err :
683-         message  =  '@ {}{} check failed' .format ('!'  if  c .negated  else  '' , c .cmd )
900+         message  =  '{}{} check failed' .format ('!'  if  c .negated  else  '' , c .cmd )
684901        print_err (c .lineno , c .context , str (err ), message )
685902    except  InvalidCheck  as  err :
686903        print_err (c .lineno , c .context , str (err ))
0 commit comments