Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 8 additions & 22 deletions crates/common/src/compile.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
//! Support for compiling [foundry_compilers::Project]

use crate::{
TestFunctionExt,
preprocessor::DynamicTestLinkingPreprocessor,
reports::{ReportKind, report_kind},
shell,
term::SpinnerReporter,
TestFunctionExt, preprocessor::DynamicTestLinkingPreprocessor, shell, term::SpinnerReporter,
};
use comfy_table::{Cell, Color, Table, modifiers::UTF8_ROUND_CORNERS, presets::ASCII_MARKDOWN};
use eyre::Result;
Expand Down Expand Up @@ -277,8 +273,7 @@ impl ProjectCompiler {
sh_println!()?;
}

let mut size_report =
SizeReport { report_kind: report_kind(), contracts: BTreeMap::new() };
let mut size_report = SizeReport { contracts: BTreeMap::new() };

let mut artifacts: BTreeMap<String, Vec<_>> = BTreeMap::new();
for (id, artifact) in output.artifact_ids().filter(|(id, _)| {
Expand Down Expand Up @@ -348,8 +343,6 @@ const CONTRACT_INITCODE_SIZE_LIMIT: usize = 49152;

/// Contracts with info about their size
pub struct SizeReport {
/// What kind of report to generate.
report_kind: ReportKind,
/// `contract name -> info`
pub contracts: BTreeMap<String, ContractInfo>,
}
Expand Down Expand Up @@ -388,18 +381,11 @@ impl SizeReport {

impl Display for SizeReport {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self.report_kind {
ReportKind::Text => {
writeln!(f, "\n{}", self.format_table_output(false))?;
}
ReportKind::JSON => {
writeln!(f, "{}", self.format_json_output())?;
}
ReportKind::Markdown => {
writeln!(f, "\n{}", self.format_table_output(true))?;
}
if shell::is_json() {
writeln!(f, "{}", self.format_json_output())?;
} else {
writeln!(f, "\n{}", self.format_table_output())?;
}

Ok(())
}
}
Expand All @@ -426,9 +412,9 @@ impl SizeReport {
serde_json::to_string(&contracts).unwrap()
}

fn format_table_output(&self, md: bool) -> Table {
fn format_table_output(&self) -> Table {
let mut table = Table::new();
if md {
if shell::is_markdown() {
table.load_preset(ASCII_MARKDOWN);
} else {
table.apply_modifier(UTF8_ROUND_CORNERS);
Expand Down
1 change: 0 additions & 1 deletion crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub mod fs;
pub mod mapping_slots;
mod preprocessor;
pub mod provider;
pub mod reports;
pub mod retry;
pub mod selectors;
pub mod serde_helpers;
Expand Down
22 changes: 0 additions & 22 deletions crates/common/src/reports.rs

This file was deleted.

36 changes: 8 additions & 28 deletions crates/forge/src/cmd/test/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ use crate::cmd::test::TestOutcome;
use comfy_table::{
Cell, Color, Row, Table, modifiers::UTF8_ROUND_CORNERS, presets::ASCII_MARKDOWN,
};
use foundry_common::{
reports::{ReportKind, report_kind},
shell,
};
use foundry_common::shell;
use foundry_evm::executors::invariant::InvariantMetrics;
use itertools::Itertools;
use serde_json::json;
use std::{collections::HashMap, fmt::Display};

/// Represents a test summary report.
pub struct TestSummaryReport {
/// The kind of report to generate.
report_kind: ReportKind,
/// Whether the report should be detailed.
is_detailed: bool,
/// The test outcome to report.
Expand All @@ -23,32 +18,17 @@ pub struct TestSummaryReport {

impl TestSummaryReport {
pub fn new(is_detailed: bool, outcome: TestOutcome) -> Self {
Self { report_kind: report_kind(), is_detailed, outcome }
Self { is_detailed, outcome }
}
}

impl Display for TestSummaryReport {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self.report_kind {
ReportKind::Text => {
writeln!(
f,
"\n{}",
&self.format_table_output(&self.is_detailed, &self.outcome, false)
)?;
}
ReportKind::JSON => {
writeln!(f, "{}", &self.format_json_output(&self.is_detailed, &self.outcome))?;
}
ReportKind::Markdown => {
writeln!(
f,
"\n{}",
&self.format_table_output(&self.is_detailed, &self.outcome, true)
)?;
}
if shell::is_json() {
writeln!(f, "{}", &self.format_json_output(&self.is_detailed, &self.outcome))?;
} else {
writeln!(f, "\n{}", &self.format_table_output(&self.is_detailed, &self.outcome))?;
}

Ok(())
}
}
Expand Down Expand Up @@ -81,9 +61,9 @@ impl TestSummaryReport {
serde_json::to_string_pretty(&output).unwrap()
}

fn format_table_output(&self, is_detailed: &bool, outcome: &TestOutcome, md: bool) -> Table {
fn format_table_output(&self, is_detailed: &bool, outcome: &TestOutcome) -> Table {
let mut table = Table::new();
if md {
if shell::is_markdown() {
table.load_preset(ASCII_MARKDOWN);
} else {
table.apply_modifier(UTF8_ROUND_CORNERS);
Expand Down
52 changes: 13 additions & 39 deletions crates/forge/src/gas_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use crate::{
};
use alloy_primitives::map::HashSet;
use comfy_table::{Cell, Color, Table, modifiers::UTF8_ROUND_CORNERS, presets::ASCII_MARKDOWN};
use foundry_common::{
TestFunctionExt, calc,
reports::{ReportKind, report_kind},
};
use foundry_common::{TestFunctionExt, calc, shell};
use foundry_evm::traces::CallKind;

use serde::{Deserialize, Serialize};
Expand All @@ -21,8 +18,6 @@ use std::{collections::BTreeMap, fmt::Display};
pub struct GasReport {
/// Whether to report any contracts.
report_any: bool,
/// What kind of report to generate.
report_kind: ReportKind,
/// Contracts to generate the report for.
report_for: HashSet<String>,
/// Contracts to ignore when generating the report.
Expand All @@ -43,14 +38,7 @@ impl GasReport {
let report_for = report_for.into_iter().collect::<HashSet<_>>();
let ignore = ignore.into_iter().collect::<HashSet<_>>();
let report_any = report_for.is_empty() || report_for.contains("*");
Self {
report_any,
report_kind: report_kind(),
report_for,
ignore,
include_tests,
..Default::default()
}
Self { report_any, report_for, ignore, include_tests, ..Default::default() }
}

/// Whether the given contract should be reported.
Expand Down Expand Up @@ -155,31 +143,17 @@ impl GasReport {

impl Display for GasReport {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self.report_kind {
ReportKind::Text => {
for (name, contract) in &self.contracts {
if contract.functions.is_empty() {
trace!(name, "gas report contract without functions");
continue;
}

let table = self.format_table_output(contract, name, false);
writeln!(f, "\n{table}")?;
if shell::is_json() {
writeln!(f, "{}", &self.format_json_output())?;
} else {
for (name, contract) in &self.contracts {
if contract.functions.is_empty() {
trace!(name, "gas report contract without functions");
continue;
}
}
ReportKind::JSON => {
writeln!(f, "{}", &self.format_json_output())?;
}
ReportKind::Markdown => {
for (name, contract) in &self.contracts {
if contract.functions.is_empty() {
trace!(name, "gas report contract without functions");
continue;
}

let table = self.format_table_output(contract, name, true);
writeln!(f, "\n{table}")?;
}
let table = self.format_table_output(contract, name);
writeln!(f, "\n{table}")?;
}
}

Expand Down Expand Up @@ -224,9 +198,9 @@ impl GasReport {
.unwrap()
}

fn format_table_output(&self, contract: &ContractInfo, name: &str, md: bool) -> Table {
fn format_table_output(&self, contract: &ContractInfo, name: &str) -> Table {
let mut table = Table::new();
if md {
if shell::is_markdown() {
table.load_preset(ASCII_MARKDOWN);
} else {
table.apply_modifier(UTF8_ROUND_CORNERS);
Expand Down
Loading