Skip to content

Commit

Permalink
Add edition configuration to compiletest
Browse files Browse the repository at this point in the history
  • Loading branch information
llogiq committed Oct 20, 2021
1 parent 1af55d1 commit 65b3c85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/tools/compiletest/src/common.rs
Expand Up @@ -349,6 +349,9 @@ pub struct Config {
/// The current Rust channel
pub channel: String,

/// The default Rust edition
pub edition: Option<String>,

// Configuration for various run-make tests frobbing things like C compilers
// or querying about various LLVM component information.
pub cc: String,
Expand Down
6 changes: 6 additions & 0 deletions src/tools/compiletest/src/header.rs
Expand Up @@ -222,6 +222,7 @@ impl TestProps {
/// `//[foo]`), then the property is ignored unless `cfg` is
/// `Some("foo")`.
fn load_from(&mut self, testfile: &Path, cfg: Option<&str>, config: &Config) {
let mut has_edition = false;
if !testfile.is_dir() {
let file = File::open(testfile).unwrap();

Expand All @@ -240,6 +241,7 @@ impl TestProps {

if let Some(edition) = config.parse_edition(ln) {
self.compile_flags.push(format!("--edition={}", edition));
has_edition = true;
if edition == "2021" {
self.compile_flags.push("-Zunstable-options".to_string());
}
Expand Down Expand Up @@ -391,6 +393,10 @@ impl TestProps {
}
}
}

if let (Some(edition), false) = (&config.edition, has_edition) {
self.compile_flags.push(format!("--edition={}", edition));
}
}

fn update_fail_mode(&mut self, ln: &str, config: &Config) {
Expand Down
4 changes: 3 additions & 1 deletion src/tools/compiletest/src/main.rs
Expand Up @@ -147,7 +147,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
)
.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged")
.optflag("h", "help", "show this message")
.reqopt("", "channel", "current Rust channel", "CHANNEL");
.reqopt("", "channel", "current Rust channel", "CHANNEL")
.optopt("", "edition", "default Rust edition", "EDITION");

let (argv0, args_) = args.split_first().unwrap();
if args.len() == 1 || args[1] == "-h" || args[1] == "--help" {
Expand Down Expand Up @@ -282,6 +283,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
rustfix_coverage: matches.opt_present("rustfix-coverage"),
has_tidy,
channel: matches.opt_str("channel").unwrap(),
edition: matches.opt_str("edition"),

cc: matches.opt_str("cc").unwrap(),
cxx: matches.opt_str("cxx").unwrap(),
Expand Down

0 comments on commit 65b3c85

Please sign in to comment.