mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-09 21:42:44 +00:00
Merge pull request #2612 from peterhuene/suppress-unstable-config-options
Suppress unstable config options by default.
This commit is contained in:
commit
518ece2272
@ -15,7 +15,7 @@ extern crate getopts;
|
||||
extern crate rustfmt_nightly as rustfmt;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{self, Read, Write};
|
||||
use std::io::{self, stdout, Read, Write};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use std::{env, error};
|
||||
@ -226,7 +226,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
|
||||
Ok(Summary::default())
|
||||
}
|
||||
Operation::ConfigHelp => {
|
||||
Config::print_docs();
|
||||
Config::print_docs(&mut stdout(), matches.opt_present("unstable-features"));
|
||||
Ok(Summary::default())
|
||||
}
|
||||
Operation::ConfigOutputDefault { path } => {
|
||||
|
@ -81,6 +81,7 @@ macro_rules! is_nightly_channel {
|
||||
macro_rules! create_config {
|
||||
($($i:ident: $ty:ty, $def:expr, $stb:expr, $( $dstring:expr ),+ );+ $(;)*) => (
|
||||
use std::collections::HashSet;
|
||||
use std::io::Write;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Config {
|
||||
@ -359,7 +360,7 @@ macro_rules! create_config {
|
||||
HIDE_OPTIONS.contains(&name)
|
||||
}
|
||||
|
||||
pub fn print_docs() {
|
||||
pub fn print_docs(out: &mut Write, include_unstable: bool) {
|
||||
use std::cmp;
|
||||
let max = 0;
|
||||
$( let max = cmp::max(max, stringify!($i).len()+1); )+
|
||||
@ -367,25 +368,29 @@ macro_rules! create_config {
|
||||
for _ in 0..max {
|
||||
space_str.push(' ');
|
||||
}
|
||||
println!("Configuration Options:");
|
||||
writeln!(out, "Configuration Options:").unwrap();
|
||||
$(
|
||||
let name_raw = stringify!($i);
|
||||
if $stb || include_unstable {
|
||||
let name_raw = stringify!($i);
|
||||
|
||||
if !Config::is_hidden_option(name_raw) {
|
||||
let mut name_out = String::with_capacity(max);
|
||||
for _ in name_raw.len()..max-1 {
|
||||
name_out.push(' ')
|
||||
if !Config::is_hidden_option(name_raw) {
|
||||
let mut name_out = String::with_capacity(max);
|
||||
for _ in name_raw.len()..max-1 {
|
||||
name_out.push(' ')
|
||||
}
|
||||
name_out.push_str(name_raw);
|
||||
name_out.push(' ');
|
||||
writeln!(out,
|
||||
"{}{} Default: {:?}{}",
|
||||
name_out,
|
||||
<$ty>::doc_hint(),
|
||||
$def,
|
||||
if !$stb { " (unstable)" } else { "" }).unwrap();
|
||||
$(
|
||||
writeln!(out, "{}{}", space_str, $dstring).unwrap();
|
||||
)+
|
||||
writeln!(out).unwrap();
|
||||
}
|
||||
name_out.push_str(name_raw);
|
||||
name_out.push(' ');
|
||||
println!("{}{} Default: {:?}",
|
||||
name_out,
|
||||
<$ty>::doc_hint(),
|
||||
$def);
|
||||
$(
|
||||
println!("{}{}", space_str, $dstring);
|
||||
)+
|
||||
println!();
|
||||
}
|
||||
)+
|
||||
}
|
||||
|
@ -181,6 +181,31 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::Config;
|
||||
use std::str;
|
||||
|
||||
#[allow(dead_code)]
|
||||
mod mock {
|
||||
use super::super::*;
|
||||
|
||||
create_config! {
|
||||
// Options that are used by the generated functions
|
||||
max_width: usize, 100, true, "Maximum width of each line";
|
||||
use_small_heuristics: bool, true, false, "Whether to use different formatting for items and \
|
||||
expressions if they satisfy a heuristic notion of 'small'.";
|
||||
license_template_path: String, String::default(), false, "Beginning of file must match license template";
|
||||
required_version: String, env!("CARGO_PKG_VERSION").to_owned(), false, "Require a specific version of rustfmt.";
|
||||
ignore: IgnoreList, IgnoreList::default(), false, "Skip formatting the specified files and directories.";
|
||||
verbose: bool, false, false, "Use verbose output";
|
||||
file_lines: FileLines, FileLines::all(), false,
|
||||
"Lines to format; this is not supported in rustfmt.toml, and can only be specified \
|
||||
via the --file-lines option";
|
||||
width_heuristics: WidthHeuristics, WidthHeuristics::scaled(100), false, "'small' heuristic values";
|
||||
|
||||
// Options that are used by the tests
|
||||
stable_option: bool, false, true, "A stable option";
|
||||
unstable_option: bool, false, false, "An unstable option";
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_config_set() {
|
||||
@ -218,6 +243,33 @@ mod test {
|
||||
assert_eq!(config.was_set().verbose(), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_print_docs_exclude_unstable() {
|
||||
use self::mock::Config;
|
||||
|
||||
let mut output = Vec::new();
|
||||
Config::print_docs(&mut output, false);
|
||||
|
||||
let s = str::from_utf8(&output).unwrap();
|
||||
|
||||
assert_eq!(s.contains("stable_option"), true);
|
||||
assert_eq!(s.contains("unstable_option"), false);
|
||||
assert_eq!(s.contains("(unstable)"), false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_print_docs_include_unstable() {
|
||||
use self::mock::Config;
|
||||
|
||||
let mut output = Vec::new();
|
||||
Config::print_docs(&mut output, true);
|
||||
|
||||
let s = str::from_utf8(&output).unwrap();
|
||||
assert_eq!(s.contains("stable_option"), true);
|
||||
assert_eq!(s.contains("unstable_option"), true);
|
||||
assert_eq!(s.contains("(unstable)"), true);
|
||||
}
|
||||
|
||||
// FIXME(#2183) these tests cannot be run in parallel because they use env vars
|
||||
// #[test]
|
||||
// fn test_as_not_nightly_channel() {
|
||||
|
Loading…
Reference in New Issue
Block a user