From 2ae1b4804ca528d21005738f56018b7c6a6141e9 Mon Sep 17 00:00:00 2001 From: Otavio Salvador Date: Tue, 9 Oct 2018 09:06:16 -0300 Subject: [PATCH] Enable `stdin_disable_all_formatting_test` test Fixes: #1990. Signed-off-by: Otavio Salvador --- src/test/mod.rs | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/test/mod.rs b/src/test/mod.rs index a9015cedf6a..1967c74da45 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -17,6 +17,7 @@ use std::io::{self, BufRead, BufReader, Read, Write}; use std::iter::{Enumerate, Peekable}; use std::mem; use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; use std::str::Chars; use config::{Color, Config, EmitMode, FileName, ReportTactic}; @@ -287,28 +288,32 @@ fn stdin_formatting_smoke_test() { assert_eq!(buf, "fn main() {}\r\n".as_bytes()); } -// FIXME(#1990) restore this test -// #[test] -// fn stdin_disable_all_formatting_test() { -// let input = String::from("fn main() { println!(\"This should not be formatted.\"); }"); -// let mut child = Command::new("./target/debug/rustfmt") -// .stdin(Stdio::piped()) -// .stdout(Stdio::piped()) -// .arg("--config-path=./tests/config/disable_all_formatting.toml") -// .spawn() -// .expect("failed to execute child"); +#[test] +fn stdin_disable_all_formatting_test() { + match option_env!("CFG_RELEASE_CHANNEL") { + None | Some("nightly") => {} + _ => return, // these tests require nightly + } + let input = String::from("fn main() { println!(\"This should not be formatted.\"); }"); + let mut child = Command::new("./target/debug/rustfmt") + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .arg("--config-path=./tests/config/disable_all_formatting.toml") + .spawn() + .expect("failed to execute child"); -// { -// let stdin = child.stdin.as_mut().expect("failed to get stdin"); -// stdin -// .write_all(input.as_bytes()) -// .expect("failed to write stdin"); -// } -// let output = child.wait_with_output().expect("failed to wait on child"); -// assert!(output.status.success()); -// assert!(output.stderr.is_empty()); -// assert_eq!(input, String::from_utf8(output.stdout).unwrap()); -// } + { + let stdin = child.stdin.as_mut().expect("failed to get stdin"); + stdin + .write_all(input.as_bytes()) + .expect("failed to write stdin"); + } + + let output = child.wait_with_output().expect("failed to wait on child"); + assert!(output.status.success()); + assert!(output.stderr.is_empty()); + assert_eq!(input, String::from_utf8(output.stdout).unwrap()); +} #[test] fn format_lines_errors_are_reported() {