Skip to content

Suppress unstable config options by default. #2612

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

Merged
merged 1 commit into from
Apr 10, 2018
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
4 changes: 2 additions & 2 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 } => {
Expand Down
41 changes: 23 additions & 18 deletions src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -359,33 +360,37 @@ 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); )+
let mut space_str = String::with_capacity(max);
for _ in 0..max {
space_str.push(' ');
}
println!("Configuration Options:");
writeln!(out, "Configuration Options:").unwrap();
$(
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 $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(' ')
}
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!();
}
)+
}
Expand Down
52 changes: 52 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down