Skip to content

Commit e570e9e

Browse files
author
Gilad Naaman
committed
libtest: JSON formatting is now only available in unstable builds
libtest: Added the -Z option for unstable options
1 parent 588a6a3 commit e570e9e

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/libtest/lib.rs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,9 @@ fn optgroups() -> getopts::Options {
399399
.optopt("", "format", "Configure formatting of output:
400400
pretty = Print verbose output;
401401
terse = Display one character per test;
402-
json = Output a json document", "pretty|terse|json");
402+
json = Output a json document", "pretty|terse|json")
403+
.optopt("Z", "", "Enable nightly-only flags:
404+
unstable-options = Allow use of experimental features", "unstable-options");
403405
return opts
404406
}
405407

@@ -435,15 +437,41 @@ Test Attributes:
435437
usage = options.usage(&message));
436438
}
437439

440+
// FIXME: Copied from libsyntax until linkage errors are resolved.
441+
fn is_nightly() -> bool {
442+
// Whether this is a feature-staged build, i.e. on the beta or stable channel
443+
let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
444+
// Whether we should enable unstable features for bootstrapping
445+
let bootstrap = env::var("RUSTC_BOOTSTRAP").is_ok();
446+
447+
bootstrap || !disable_unstable_features
448+
}
449+
438450
// Parses command line arguments into test options
439451
pub fn parse_opts(args: &[String]) -> Option<OptRes> {
452+
let mut allow_unstable = false;
440453
let opts = optgroups();
441454
let args = args.get(1..).unwrap_or(args);
442455
let matches = match opts.parse(args) {
443456
Ok(m) => m,
444457
Err(f) => return Some(Err(f.to_string())),
445458
};
446459

460+
if let Some(opt) = matches.opt_str("Z") {
461+
if !is_nightly() {
462+
return Some(Err("the option `Z` is only accepted on the nightly compiler".into()));
463+
}
464+
465+
match &*opt {
466+
"unstable-options" => {
467+
allow_unstable = true;
468+
}
469+
_ => {
470+
return Some(Err("Unrecognized option to `Z`".into()));
471+
}
472+
}
473+
};
474+
447475
if matches.opt_present("h") {
448476
usage(&args[0], &opts);
449477
return None;
@@ -504,7 +532,13 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
504532
None if quiet => OutputFormat::Terse,
505533
Some("pretty") | None => OutputFormat::Pretty,
506534
Some("terse") => OutputFormat::Terse,
507-
Some("json") => OutputFormat::Json,
535+
Some("json") => {
536+
if !allow_unstable {
537+
return Some(
538+
Err("The \"json\" format is only accepted on the nightly compiler".into()));
539+
}
540+
OutputFormat::Json
541+
},
508542

509543
Some(v) => {
510544
return Some(Err(format!("argument for --format must be pretty, terse, or json (was \

0 commit comments

Comments
 (0)