-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Detect typos for compiletest test directives #121561
Detect typos for compiletest test directives #121561
Conversation
r? @onur-ozkan rustbot has assigned @onur-ozkan. Use r? to explicitly pick a reviewer |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
7ecce91
to
f285c6e
Compare
This comment has been minimized.
This comment has been minimized.
f285c6e
to
c230627
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
e7e58a0
to
6579112
Compare
This comment has been minimized.
This comment has been minimized.
6579112
to
1e86c63
Compare
src/tools/compiletest/src/util.rs
Outdated
// Edit distance taken from rustc's `rustc_span::edit_distance`. | ||
|
||
/// Finds the [edit distance] between two strings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Edit distance taken from rustc's `rustc_span::edit_distance`. | |
/// Finds the [edit distance] between two strings. | |
/// Edit distance taken from rustc's `rustc_span::edit_distance`. | |
/// | |
/// Finds the [edit distance] between two strings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it to a top-level comment for the edit_distance
module.
@@ -23,7 +23,6 @@ mod typeof_1 { | |||
use super::*; | |||
type Opaque = impl Sized; | |||
fn define() -> Opaque { | |||
//[current]~^ ERROR concrete type differs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: Why these are removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tidy enforces that if a revision like current
is associated with a known-bug
directive, then it cannot have any revisioned //~ERROR
s. At least that's what I understood from tidy's error message. This tidy check was not previously triggered because of the extra colon after //@ [current]
...
src/tools/compiletest/src/header.rs
Outdated
// tidy-alphabetical-start | ||
const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we put tidy-alphabetical-start
inside the list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, yeah that would make more sense...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
src/tools/compiletest/src/util.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on creating a separate module for this implementation? Putting these functions and explanations in the generic module util
seems to complicate things a bit, in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I can move it out to some edit_distance module. This code is like copy-pasta'd (including this) 3 places over rustc/cargo/compiletest, ideally we would share a single crate for this, but alas...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to new edit_distance
module.
src/tools/compiletest/src/header.rs
Outdated
} else if let Some((header_revision, original_directive_line)) = line_directive(comment, ln) | ||
{ | ||
// Let Makefiles and non-rs files just get handled in the regular way. | ||
if testfile.extension().map(|e| e != "rs").unwrap_or(true) { | ||
it(HeaderLine { | ||
line_number, | ||
original_line, | ||
header_revision, | ||
directive: original_directive_line, | ||
}); | ||
continue; | ||
} | ||
|
||
let directive_ln = original_directive_line.trim(); | ||
|
||
if let Some((directive_name, _)) = directive_ln.split_once([':', ' ']) { | ||
if KNOWN_DIRECTIVE_NAMES.contains(&directive_name) { | ||
it(HeaderLine { | ||
line_number, | ||
original_line, | ||
header_revision, | ||
directive: original_directive_line, | ||
}); | ||
continue; | ||
} else { | ||
*poisoned = true; | ||
eprintln!( | ||
"error: detected unknown compiletest test directive `{}` in {}:{}", | ||
directive_ln, | ||
testfile.display(), | ||
line_number, | ||
); | ||
|
||
if let Some(suggestion) = | ||
find_best_match_for_name(KNOWN_DIRECTIVE_NAMES, directive_name, None) | ||
{ | ||
eprintln!("help: did you mean `{}` instead?", suggestion); | ||
} | ||
return; | ||
} | ||
} else if KNOWN_DIRECTIVE_NAMES.contains(&directive_ln) { | ||
it(HeaderLine { | ||
line_number, | ||
original_line, | ||
header_revision, | ||
directive: original_directive_line, | ||
}); | ||
continue; | ||
} else { | ||
*poisoned = true; | ||
eprintln!( | ||
"error: detected unknown compiletest test directive `{}` in {}:{}", | ||
directive_ln, | ||
testfile.display(), | ||
line_number, | ||
); | ||
|
||
if let Some(suggestion) = | ||
find_best_match_for_name(KNOWN_DIRECTIVE_NAMES, directive_ln, None) | ||
{ | ||
eprintln!("help: did you mean `{}` instead?", suggestion); | ||
} | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we write some unit tests for this logic (or maybe for the whole feature)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe for the whole compiletest But yeah, I'll think about how to test this / make this more testable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplified this logic and added some (integration) tests for iter_header
and directives checking.
ffde4b6
to
32e713f
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
a7ee012
to
a816cc5
Compare
Summary:
|
@rustbot ready |
…o-check, r=onur-ozkan Detect typos for compiletest test directives Checks directives against a known list of compiletest directives collected during migration from legacy-style compiletest directives. A suggestion for the best matching known directive will be made if an invalid directive is found. This PR does not attempt to implement checks for Makefile directives because they still have the problem of regular comments and directives sharing the same comment prefix `#`. Closes rust-lang#83551.
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#121561 (Detect typos for compiletest test directives) - rust-lang#121567 (Avoid some interning in bootstrap) - rust-lang#121685 (Fixing shellcheck comments on lvi test script) - rust-lang#121833 (Suggest correct path in include_bytes!) - rust-lang#121860 (Add a tidy check that checks whether the fluent slugs only appear once) - rust-lang#121907 (skip sanity check for non-host targets in `check` builds) - rust-lang#122029 (When displaying multispans, ignore empty lines adjacent to `...`) - rust-lang#122221 (match lowering: define a convenient struct) - rust-lang#122244 (fix: LocalWaker memory leak and some stability attributes) - rust-lang#122251 (Add test to check unused_lifetimes don't duplicate "parameter is never used" error) r? `@ghost` `@rustbot` modify labels: rollup
…o-check, r=onur-ozkan Detect typos for compiletest test directives Checks directives against a known list of compiletest directives collected during migration from legacy-style compiletest directives. A suggestion for the best matching known directive will be made if an invalid directive is found. This PR does not attempt to implement checks for Makefile directives because they still have the problem of regular comments and directives sharing the same comment prefix `#`. Closes rust-lang#83551.
…kingjubilee Rollup of 10 pull requests Successful merges: - rust-lang#112136 (Add std::ffi::c_str module) - rust-lang#113525 (Dynamically size sigaltstk in std) - rust-lang#121561 (Detect typos for compiletest test directives) - rust-lang#121685 (Fixing shellcheck comments on lvi test script) - rust-lang#121833 (Suggest correct path in include_bytes!) - rust-lang#121860 (Add a tidy check that checks whether the fluent slugs only appear once) - rust-lang#122125 (Revert back to Git-for-Windows for MinGW CI builds) - rust-lang#122221 (match lowering: define a convenient struct) - rust-lang#122251 (Add test to check unused_lifetimes don't duplicate "parameter is never used" error) - rust-lang#122264 (add myself to rotation) r? `@ghost` `@rustbot` modify labels: rollup
@bors r- rollup=iffy
|
- Fix invalid directive in `normalize-hidden-types` - Update legacy directive in `two-phase-reservation-sharing-interference`
046c28f
to
64dda8c
Compare
Added missing known |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (af69f4c): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 646.803s -> 647.057s (0.04%) |
…notriddle rustdoc: fix up old test `tests/rustdoc/line-breaks.rs` had several issues: 1. It used `//`@count`` instead of `// `@count`` (notice the space!) which gets treated as a `ui_test` directive instead of a `htmldocck` one. `compiletest` didn't flag it as an error because it's allowlisted ([rust-lang#121561](rust-lang#121561)) presumably precisely because of this test. And before the compiletest→ui_test migration, these directives must've been ignored, too, because … 2. … the checks themselves no longer work either: The count of `<br>`s is actually 0 in all 3 cases because – well – we no longer generate any `<br>`s inside `<pre>`s. Since I don't know how to ``@count`` `\n`s instead of `<br>`s, I've turned them into ``@matches`.` Btw, I don't know if this test is still desirable or if we have other tests that cover this (I haven't checked). r? rustdoc
Rollup merge of rust-lang#122355 - fmease:rustdoc-fix-up-old-test, r=notriddle rustdoc: fix up old test `tests/rustdoc/line-breaks.rs` had several issues: 1. It used `//`@count`` instead of `// `@count`` (notice the space!) which gets treated as a `ui_test` directive instead of a `htmldocck` one. `compiletest` didn't flag it as an error because it's allowlisted ([rust-lang#121561](rust-lang#121561)) presumably precisely because of this test. And before the compiletest→ui_test migration, these directives must've been ignored, too, because … 2. … the checks themselves no longer work either: The count of `<br>`s is actually 0 in all 3 cases because – well – we no longer generate any `<br>`s inside `<pre>`s. Since I don't know how to ``@count`` `\n`s instead of `<br>`s, I've turned them into ``@matches`.` Btw, I don't know if this test is still desirable or if we have other tests that cover this (I haven't checked). r? rustdoc
Checks directives against a known list of compiletest directives collected during migration from legacy-style compiletest directives. A suggestion for the best matching known directive will be made if an invalid directive is found.
This PR does not attempt to implement checks for Makefile directives because they still have the problem of regular comments and directives sharing the same comment prefix
#
.Closes #83551.