Skip to content

Commit b9e26f1

Browse files
sfackleralexcrichton
authored andcommitted
---
yaml --- r: 152414 b: refs/heads/try2 c: 5eb4d19 h: refs/heads/master v: v3
1 parent e061f70 commit b9e26f1

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 9faf5a3483c4fc9a0d290c9dc6af006c6b76255c
8+
refs/heads/try2: 5eb4d19dc35dc59aaeaf3d53759c9b0341148ef8
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/compiletest/compiletest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
292292
save_metrics: config.save_metrics.clone(),
293293
test_shard: config.test_shard.clone(),
294294
nocapture: false,
295+
color: test::AutoColor,
295296
}
296297
}
297298

branches/try2/src/libtest/lib.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ pub fn test_main_static_x(args: &[~str], tests: &[TestDescAndFn]) {
271271
tests)
272272
}
273273

274+
pub enum ColorConfig {
275+
AutoColor,
276+
AlwaysColor,
277+
NeverColor,
278+
}
279+
274280
pub struct TestOpts {
275281
pub filter: Option<Regex>,
276282
pub run_ignored: bool,
@@ -282,6 +288,7 @@ pub struct TestOpts {
282288
pub test_shard: Option<(uint,uint)>,
283289
pub logfile: Option<Path>,
284290
pub nocapture: bool,
291+
pub color: ColorConfig,
285292
}
286293

287294
impl TestOpts {
@@ -298,6 +305,7 @@ impl TestOpts {
298305
test_shard: None,
299306
logfile: None,
300307
nocapture: false,
308+
color: AutoColor,
301309
}
302310
}
303311
}
@@ -324,7 +332,11 @@ fn optgroups() -> Vec<getopts::OptGroup> {
324332
getopts::optopt("", "test-shard", "run shard A, of B shards, worth of the testsuite",
325333
"A.B"),
326334
getopts::optflag("", "nocapture", "don't capture stdout/stderr of each \
327-
task, allow printing directly"))
335+
task, allow printing directly"),
336+
getopts::optopt("", "color", "Configure coloring of output:
337+
auto = colorize if stdout is a tty and tests are run on serially (default);
338+
always = always colorize output;
339+
never = never colorize output;", "auto|always|never"))
328340
}
329341

330342
fn usage(binary: &str) {
@@ -406,6 +418,16 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
406418
nocapture = os::getenv("RUST_TEST_NOCAPTURE").is_some();
407419
}
408420

421+
let color = match matches.opt_str("color").as_ref().map(|s| s.as_slice()) {
422+
Some("auto") | None => AutoColor,
423+
Some("always") => AlwaysColor,
424+
Some("never") => NeverColor,
425+
426+
Some(v) => return Some(Err(format!("argument for --color must be \
427+
auto, always, or never (was {})",
428+
v))),
429+
};
430+
409431
let test_opts = TestOpts {
410432
filter: filter,
411433
run_ignored: run_ignored,
@@ -417,6 +439,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
417439
test_shard: test_shard,
418440
logfile: logfile,
419441
nocapture: nocapture,
442+
color: color,
420443
};
421444

422445
Some(Ok(test_opts))
@@ -492,7 +515,7 @@ impl<T: Writer> ConsoleTestState<T> {
492515
Ok(ConsoleTestState {
493516
out: out,
494517
log_out: log_out,
495-
use_color: use_color(),
518+
use_color: use_color(opts),
496519
total: 0u,
497520
passed: 0u,
498521
failed: 0u,
@@ -867,8 +890,12 @@ fn should_sort_failures_before_printing_them() {
867890
assert!(apos < bpos);
868891
}
869892

870-
fn use_color() -> bool {
871-
get_concurrency() == 1 && io::stdout().get_ref().isatty()
893+
fn use_color(opts: &TestOpts) -> bool {
894+
match opts.color {
895+
AutoColor => get_concurrency() == 1 && io::stdout().get_ref().isatty(),
896+
AlwaysColor => true,
897+
NeverColor => false,
898+
}
872899
}
873900

874901
#[deriving(Clone)]

0 commit comments

Comments
 (0)