Skip to content

Commit 1a1ea25

Browse files
committed
Added --color flag to compiletest.
1 parent 57356b3 commit 1a1ea25

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/tools/compiletest/src/common.rs

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ use std::fmt;
1313
use std::str::FromStr;
1414
use std::path::PathBuf;
1515

16+
use test::ColorConfig;
17+
1618
#[derive(Clone, Copy, PartialEq, Debug)]
1719
pub enum Mode {
1820
CompileFail,
@@ -185,6 +187,9 @@ pub struct Config {
185187
// Print one character per test instead of one line
186188
pub quiet: bool,
187189

190+
// Whether to use colors in test.
191+
pub color: ColorConfig,
192+
188193
// where to find the remote test client process, if we're using it
189194
pub remote_test_client: Option<PathBuf>,
190195

src/tools/compiletest/src/main.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use filetime::FileTime;
3737
use getopts::{optopt, optflag, reqopt};
3838
use common::Config;
3939
use common::{Pretty, DebugInfoGdb, DebugInfoLldb, Mode};
40-
use test::TestPaths;
40+
use test::{TestPaths, ColorConfig};
4141
use util::logv;
4242

4343
use self::header::EarlyProps;
@@ -90,6 +90,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
9090
optopt("", "target-rustcflags", "flags to pass to rustc for target", "FLAGS"),
9191
optflag("", "verbose", "run tests verbosely, showing all output"),
9292
optflag("", "quiet", "print one character per test instead of one line"),
93+
optopt("", "color", "coloring: auto, always, never", "WHEN"),
9394
optopt("", "logfile", "file to log test execution to", "FILE"),
9495
optopt("", "target", "the target to build for", "TARGET"),
9596
optopt("", "host", "the host to build for", "HOST"),
@@ -147,6 +148,13 @@ pub fn parse_config(args: Vec<String> ) -> Config {
147148

148149
let (gdb, gdb_version, gdb_native_rust) = analyze_gdb(matches.opt_str("gdb"));
149150

151+
let color = match matches.opt_str("color").as_ref().map(|x| &**x) {
152+
Some("auto") | None => ColorConfig::AutoColor,
153+
Some("always") => ColorConfig::AlwaysColor,
154+
Some("never") => ColorConfig::NeverColor,
155+
Some(x) => panic!("argument for --color must be auto, always, or never, but found `{}`", x),
156+
};
157+
150158
Config {
151159
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
152160
run_lib_path: make_absolute(opt_path(matches, "run-lib-path")),
@@ -185,6 +193,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
185193
lldb_python_dir: matches.opt_str("lldb-python-dir"),
186194
verbose: matches.opt_present("verbose"),
187195
quiet: matches.opt_present("quiet"),
196+
color: color,
188197
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
189198

190199
cc: matches.opt_str("cc").unwrap(),
@@ -332,7 +341,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
332341
Ok(val) => &val != "0",
333342
Err(_) => false
334343
},
335-
color: test::AutoColor,
344+
color: config.color,
336345
test_threads: None,
337346
skip: vec![],
338347
list: false,

0 commit comments

Comments
 (0)