diff --git a/src/spec/mod.rs b/src/spec/mod.rs index 97632b8..b65ab63 100644 --- a/src/spec/mod.rs +++ b/src/spec/mod.rs @@ -41,6 +41,11 @@ pub fn run() -> Result<(), Box> { // contract contains that source method's tests/specification. let mut protocol_spec = ProtocolSpecification::new(); for src_contract in src_contracts { + // Skip contracts with no functions - they have nothing to specify + if src_contract.functions.is_empty() { + continue; + } + let mut contract_specification = ContractSpecification::new(src_contract.clone()); let src_contract_name = src_contract.contract.unwrap().name.unwrap().name; @@ -114,6 +119,7 @@ impl ContractSpecification { // which is the order we want to print in. let src_fns = &self.src_contract.functions; let num_src_fns = src_fns.len(); + for (i, src_fn) in src_fns.iter().enumerate() { let src_fn_name_prefix = if i == num_src_fns - 1 { "└── " } else { "├── " }; diff --git a/tests/spec-proj2-EmptyContract/foundry.toml b/tests/spec-proj2-EmptyContract/foundry.toml new file mode 100644 index 0000000..a9fd641 --- /dev/null +++ b/tests/spec-proj2-EmptyContract/foundry.toml @@ -0,0 +1,8 @@ +[profile.default] +src = "src" +out = "out" +libs = ["lib"] +solc_version = "0.8.19" +optimizer = true +optimizer_runs = 200 +via_ir = false \ No newline at end of file diff --git a/tests/spec-proj2-EmptyContract/src/EmptyContract.sol b/tests/spec-proj2-EmptyContract/src/EmptyContract.sol new file mode 100644 index 0000000..736ee26 --- /dev/null +++ b/tests/spec-proj2-EmptyContract/src/EmptyContract.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +contract EmptyContract { + // This contract has no functions + uint256 public someVariable; +} \ No newline at end of file diff --git a/tests/spec.rs b/tests/spec.rs index e14dcfc..07ce486 100644 --- a/tests/spec.rs +++ b/tests/spec.rs @@ -50,3 +50,12 @@ Contract Specification: ERC20 "#; assert_eq!(stdout, expected_spec); } + +#[test] +fn test_spec_proj2_empty_contract() { + let output = run_scopelint("spec-proj2-EmptyContract"); + let stdout = String::from_utf8(output.stdout).unwrap(); + // Empty contracts should be ignored and produce no output + let expected_spec = ""; + assert_eq!(stdout, expected_spec); +}