Skip to content

Commit 5b4a105

Browse files
authored
fix: propagate color config to TraceWriter (#9679)
1 parent 017c59d commit 5b4a105

File tree

6 files changed

+143
-1
lines changed

6 files changed

+143
-1
lines changed

Cargo.lock

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/common/src/io/shell.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ use std::{
1818
},
1919
};
2020

21+
/// Returns the current color choice.
22+
pub fn color_choice() -> ColorChoice {
23+
Shell::get().color_choice()
24+
}
25+
2126
/// Returns the currently set verbosity level.
2227
pub fn verbosity() -> Verbosity {
2328
Shell::get().verbosity()

crates/evm/traces/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,22 @@ pub fn render_trace_arena_inner(
201201
}
202202

203203
let mut w = TraceWriter::new(Vec::<u8>::new())
204+
.color_cheatcodes(true)
205+
.use_colors(convert_color_choice(shell::color_choice()))
204206
.write_bytecodes(with_bytecodes)
205207
.with_storage_changes(with_storage_changes);
206208
w.write_arena(&arena.resolve_arena()).expect("Failed to write traces");
207209
String::from_utf8(w.into_writer()).expect("trace writer wrote invalid UTF-8")
208210
}
209211

212+
fn convert_color_choice(choice: shell::ColorChoice) -> revm_inspectors::ColorChoice {
213+
match choice {
214+
shell::ColorChoice::Auto => revm_inspectors::ColorChoice::Auto,
215+
shell::ColorChoice::Always => revm_inspectors::ColorChoice::Always,
216+
shell::ColorChoice::Never => revm_inspectors::ColorChoice::Never,
217+
}
218+
}
219+
210220
/// Specifies the kind of trace.
211221
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
212222
pub enum TraceKind {

crates/forge/tests/cli/test_cmd.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,3 +2829,10 @@ forgetest!(test_fail_deprecation_warning, |prj, cmd| {
28292829
.stderr_eq(r#"Warning: `testFail*` has been deprecated and will be removed in the next release. Consider changing to test_Revert[If|When]_Condition and expecting a revert. Found deprecated testFail* function(s): testFail_deprecated, testFail_deprecated2.
28302830
"#);
28312831
});
2832+
2833+
#[cfg(not(feature = "isolate-by-default"))]
2834+
forgetest_init!(colored_traces, |prj, cmd| {
2835+
cmd.args(["test", "--mt", "test_Increment", "--color", "always", "-vvvvv"])
2836+
.assert_success()
2837+
.stdout_eq(file!["../fixtures/colored_traces.svg": TermSvg]);
2838+
});
Lines changed: 82 additions & 0 deletions
Loading

crates/test-utils/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ serde_json.workspace = true
3030
tracing.workspace = true
3131
tracing-subscriber = { workspace = true, features = ["env-filter"] }
3232
rand.workspace = true
33-
snapbox = { version = "0.6", features = ["json", "regex"] }
33+
snapbox = { version = "0.6", features = ["json", "regex", "term-svg"] }
3434
tempfile.workspace = true
3535

3636
[dev-dependencies]

0 commit comments

Comments
 (0)