Skip to content

Commit 7c0a5a0

Browse files
authored
fix: only classify setUp as test setup if it has no parameters (#13204)
Contracts with `setUp(bytes memory)` (common in Gnosis Safe/Zodiac modules) were incorrectly classified as dev/test contracts and excluded from `forge build --sizes` output. Now `setUp` is only classified as a test `Setup` function when it has no parameters, matching Forge's actual test setup behavior. Fixes #11126
1 parent 0156b73 commit 7c0a5a0

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

crates/common/src/traits.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl TestFunctionKind {
175175
Self::InvariantTest
176176
}
177177
_ if name.starts_with("table") => Self::TableTest,
178-
_ if name.eq_ignore_ascii_case("setup") => Self::Setup,
178+
_ if name.eq_ignore_ascii_case("setup") && !has_inputs => Self::Setup,
179179
_ if name.eq_ignore_ascii_case("afterinvariant") => Self::AfterInvariant,
180180
_ if name.starts_with("fixture") => Self::Fixture,
181181
_ => Self::Unknown,
@@ -285,3 +285,18 @@ impl<T: std::error::Error> ErrorExt for T {
285285
alloy_sol_types::Revert::from(self.to_string()).abi_encode().into()
286286
}
287287
}
288+
289+
#[cfg(test)]
290+
mod tests {
291+
use super::*;
292+
293+
#[test]
294+
fn test_setup_classification() {
295+
// setUp() with no params should be classified as Setup
296+
assert_eq!(TestFunctionKind::classify("setUp", false), TestFunctionKind::Setup);
297+
298+
// setUp(bytes memory) with params should NOT be classified as Setup
299+
// This is common in Gnosis Safe/Zodiac modules
300+
assert_eq!(TestFunctionKind::classify("setUp", true), TestFunctionKind::Unknown);
301+
}
302+
}

0 commit comments

Comments
 (0)