Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/tools/compiletest/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ impl EarlyProps {
}

#[derive(Clone, Debug)]
pub struct TestProps {
pub(crate) struct TestProps {
// Lines that should be expected, in order, on standard out
pub error_patterns: Vec<String>,
// Regexes that should be expected, in order, on standard out
pub regex_error_patterns: Vec<String>,
/// Edition selected by an `//@ edition` directive, if any.
///
/// Automatically added to `compile_flags` during directive processing.
pub edition: Option<Edition>,
// Extra flags to pass to the compiler
pub compile_flags: Vec<String>,
// Extra flags to pass when the compiled code is run (such as --bench)
Expand Down Expand Up @@ -267,6 +271,7 @@ impl TestProps {
TestProps {
error_patterns: vec![],
regex_error_patterns: vec![],
edition: None,
compile_flags: vec![],
run_flags: vec![],
doc_flags: vec![],
Expand Down Expand Up @@ -355,7 +360,6 @@ impl TestProps {
/// `//@[foo]`), then the property is ignored unless `test_revision` is
/// `Some("foo")`.
fn load_from(&mut self, testfile: &Utf8Path, test_revision: Option<&str>, config: &Config) {
let mut has_edition = false;
if !testfile.is_dir() {
let file_contents = fs::read_to_string(testfile).unwrap();
let file_directives = FileDirectives::from_file_contents(testfile, &file_contents);
Expand Down Expand Up @@ -423,13 +427,7 @@ impl TestProps {
}

if let Some(range) = parse_edition_range(config, ln) {
// The edition is added at the start, since flags from //@compile-flags must
// be passed to rustc last.
self.compile_flags.insert(
0,
format!("--edition={}", range.edition_to_test(config.edition)),
);
has_edition = true;
self.edition = Some(range.edition_to_test(config.edition));
}

config.parse_and_update_revisions(ln, &mut self.revisions);
Expand Down Expand Up @@ -678,10 +676,10 @@ impl TestProps {
}
}

if let (Some(edition), false) = (&config.edition, has_edition) {
if let Some(edition) = self.edition.or(config.edition) {
// The edition is added at the start, since flags from //@compile-flags must be passed
// to rustc last.
self.compile_flags.insert(0, format!("--edition={}", edition));
self.compile_flags.insert(0, format!("--edition={edition}"));
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/tools/compiletest/src/directives/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,18 @@ fn parse_edition_range(line: &str) -> Option<EditionRange> {
super::parse_edition_range(&config, &line)
}

#[test]
fn edition_order() {
let editions = &[
Edition::Year(2015),
Edition::Year(2018),
Edition::Year(2021),
Edition::Year(2024),
Edition::Future,
];
assert!(editions.is_sorted(), "{editions:#?}");
}

#[test]
fn test_parse_edition_range() {
assert_eq!(None, parse_edition_range("hello-world"));
Expand Down
Loading