Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9057c3f

Browse files
committedJul 19, 2024
Auto merge of #127968 - fmease:upd-jsondocck-directive-style, r=GuillaumeGomez
Update jsondocck directives to follow ui_test-style Context: Comment chain in #125813. Follow-up to #126788. Use the same temporary approach of "double parsing" until we figure out how we want to support compiletest/ui_test directive "add-ons" for child test runners like HtmlDocCk and JsonDocCk. I didn't touch much of jsondocck because I want to refactor it some other time (for robustness, maintainability and better diagnostics; basically by following a similar design of my WIP HtmlDocCk-next, cc #125780). r? `@GuillaumeGomez`
2 parents ff4b398 + 633f41d commit 9057c3f

File tree

131 files changed

+1095
-1090
lines changed

Some content is hidden

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

131 files changed

+1095
-1090
lines changed
 

‎src/etc/htmldocck.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ def filter_line(line):
266266
# To prevent duplicating the list of commmands between `compiletest` and `htmldocck`, we put
267267
# it into a common file which is included in rust code and parsed here.
268268
# FIXME: This setup is temporary until we figure out how to improve this situation.
269+
# See <https://github.com/rust-lang/rust/issues/125813#issuecomment-2141953780>.
269270
KNOWN_DIRECTIVE_NAMES = get_known_directive_names()
270271

271272
LINE_PATTERN = re.compile(r'''

‎src/tools/compiletest/src/header.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -723,12 +723,13 @@ pub fn line_directive<'line>(
723723
}
724724
}
725725

726-
// To prevent duplicating the list of commmands between `compiletest` and `htmldocck`, we put
727-
// it into a common file which is included in rust code and parsed here.
726+
// To prevent duplicating the list of commmands between `compiletest`,`htmldocck` and `jsondocck`,
727+
// we put it into a common file which is included in rust code and parsed here.
728728
// FIXME: This setup is temporary until we figure out how to improve this situation.
729+
// See <https://github.com/rust-lang/rust/issues/125813#issuecomment-2141953780>.
729730
include!("command-list.rs");
730731

731-
const KNOWN_RUSTDOC_DIRECTIVE_NAMES: &[&str] = &[
732+
const KNOWN_HTMLDOCCK_DIRECTIVE_NAMES: &[&str] = &[
732733
"count",
733734
"!count",
734735
"files",
@@ -747,6 +748,9 @@ const KNOWN_RUSTDOC_DIRECTIVE_NAMES: &[&str] = &[
747748
"!snapshot",
748749
];
749750

751+
const KNOWN_JSONDOCCK_DIRECTIVE_NAMES: &[&str] =
752+
&["count", "!count", "has", "!has", "is", "!is", "ismany", "!ismany", "set", "!set"];
753+
750754
/// The broken-down contents of a line containing a test header directive,
751755
/// which [`iter_header`] passes to its callback function.
752756
///
@@ -783,17 +787,26 @@ pub(crate) struct CheckDirectiveResult<'ln> {
783787

784788
pub(crate) fn check_directive<'a>(
785789
directive_ln: &'a str,
786-
is_rustdoc: bool,
790+
mode: Mode,
787791
original_line: &str,
788792
) -> CheckDirectiveResult<'a> {
789793
let (directive_name, post) = directive_ln.split_once([':', ' ']).unwrap_or((directive_ln, ""));
790794

791795
let trailing = post.trim().split_once(' ').map(|(pre, _)| pre).unwrap_or(post);
792796
let is_known = |s: &str| {
793797
KNOWN_DIRECTIVE_NAMES.contains(&s)
794-
|| (is_rustdoc
795-
&& original_line.starts_with("//@")
796-
&& KNOWN_RUSTDOC_DIRECTIVE_NAMES.contains(&s))
798+
|| match mode {
799+
Mode::Rustdoc | Mode::RustdocJson => {
800+
original_line.starts_with("//@")
801+
&& match mode {
802+
Mode::Rustdoc => KNOWN_HTMLDOCCK_DIRECTIVE_NAMES,
803+
Mode::RustdocJson => KNOWN_JSONDOCCK_DIRECTIVE_NAMES,
804+
_ => unreachable!(),
805+
}
806+
.contains(&s)
807+
}
808+
_ => false,
809+
}
797810
};
798811
let trailing_directive = {
799812
// 1. is the directive name followed by a space? (to exclude `:`)
@@ -875,7 +888,7 @@ fn iter_header(
875888
let directive_ln = non_revisioned_directive_line.trim();
876889

877890
let CheckDirectiveResult { is_known_directive, trailing_directive, .. } =
878-
check_directive(directive_ln, mode == Mode::Rustdoc, ln);
891+
check_directive(directive_ln, mode, ln);
879892

880893
if !is_known_directive {
881894
*poisoned = true;
@@ -928,7 +941,7 @@ fn iter_header(
928941
let rest = rest.trim_start();
929942

930943
let CheckDirectiveResult { is_known_directive, directive_name, .. } =
931-
check_directive(rest, mode == Mode::Rustdoc, ln);
944+
check_directive(rest, mode, ln);
932945

933946
if is_known_directive {
934947
*poisoned = true;

0 commit comments

Comments
 (0)
Please sign in to comment.