From 1a1ea253f2b92179333e0042d63dcfca45a947f0 Mon Sep 17 00:00:00 2001 From: kennytm Date: Sun, 21 May 2017 00:35:53 +0800 Subject: [PATCH] Added --color flag to compiletest. --- src/tools/compiletest/src/common.rs | 5 +++++ src/tools/compiletest/src/main.rs | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index df41e786be58..92f6f36d69d9 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -13,6 +13,8 @@ use std::fmt; use std::str::FromStr; use std::path::PathBuf; +use test::ColorConfig; + #[derive(Clone, Copy, PartialEq, Debug)] pub enum Mode { CompileFail, @@ -185,6 +187,9 @@ pub struct Config { // Print one character per test instead of one line pub quiet: bool, + // Whether to use colors in test. + pub color: ColorConfig, + // where to find the remote test client process, if we're using it pub remote_test_client: Option, diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 6fc7f9f07ac1..1bb0b765f9f1 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -37,7 +37,7 @@ use filetime::FileTime; use getopts::{optopt, optflag, reqopt}; use common::Config; use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Mode}; -use test::TestPaths; +use test::{TestPaths, ColorConfig}; use util::logv; use self::header::EarlyProps; @@ -90,6 +90,7 @@ pub fn parse_config(args: Vec ) -> Config { optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS"), optflag("", "verbose", "run tests verbosely, showing all output"), optflag("", "quiet", "print one character per test instead of one line"), + optopt("", "color", "coloring: auto, always, never", "WHEN"), optopt("", "logfile", "file to log test execution to", "FILE"), optopt("", "target", "the target to build for", "TARGET"), optopt("", "host", "the host to build for", "HOST"), @@ -147,6 +148,13 @@ pub fn parse_config(args: Vec ) -> Config { let (gdb, gdb_version, gdb_native_rust) = analyze_gdb(matches.opt_str("gdb")); + let color = match matches.opt_str("color").as_ref().map(|x| &**x) { + Some("auto") | None => ColorConfig::AutoColor, + Some("always") => ColorConfig::AlwaysColor, + Some("never") => ColorConfig::NeverColor, + Some(x) => panic!("argument for --color must be auto, always, or never, but found `{}`", x), + }; + Config { compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")), run_lib_path: make_absolute(opt_path(matches, "run-lib-path")), @@ -185,6 +193,7 @@ pub fn parse_config(args: Vec ) -> Config { lldb_python_dir: matches.opt_str("lldb-python-dir"), verbose: matches.opt_present("verbose"), quiet: matches.opt_present("quiet"), + color: color, remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from), cc: matches.opt_str("cc").unwrap(), @@ -332,7 +341,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts { Ok(val) => &val != "0", Err(_) => false }, - color: test::AutoColor, + color: config.color, test_threads: None, skip: vec![], list: false,