about summary refs log tree commit diff
path: root/src/tools/compiletest
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2024-06-21 14:02:53 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2024-06-24 11:08:41 +0200
commitd3ec92e16e7e78c273c0f996cad5122ce5a6cdd6 (patch)
tree625a249be0f23d854e210ab54746721f8e9a2114 /src/tools/compiletest
parent2c243d957008f5909f7a4af19e486ea8a3814be7 (diff)
downloadrust-d3ec92e16e7e78c273c0f996cad5122ce5a6cdd6.tar.gz
rust-d3ec92e16e7e78c273c0f996cad5122ce5a6cdd6.zip
Move `tests/rustdoc` testsuite to `//@` syntax
Diffstat (limited to 'src/tools/compiletest')
-rw-r--r--src/tools/compiletest/src/header.rs39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs
index 31ae0deb7ec..6780c593a5a 100644
--- a/src/tools/compiletest/src/header.rs
+++ b/src/tools/compiletest/src/header.rs
@@ -954,6 +954,25 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
     // tidy-alphabetical-end
 ];
 
+const KNOWN_RUSTDOC_DIRECTIVE_NAMES: &[&str] = &[
+    "count",
+    "!count",
+    "files",
+    "!files",
+    "has",
+    "!has",
+    "has-dir",
+    "!has-dir",
+    "hasraw",
+    "!hasraw",
+    "matches",
+    "!matches",
+    "matchesraw",
+    "!matchesraw",
+    "snapshot",
+    "!snapshot",
+];
+
 /// The broken-down contents of a line containing a test header directive,
 /// which [`iter_header`] passes to its callback function.
 ///
@@ -988,20 +1007,30 @@ pub(crate) struct CheckDirectiveResult<'ln> {
     trailing_directive: Option<&'ln str>,
 }
 
-pub(crate) fn check_directive(directive_ln: &str) -> CheckDirectiveResult<'_> {
+pub(crate) fn check_directive<'a>(
+    directive_ln: &'a str,
+    is_rustdoc: bool,
+    original_line: &str,
+) -> CheckDirectiveResult<'a> {
     let (directive_name, post) = directive_ln.split_once([':', ' ']).unwrap_or((directive_ln, ""));
 
     let trailing = post.trim().split_once(' ').map(|(pre, _)| pre).unwrap_or(post);
+    let is_known = |s: &str| {
+        KNOWN_DIRECTIVE_NAMES.contains(&s)
+            || (is_rustdoc
+                && original_line.starts_with("//@")
+                && KNOWN_RUSTDOC_DIRECTIVE_NAMES.contains(&s))
+    };
     let trailing_directive = {
         // 1. is the directive name followed by a space? (to exclude `:`)
         matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(' '))
             // 2. is what is after that directive also a directive (ex: "only-x86 only-arm")
-            && KNOWN_DIRECTIVE_NAMES.contains(&trailing)
+            && is_known(trailing)
     }
     .then_some(trailing);
 
     CheckDirectiveResult {
-        is_known_directive: KNOWN_DIRECTIVE_NAMES.contains(&directive_name),
+        is_known_directive: is_known(&directive_name),
         directive_name: directive_ln,
         trailing_directive,
     }
@@ -1072,7 +1101,7 @@ fn iter_header(
                 let directive_ln = non_revisioned_directive_line.trim();
 
                 let CheckDirectiveResult { is_known_directive, trailing_directive, .. } =
-                    check_directive(directive_ln);
+                    check_directive(directive_ln, mode == Mode::Rustdoc, ln);
 
                 if !is_known_directive {
                     *poisoned = true;
@@ -1125,7 +1154,7 @@ fn iter_header(
             let rest = rest.trim_start();
 
             let CheckDirectiveResult { is_known_directive, directive_name, .. } =
-                check_directive(rest);
+                check_directive(rest, mode == Mode::Rustdoc, ln);
 
             if is_known_directive {
                 *poisoned = true;