Skip to content

Commit

Permalink
Comment changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ksew1 committed Nov 18, 2024
1 parent b9666d3 commit 8b69c96
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 23 deletions.
26 changes: 14 additions & 12 deletions crates/forge-runner/src/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{env, fmt};

const BACKTRACE_ENV: &str = "SNFORGE_BACKTRACE";

pub fn add_back_trace_footer(
pub fn add_backtrace_footer(
message: String,
contracts_data: &ContractsData,
encountered_errors: &[EncounteredError],
Expand Down Expand Up @@ -137,17 +137,19 @@ impl ContractBacktraceData {
.statements_functions
.get(&sierra_statement_idx)?;

let stack = code_locations
.iter()
.zip(function_names)
.map(|(code_location, function_name)| Backtrace {
code_location,
function_name,
})
.collect();

Some(BacktraceStack {
pc,
contract_name: &self.contract_name,
origins: code_locations
.iter()
.zip(function_names)
.map(|(code_location, function_name)| Backtrace {
code_location,
function_name,
})
.collect(),
stack,
})
}
}
Expand Down Expand Up @@ -187,7 +189,7 @@ struct Backtrace<'a> {
struct BacktraceStack<'a> {
pc: usize,
contract_name: &'a str,
origins: Vec<Backtrace<'a>>,
stack: Vec<Backtrace<'a>>,
}

impl Display for Backtrace<'_> {
Expand All @@ -209,8 +211,8 @@ impl Display for BacktraceStack<'_> {
self.contract_name, self.pc
)?;
writeln!(f, "possible stack backtrace:")?;
for (i, pc_origin) in self.origins.iter().enumerate() {
writeln!(f, " {i}: {pc_origin}")?;
for (i, backtrace) in self.stack.iter().enumerate() {
writeln!(f, " {i}: {backtrace}")?;
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/forge-runner/src/running.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backtrace::add_back_trace_footer;
use crate::backtrace::add_backtrace_footer;
use crate::build_trace_data::test_sierra_program_path::VersionedProgramPath;
use crate::forge_config::{RuntimeConfig, TestRunnerConfig};
use crate::gas::calculate_used_gas;
Expand Down Expand Up @@ -314,7 +314,7 @@ fn extract_test_case_summary(
error.to_string().replace(" Custom Hint Error: ", "\n ")
))
.map(|msg| {
add_back_trace_footer(
add_backtrace_footer(
msg,
contracts_data,
&result_with_info.encountered_errors,
Expand Down
4 changes: 2 additions & 2 deletions crates/forge-runner/src/test_case_summary.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::backtrace::add_back_trace_footer;
use crate::backtrace::add_backtrace_footer;
use crate::build_trace_data::build_profiler_call_trace;
use crate::build_trace_data::test_sierra_program_path::VersionedProgramPath;
use crate::expected_result::{ExpectedPanicValue, ExpectedTestResult};
Expand Down Expand Up @@ -223,7 +223,7 @@ impl TestCaseSummary<Single> {
) -> Self {
let name = test_case.name.clone();
let msg = extract_result_data(&run_result, &test_case.config.expected_result)
.map(|msg| add_back_trace_footer(msg, contracts_data, encountered_errors));
.map(|msg| add_backtrace_footer(msg, contracts_data, encountered_errors));
match run_result.value {
RunResultValue::Success(_) => match &test_case.config.expected_result {
ExpectedTestResult::Success => {
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/tests/data/backtrace_panic/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ test = "snforge test"

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
unstable-add-statements-code-locations-debug-info = true
unstable-add-statements-code-locations-debug-info = true
2 changes: 1 addition & 1 deletion crates/forge/tests/data/backtrace_vm_error/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ test = "snforge test"

[profile.dev.cairo]
unstable-add-statements-functions-debug-info = true
unstable-add-statements-code-locations-debug-info = true
unstable-add-statements-code-locations-debug-info = true
7 changes: 2 additions & 5 deletions crates/forge/tests/e2e/backtrace.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::common::runner::{setup_package, test_runner};
use assert_fs::fixture::{FileWriteStr, PathChild};
use indoc::indoc;
use shared::test_utils::output_assert::{assert_stdout_contains, AsOutput};
use shared::test_utils::output_assert::assert_stdout_contains;
use std::fs;
use toml_edit::{value, DocumentMut};

Expand Down Expand Up @@ -60,7 +60,7 @@ fn test_backtrace() {

#[test]
#[cfg_attr(not(feature = "scarb_2_8_3"), ignore)]
fn test_wrong_configuration() {
fn test_wrong_scarb_toml_configuration() {
let temp = setup_package("backtrace_vm_error");

let manifest_path = temp.child("Scarb.toml");
Expand Down Expand Up @@ -103,9 +103,6 @@ fn test_backtrace_panic() {
.assert()
.failure();

println!("{}", output.as_stdout());
println!("{}", output.as_stderr());

assert_stdout_contains(
output,
indoc! {
Expand Down

0 comments on commit 8b69c96

Please sign in to comment.