Skip to content

Commit

Permalink
Auto merge of #7607 - ehuss:fwdansi-hack, r=alexcrichton
Browse files Browse the repository at this point in the history
Add hack for fwdansi change.

This is a hack to fix a test failing on CI.

The issue is that fwdansi 1.1 was published with a change on how it processes reset codes. I have filed kennytm/fwdansi#2 with some details on some of the issues.

This is just a workaround to get the test to pass.  I'm not too happy with it, but other choices seemed less than ideal.  Am happy to consider them, though:

- Remove fwdansi, and give up supporting color on Win 7/8, old 10.
- Change `Shell` so that it knows whether or not the console supports ANSI, and only use fwdansi when necessary.  This means Win 10 would stop using fwdansi, but 7/8 would continue to use it. It is a little awkward – I think it would have to call wincolor::set_virtual_terminal_processing and see if it succeeds.
- Wait for a change to fwdansi to make resets more transparent.

I am very tempted by the first choice.  rustc's color output has been broken on win 7/8 for a long time, and only a very small number of people have complained.  I have spent way too much time dealing with something I think nobody really uses.

cc @kennytm
  • Loading branch information
bors committed Nov 19, 2019
2 parents e55600b + 8149c7f commit 776ba5f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/testsuite/cache_messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ fn color() {
// Check enabling/disabling color.
let p = project().file("src/lib.rs", "fn a() {}").build();

// Hack for issue in fwdansi 1.1. It is squashing multiple resets
// into a single reset.
// https://github.com/kennytm/fwdansi/issues/2
fn normalize(s: &str) -> String {
#[cfg(windows)]
return s.replace("\x1b[0m\x1b[0m", "\x1b[0m");
#[cfg(not(windows))]
return s.to_string();
};

let compare = |a, b| {
assert_eq!(normalize(a), normalize(b));
};

let agnostic_path = Path::new("src").join("lib.rs");
let agnostic_path_s = agnostic_path.to_str().unwrap();
// Capture the original color output.
Expand All @@ -121,21 +135,21 @@ fn color() {
.cargo("check -q --color=always")
.exec_with_output()
.expect("cargo to run");
assert_eq!(rustc_color, as_str(&cargo_output1.stderr));
compare(rustc_color, as_str(&cargo_output1.stderr));

// Replay cached, with color.
let cargo_output2 = p
.cargo("check -q --color=always")
.exec_with_output()
.expect("cargo to run");
assert_eq!(rustc_color, as_str(&cargo_output2.stderr));
compare(rustc_color, as_str(&cargo_output2.stderr));

// Replay cached, no color.
let cargo_output_nocolor = p
.cargo("check -q --color=never")
.exec_with_output()
.expect("cargo to run");
assert_eq!(rustc_nocolor, as_str(&cargo_output_nocolor.stderr));
compare(rustc_nocolor, as_str(&cargo_output_nocolor.stderr));
}

#[cargo_test]
Expand Down

0 comments on commit 776ba5f

Please sign in to comment.