Skip to content

Commit 518ece2

Browse files
authored
Merge pull request #2612 from peterhuene/suppress-unstable-config-options
Suppress unstable config options by default.
2 parents 2840229 + 8208f8a commit 518ece2

File tree

3 files changed

+77
-20
lines changed

3 files changed

+77
-20
lines changed

src/bin/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ extern crate getopts;
1515
extern crate rustfmt_nightly as rustfmt;
1616

1717
use std::fs::File;
18-
use std::io::{self, Read, Write};
18+
use std::io::{self, stdout, Read, Write};
1919
use std::path::{Path, PathBuf};
2020
use std::str::FromStr;
2121
use std::{env, error};
@@ -226,7 +226,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
226226
Ok(Summary::default())
227227
}
228228
Operation::ConfigHelp => {
229-
Config::print_docs();
229+
Config::print_docs(&mut stdout(), matches.opt_present("unstable-features"));
230230
Ok(Summary::default())
231231
}
232232
Operation::ConfigOutputDefault { path } => {

src/config/config_type.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ macro_rules! is_nightly_channel {
8181
macro_rules! create_config {
8282
($($i:ident: $ty:ty, $def:expr, $stb:expr, $( $dstring:expr ),+ );+ $(;)*) => (
8383
use std::collections::HashSet;
84+
use std::io::Write;
8485

8586
#[derive(Clone)]
8687
pub struct Config {
@@ -359,33 +360,37 @@ macro_rules! create_config {
359360
HIDE_OPTIONS.contains(&name)
360361
}
361362

362-
pub fn print_docs() {
363+
pub fn print_docs(out: &mut Write, include_unstable: bool) {
363364
use std::cmp;
364365
let max = 0;
365366
$( let max = cmp::max(max, stringify!($i).len()+1); )+
366367
let mut space_str = String::with_capacity(max);
367368
for _ in 0..max {
368369
space_str.push(' ');
369370
}
370-
println!("Configuration Options:");
371+
writeln!(out, "Configuration Options:").unwrap();
371372
$(
372-
let name_raw = stringify!($i);
373-
374-
if !Config::is_hidden_option(name_raw) {
375-
let mut name_out = String::with_capacity(max);
376-
for _ in name_raw.len()..max-1 {
377-
name_out.push(' ')
373+
if $stb || include_unstable {
374+
let name_raw = stringify!($i);
375+
376+
if !Config::is_hidden_option(name_raw) {
377+
let mut name_out = String::with_capacity(max);
378+
for _ in name_raw.len()..max-1 {
379+
name_out.push(' ')
380+
}
381+
name_out.push_str(name_raw);
382+
name_out.push(' ');
383+
writeln!(out,
384+
"{}{} Default: {:?}{}",
385+
name_out,
386+
<$ty>::doc_hint(),
387+
$def,
388+
if !$stb { " (unstable)" } else { "" }).unwrap();
389+
$(
390+
writeln!(out, "{}{}", space_str, $dstring).unwrap();
391+
)+
392+
writeln!(out).unwrap();
378393
}
379-
name_out.push_str(name_raw);
380-
name_out.push(' ');
381-
println!("{}{} Default: {:?}",
382-
name_out,
383-
<$ty>::doc_hint(),
384-
$def);
385-
$(
386-
println!("{}{}", space_str, $dstring);
387-
)+
388-
println!();
389394
}
390395
)+
391396
}

src/config/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,31 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
181181
#[cfg(test)]
182182
mod test {
183183
use super::Config;
184+
use std::str;
185+
186+
#[allow(dead_code)]
187+
mod mock {
188+
use super::super::*;
189+
190+
create_config! {
191+
// Options that are used by the generated functions
192+
max_width: usize, 100, true, "Maximum width of each line";
193+
use_small_heuristics: bool, true, false, "Whether to use different formatting for items and \
194+
expressions if they satisfy a heuristic notion of 'small'.";
195+
license_template_path: String, String::default(), false, "Beginning of file must match license template";
196+
required_version: String, env!("CARGO_PKG_VERSION").to_owned(), false, "Require a specific version of rustfmt.";
197+
ignore: IgnoreList, IgnoreList::default(), false, "Skip formatting the specified files and directories.";
198+
verbose: bool, false, false, "Use verbose output";
199+
file_lines: FileLines, FileLines::all(), false,
200+
"Lines to format; this is not supported in rustfmt.toml, and can only be specified \
201+
via the --file-lines option";
202+
width_heuristics: WidthHeuristics, WidthHeuristics::scaled(100), false, "'small' heuristic values";
203+
204+
// Options that are used by the tests
205+
stable_option: bool, false, true, "A stable option";
206+
unstable_option: bool, false, false, "An unstable option";
207+
}
208+
}
184209

185210
#[test]
186211
fn test_config_set() {
@@ -218,6 +243,33 @@ mod test {
218243
assert_eq!(config.was_set().verbose(), false);
219244
}
220245

246+
#[test]
247+
fn test_print_docs_exclude_unstable() {
248+
use self::mock::Config;
249+
250+
let mut output = Vec::new();
251+
Config::print_docs(&mut output, false);
252+
253+
let s = str::from_utf8(&output).unwrap();
254+
255+
assert_eq!(s.contains("stable_option"), true);
256+
assert_eq!(s.contains("unstable_option"), false);
257+
assert_eq!(s.contains("(unstable)"), false);
258+
}
259+
260+
#[test]
261+
fn test_print_docs_include_unstable() {
262+
use self::mock::Config;
263+
264+
let mut output = Vec::new();
265+
Config::print_docs(&mut output, true);
266+
267+
let s = str::from_utf8(&output).unwrap();
268+
assert_eq!(s.contains("stable_option"), true);
269+
assert_eq!(s.contains("unstable_option"), true);
270+
assert_eq!(s.contains("(unstable)"), true);
271+
}
272+
221273
// FIXME(#2183) these tests cannot be run in parallel because they use env vars
222274
// #[test]
223275
// fn test_as_not_nightly_channel() {

0 commit comments

Comments
 (0)