Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): inline config intermingled #7496

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
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
51 changes: 49 additions & 2 deletions crates/config/src/inline/natspec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,13 @@ impl SolangParser {
}

let Ok((pt, comments)) = solang_parser::parse(src, 0) else { return };
let mut prev_end = 0;
for item in &pt.0 {
let pt::SourceUnitPart::ContractDefinition(c) = item else { continue };
let Some(id) = c.name.as_ref() else { continue };
if id.name != contract_name {
continue
};
let mut prev_end = c.loc.start();
for part in &c.parts {
let pt::ContractPart::FunctionDefinition(f) = part else { continue };
let start = f.loc.start();
Expand All @@ -215,7 +215,6 @@ impl SolangParser {
}
prev_end = f.loc.end();
}
prev_end = c.loc.end();
}
}
}
Expand Down Expand Up @@ -401,4 +400,52 @@ contract FuzzInlineConf is DSTest {
docs: conf.to_string(),
}
}

#[test]
fn parse_solang_multiple_contracts_from_same_file() {
let src = r#"
// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity >=0.8.0;

import "ds-test/test.sol";

contract FuzzInlineConf is DSTest {
/// forge-config: default.fuzz.runs = 1
function testInlineConfFuzz1() {}
}

contract FuzzInlineConf2 is DSTest {
/// forge-config: default.fuzz.runs = 2
function testInlineConfFuzz2() {}
}
"#;
let mut natspecs = vec![];
let solang = SolangParser::new();
let id = || "inline/FuzzInlineConf.t.sol:FuzzInlineConf".to_string();
let default_line = || "0:0:0".to_string();
solang.parse(&mut natspecs, src, &id(), "FuzzInlineConf");
assert_eq!(
natspecs,
[NatSpec {
contract: id(),
function: "testInlineConfFuzz1".to_string(),
line: default_line(),
docs: "forge-config: default.fuzz.runs = 1".to_string(),
},]
);

let mut natspecs = vec![];
let id = || "inline/FuzzInlineConf2.t.sol:FuzzInlineConf2".to_string();
solang.parse(&mut natspecs, src, &id(), "FuzzInlineConf2");
assert_eq!(
natspecs,
[NatSpec {
contract: id(),
function: "testInlineConfFuzz2".to_string(),
line: default_line(),
// should not get config from previous contract
docs: "forge-config: default.fuzz.runs = 2".to_string(),
},]
);
}
}
Loading