Skip to content

Commit 1be2c85

Browse files
committed
Compiletest: Simplify {Html,Json}DocCk directive handling
1 parent 915e535 commit 1be2c85

File tree

8 files changed

+293
-363
lines changed

8 files changed

+293
-363
lines changed

src/doc/rustc-dev-guide/src/rustdoc-internals/rustdoc-test-suite.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Similar to shell commands,
5555
directives can extend across multiple lines if their last char is `\`.
5656
In this case, the start of the next line should be `//`, with no `@`.
5757

58+
Similar to compiletest directives, besides a space you can also use a colon `:` to separate
59+
the command from its arguments, however a space is preferred for HtmlDocCk directives.
60+
5861
Use the special string `{{channel}}` in XPaths, `PATTERN` arguments and [snapshot files](#snapshot)
5962
if you'd like to refer to the URL `https://doc.rust-lang.org/CHANNEL` where `CHANNEL` refers to the
6063
current release channel (e.g, `stable` or `nightly`).

src/etc/htmldocck.py

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -147,48 +147,17 @@ def concat_multi_lines(f):
147147
print_err(lineno, line, "Trailing backslash at the end of the file")
148148

149149

150-
def get_known_directive_names():
151-
def filter_line(line):
152-
line = line.strip()
153-
return line.startswith('"') and (line.endswith('",') or line.endswith('"'))
154-
155-
# Equivalent to `src/tools/compiletest/src/header.rs` constant of the same name.
156-
with open(
157-
os.path.join(
158-
# We go back to `src`.
159-
os.path.dirname(os.path.dirname(__file__)),
160-
"tools/compiletest/src/directive-list.rs",
161-
),
162-
"r",
163-
encoding="utf8",
164-
) as fd:
165-
content = fd.read()
166-
return [
167-
line.strip().replace('",', "").replace('"', "")
168-
for line in content.split("\n")
169-
if filter_line(line)
170-
]
171-
172-
173-
# To prevent duplicating the list of commmands between `compiletest` and `htmldocck`, we put
174-
# it into a common file which is included in rust code and parsed here.
175-
# FIXME: This setup is temporary until we figure out how to improve this situation.
176-
# See <https://github.com/rust-lang/rust/issues/125813#issuecomment-2141953780>.
177-
KNOWN_DIRECTIVE_NAMES = get_known_directive_names()
178-
179150
LINE_PATTERN = re.compile(
180151
r"""
181152
//@\s+
182-
(?P<negated>!?)(?P<cmd>[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)
183-
(?P<args>.*)$
153+
(?P<negated>!?)(?P<cmd>.+?)
154+
(?:[\s:](?P<args>.*))?$
184155
""",
185156
re.X | re.UNICODE,
186157
)
187158

188159
DEPRECATED_LINE_PATTERN = re.compile(
189-
r"""
190-
//\s+@
191-
""",
160+
r"//\s+@",
192161
re.X | re.UNICODE,
193162
)
194163

@@ -209,12 +178,7 @@ def get_commands(template):
209178

210179
cmd = m.group("cmd")
211180
negated = m.group("negated") == "!"
212-
if not negated and cmd in KNOWN_DIRECTIVE_NAMES:
213-
continue
214-
args = m.group("args")
215-
if args and not args[:1].isspace():
216-
print_err(lineno, line, "Invalid template syntax")
217-
continue
181+
args = m.group("args") or ""
218182
try:
219183
args = shlex.split(args)
220184
except UnicodeEncodeError:
@@ -632,14 +596,10 @@ def check_command(c, cache):
632596
else:
633597
raise InvalidCheck("Invalid number of {} arguments".format(c.cmd))
634598

635-
elif c.cmd == "valid-html":
636-
raise InvalidCheck("Unimplemented valid-html")
637-
638-
elif c.cmd == "valid-links":
639-
raise InvalidCheck("Unimplemented valid-links")
640-
641599
else:
642-
raise InvalidCheck("Unrecognized {}".format(c.cmd))
600+
# Ignore unknown directives, they might be compiletest directives.
601+
# In any case, compiletest rejects unknown directives for us.
602+
return
643603

644604
if ret == c.negated:
645605
raise FailedCheck(cerr)

src/tools/compiletest/src/directive-list.rs

Lines changed: 0 additions & 260 deletions
This file was deleted.

0 commit comments

Comments
 (0)