Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: fix up old test #122355

Merged
merged 1 commit into from Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/tools/compiletest/src/header.rs
Expand Up @@ -694,7 +694,6 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"check-stdout",
"check-test-line-numbers-match",
"compile-flags",
"count",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @jieyouxu (#121561) I presume you allowlisted count precisely because of tests/rustdoc/line-breaks.rs, am I correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must have assumed it was a valid directive too...

"dont-check-compiler-stderr",
"dont-check-compiler-stdout",
"dont-check-failure-status",
Expand Down
41 changes: 26 additions & 15 deletions tests/rustdoc/line-breaks.rs
@@ -1,26 +1,37 @@
#![crate_name = "foo"]

use std::ops::Add;
use std::fmt::Display;
use std::ops::Add;

//@count foo/fn.function_with_a_really_long_name.html //pre/br 2
pub fn function_with_a_really_long_name(parameter_one: i32,
parameter_two: i32)
-> Option<i32> {
// @matches foo/fn.function_with_a_really_long_name.html '//*[@class="rust item-decl"]//code' "\
// function_with_a_really_long_name\(\n\
// \ parameter_one: i32,\n\
// \ parameter_two: i32\n\
// \) -> Option<i32>$"
pub fn function_with_a_really_long_name(parameter_one: i32, parameter_two: i32) -> Option<i32> {
Some(parameter_one + parameter_two)
}

//@count foo/fn.short_name.html //pre/br 0
pub fn short_name(param: i32) -> i32 { param + 1 }
// @matches foo/fn.short_name.html '//*[@class="rust item-decl"]//code' \
// "short_name\(param: i32\) -> i32$"
pub fn short_name(param: i32) -> i32 {
param + 1
}

//@count foo/fn.where_clause.html //pre/br 4
pub fn where_clause<T, U>(param_one: T,
param_two: U)
where T: Add<U> + Display + Copy,
U: Add<T> + Display + Copy,
T::Output: Display + Add<U::Output> + Copy,
<T::Output as Add<U::Output>>::Output: Display,
U::Output: Display + Copy
// @matches foo/fn.where_clause.html '//*[@class="rust item-decl"]//code' "\
// where_clause<T, U>\(param_one: T, param_two: U\)where\n\
// \ T: Add<U> \+ Display \+ Copy,\n\
Copy link
Member Author

@fmease fmease Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The \ right before the LF makes htmldocck dedent the following line, hence the “floating” \ on this line: It stops the dedentation process and “bakes” 4 literal spaces into the string literal whose presence we want to check.

// \ U: Add<T> \+ Display \+ Copy,\n\
// \ T::Output: Display \+ Add<U::Output> \+ Copy,\n\
// \ <T::Output as Add<U::Output>>::Output: Display,\n\
// \ U::Output: Display \+ Copy,$"
pub fn where_clause<T, U>(param_one: T, param_two: U)
where
T: Add<U> + Display + Copy,
U: Add<T> + Display + Copy,
T::Output: Display + Add<U::Output> + Copy,
<T::Output as Add<U::Output>>::Output: Display,
U::Output: Display + Copy,
{
let x = param_one + param_two;
println!("{} + {} = {}", param_one, param_two, x);
Expand Down