Compare commits

...

1 Commits

Author SHA1 Message Date
Charlie Marsh
fb7091cc51 Retain colored output in mdtest failures 2024-10-28 22:10:36 -04:00
13 changed files with 70 additions and 56 deletions

19
Cargo.lock generated
View File

@@ -75,15 +75,16 @@ dependencies = [
[[package]]
name = "anstream"
version = "0.6.13"
version = "0.6.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
checksum = "23a1e53f0f5d86382dafe1cf314783b2044280f406e7e1506368220ad11b1338"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
@@ -113,12 +114,12 @@ dependencies = [
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]
@@ -1291,6 +1292,12 @@ dependencies = [
"once_cell",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itertools"
version = "0.10.5"
@@ -2308,6 +2315,7 @@ dependencies = [
name = "ruff"
version = "0.7.1"
dependencies = [
"anstream",
"anyhow",
"argfile",
"assert_fs",
@@ -2527,6 +2535,7 @@ version = "0.7.1"
dependencies = [
"aho-corasick",
"annotate-snippets 0.9.2",
"anstream",
"anyhow",
"bitflags 2.6.0",
"chrono",

View File

@@ -44,6 +44,7 @@ red_knot_workspace = { path = "crates/red_knot_workspace", default-features = fa
aho-corasick = { version = "1.1.3" }
annotate-snippets = { version = "0.9.2", features = ["color"] }
anstream = { version = "0.6.17" }
anyhow = { version = "1.0.80" }
assert_fs = { version = "1.1.0" }
argfile = { version = "0.2.0" }

View File

@@ -63,9 +63,9 @@ wild = { workspace = true }
# Enable test rules during development
ruff_linter = { workspace = true, features = ["clap", "test-rules"] }
anstream = { workspace = true }
assert_fs = { workspace = true }
# Avoid writing colored snapshots when running tests from the terminal
colored = { workspace = true, features = ["no-color"] }
colored = { workspace = true }
indoc = { workspace = true }
insta = { workspace = true, features = ["filters", "json"] }
insta-cmd = { workspace = true }

View File

@@ -277,18 +277,19 @@ mod test {
UnsafeFixes::Enabled,
)
.unwrap();
let mut output = Vec::new();
let mut writer = anstream::StripStream::new(Vec::new());
TextEmitter::default()
.with_show_fix_status(true)
.emit(
&mut output,
&mut writer,
&diagnostics.messages,
&EmitterContext::new(&FxHashMap::default()),
)
.unwrap();
let messages = String::from_utf8(output).unwrap();
let messages = String::from_utf8(writer.into_inner()).unwrap();
insta::with_settings!({
omit_expression => true,

View File

@@ -47,8 +47,8 @@ log = { workspace = true }
memchr = { workspace = true }
natord = { workspace = true }
path-absolutize = { workspace = true, features = [
"once_cell_cache",
"use_unix_paths_on_wasm",
"once_cell_cache",
"use_unix_paths_on_wasm",
] }
pathdiff = { workspace = true }
pep440_rs = { workspace = true }
@@ -72,10 +72,13 @@ unicode-normalization = { workspace = true }
url = { workspace = true }
[dev-dependencies]
anstream = { version = "0.6.17" }
colored = { workspace = true }
insta = { workspace = true, features = ["filters", "json", "redactions"] }
test-case = { workspace = true }
# Disable colored output in tests
colored = { workspace = true, features = ["no-color"] }
[target.'cfg(fuzzing)'.dependencies]
anstream = { version = "0.6.17" }
[features]
default = []

View File

@@ -513,10 +513,10 @@ def foo():
) -> String {
let notebook_indexes = FxHashMap::default();
let context = EmitterContext::new(&notebook_indexes);
let mut output: Vec<u8> = Vec::new();
emitter.emit(&mut output, messages, &context).unwrap();
let mut writer = anstream::StripStream::new(Vec::new());
emitter.emit(&mut writer, messages, &context).unwrap();
String::from_utf8(output).expect("Output to be valid UTF-8")
String::from_utf8(writer.into_inner()).expect("Output to be valid UTF-8")
}
pub(super) fn capture_emitter_notebook_output(
@@ -525,9 +525,9 @@ def foo():
notebook_indexes: &FxHashMap<String, NotebookIndex>,
) -> String {
let context = EmitterContext::new(notebook_indexes);
let mut output: Vec<u8> = Vec::new();
emitter.emit(&mut output, messages, &context).unwrap();
let mut writer = anstream::StripStream::new(Vec::new());
emitter.emit(&mut writer, messages, &context).unwrap();
String::from_utf8(output).expect("Output to be valid UTF-8")
String::from_utf8(writer.into_inner()).expect("Output to be valid UTF-8")
}
}

View File

@@ -46,7 +46,7 @@ invalid_characters.py:55:21: PLE2510 [*] Invalid unescaped character backspace,
|
53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
54 |
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
| ^ PLE2510
56 |
57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
@@ -57,8 +57,8 @@ invalid_characters.py:55:21: PLE2510 [*] Invalid unescaped character backspace,
52 52 | zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ "
53 53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
54 54 |
55 |-nested_fstrings = f'␈{f'{f'␛'}'}'
55 |+nested_fstrings = f'\b{f'{f'␛'}'}'
55 |-nested_fstrings = f'␈{f'{f'␛'}'}'
55 |+nested_fstrings = f'\b{f'{f'␛'}'}'
56 56 |
57 57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
58 58 | x = f"""}}ab"""
58 58 | x = f"""}}ab"""

View File

@@ -5,9 +5,9 @@ invalid_characters.py:24:12: PLE2512 [*] Invalid unescaped character SUB, use "\
|
22 | cr_ok = f'\\r'
23 |
24 | sub = 'sub '
24 | sub = 'sub '
| PLE2512
25 | sub = f'sub '
25 | sub = f'sub '
|
= help: Replace with escape sequence
@@ -15,16 +15,16 @@ invalid_characters.py:24:12: PLE2512 [*] Invalid unescaped character SUB, use "\
21 21 | cr_ok = '\\r'
22 22 | cr_ok = f'\\r'
23 23 |
24 |-sub = 'sub '
24 |-sub = 'sub '
24 |+sub = 'sub \x1A'
25 25 | sub = f'sub '
25 25 | sub = f'sub '
26 26 |
27 27 | sub_ok = '\x1a'
invalid_characters.py:25:13: PLE2512 [*] Invalid unescaped character SUB, use "\x1A" instead
|
24 | sub = 'sub '
25 | sub = f'sub '
24 | sub = 'sub '
25 | sub = f'sub '
| PLE2512
26 |
27 | sub_ok = '\x1a'
@@ -34,8 +34,8 @@ invalid_characters.py:25:13: PLE2512 [*] Invalid unescaped character SUB, use "\
Safe fix
22 22 | cr_ok = f'\\r'
23 23 |
24 24 | sub = 'sub '
25 |-sub = f'sub '
24 24 | sub = 'sub '
25 |-sub = f'sub '
25 |+sub = f'sub \x1A'
26 26 |
27 27 | sub_ok = '\x1a'
@@ -45,7 +45,7 @@ invalid_characters.py:55:25: PLE2512 [*] Invalid unescaped character SUB, use "\
|
53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
54 |
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
| PLE2512
56 |
57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
@@ -56,16 +56,16 @@ invalid_characters.py:55:25: PLE2512 [*] Invalid unescaped character SUB, use "\
52 52 | zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ "
53 53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
54 54 |
55 |-nested_fstrings = f'␈{f'{f'␛'}'}'
55 |-nested_fstrings = f'␈{f'{f'␛'}'}'
55 |+nested_fstrings = f'␈{f'\x1A{f'␛'}'}'
56 56 |
57 57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
58 58 | x = f"""}}ab"""
58 58 | x = f"""}}ab"""
invalid_characters.py:58:12: PLE2512 [*] Invalid unescaped character SUB, use "\x1A" instead
|
57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
58 | x = f"""}}ab"""
58 | x = f"""}}ab"""
| PLE2512
59 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998256
60 | x = f"""}}a␛b"""
@@ -73,10 +73,10 @@ invalid_characters.py:58:12: PLE2512 [*] Invalid unescaped character SUB, use "\
= help: Replace with escape sequence
Safe fix
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
56 56 |
57 57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
58 |-x = f"""}}ab"""
58 |-x = f"""}}ab"""
58 |+x = f"""}}a\x1Ab"""
59 59 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998256
60 60 | x = f"""}}a␛b"""

View File

@@ -45,7 +45,7 @@ invalid_characters.py:55:29: PLE2513 [*] Invalid unescaped character ESC, use "\
|
53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
54 |
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
| ^ PLE2513
56 |
57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
@@ -56,15 +56,15 @@ invalid_characters.py:55:29: PLE2513 [*] Invalid unescaped character ESC, use "\
52 52 | zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ "
53 53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
54 54 |
55 |-nested_fstrings = f'␈{f'{f'␛'}'}'
55 |+nested_fstrings = f'␈{f'{f'\x1B'}'}'
55 |-nested_fstrings = f'␈{f'{f'␛'}'}'
55 |+nested_fstrings = f'␈{f'{f'\x1B'}'}'
56 56 |
57 57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
58 58 | x = f"""}}ab"""
58 58 | x = f"""}}ab"""
invalid_characters.py:60:12: PLE2513 [*] Invalid unescaped character ESC, use "\x1B" instead
|
58 | x = f"""}}ab"""
58 | x = f"""}}ab"""
59 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998256
60 | x = f"""}}a␛b"""
| ^ PLE2513
@@ -73,7 +73,7 @@ invalid_characters.py:60:12: PLE2513 [*] Invalid unescaped character ESC, use "\
Safe fix
57 57 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998106
58 58 | x = f"""}}ab"""
58 58 | x = f"""}}ab"""
59 59 | # https://github.com/astral-sh/ruff/issues/7455#issuecomment-1741998256
60 |-x = f"""}}a␛b"""
60 |+x = f"""}}a\x1Bb"""

View File

@@ -100,7 +100,7 @@ invalid_characters.py:52:60: PLE2515 [*] Invalid unescaped character zero-width-
52 |+zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ \u200b"
53 53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
54 54 |
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
invalid_characters.py:52:61: PLE2515 [*] Invalid unescaped character zero-width-space, use "\u200B" instead
|
@@ -120,7 +120,7 @@ invalid_characters.py:52:61: PLE2515 [*] Invalid unescaped character zero-width-
52 |+zwsp_after_multicharacter_grapheme_cluster = "ಫ್ರಾನ್ಸಿಸ್ಕೊ \u200b"
53 53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
54 54 |
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
invalid_characters.py:53:61: PLE2515 [*] Invalid unescaped character zero-width-space, use "\u200B" instead
|
@@ -129,7 +129,7 @@ invalid_characters.py:53:61: PLE2515 [*] Invalid unescaped character zero-width-
53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
| PLE2515
54 |
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
|
= help: Replace with escape sequence
@@ -140,7 +140,7 @@ invalid_characters.py:53:61: PLE2515 [*] Invalid unescaped character zero-width-
53 |-zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
53 |+zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ \u200b"
54 54 |
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
56 56 |
invalid_characters.py:53:62: PLE2515 [*] Invalid unescaped character zero-width-space, use "\u200B" instead
@@ -150,7 +150,7 @@ invalid_characters.py:53:62: PLE2515 [*] Invalid unescaped character zero-width-
53 | zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
| PLE2515
54 |
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 | nested_fstrings = f'␈{f'{f'␛'}'}'
|
= help: Replace with escape sequence
@@ -161,5 +161,5 @@ invalid_characters.py:53:62: PLE2515 [*] Invalid unescaped character zero-width-
53 |-zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ "
53 |+zwsp_after_multicharacter_grapheme_cluster = f"ಫ್ರಾನ್ಸಿಸ್ಕೊ \u200b"
54 54 |
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
55 55 | nested_fstrings = f'␈{f'{f'␛'}'}'
56 56 |

View File

@@ -325,7 +325,7 @@ pub(crate) fn print_jupyter_messages(
path: &Path,
notebook: &Notebook,
) -> String {
let mut output = Vec::new();
let mut writer = anstream::StripStream::new(Vec::new());
TextEmitter::default()
.with_show_fix_status(true)
@@ -333,7 +333,7 @@ pub(crate) fn print_jupyter_messages(
.with_show_source(true)
.with_unsafe_fixes(UnsafeFixes::Enabled)
.emit(
&mut output,
&mut writer,
messages,
&EmitterContext::new(&FxHashMap::from_iter([(
path.file_name().unwrap().to_string_lossy().to_string(),
@@ -342,11 +342,11 @@ pub(crate) fn print_jupyter_messages(
)
.unwrap();
String::from_utf8(output).unwrap()
String::from_utf8(writer.into_inner()).unwrap()
}
pub(crate) fn print_messages(messages: &[Message]) -> String {
let mut output = Vec::new();
let mut writer = anstream::StripStream::new(Vec::new());
TextEmitter::default()
.with_show_fix_status(true)
@@ -354,13 +354,13 @@ pub(crate) fn print_messages(messages: &[Message]) -> String {
.with_show_source(true)
.with_unsafe_fixes(UnsafeFixes::Enabled)
.emit(
&mut output,
&mut writer,
messages,
&EmitterContext::new(&FxHashMap::default()),
)
.unwrap();
String::from_utf8(output).unwrap()
String::from_utf8(writer.into_inner()).unwrap()
}
#[macro_export]