Skip to content

Commit

Permalink
e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
loocapro committed Feb 9, 2024
1 parent fd3634f commit d43f28e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ etherscan_api_key = "YOURETHERSCANAPIKEY"
# known error codes are: ["unreachable", "unused-return", "unused-param", "unused-var", "code-size", "shadowing", "func-mutability", "license", "pragma-solidity", "virtual-interfaces", "same-varname"]
# additional warnings can be added using their numeric error code: ["license", 1337]
ignored_error_codes = ["license", "code-size"]
ignored_file_paths = ["path_to_ignore"]
deny_warnings = false
match_test = "Foo"
no_match_test = "Bar"
Expand Down
41 changes: 40 additions & 1 deletion crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use foundry_test_utils::{
use semver::Version;
use std::{
env, fs,
path::PathBuf,
path::{Path, PathBuf},
process::{Command, Stdio},
str::FromStr,
};
Expand Down Expand Up @@ -666,6 +666,45 @@ contract ATest is DSTest {
}
);

// test that `forge build` does not print `(with warnings)` if file path is ignored
forgetest!(can_compile_without_warnings_ignored_file_paths, |prj, cmd| {
let create_config =
|ignored_file_paths: Vec<PathBuf>, ignored_error_codes: Vec<SolidityErrorCode>| -> Config {
Config { ignored_file_paths, ignored_error_codes, ..Default::default() }
};

// Ignoring path and setting empty error_codes as default would set SpdxLicenseNotProvided
let config_with_ignored_paths = create_config(vec![Path::new("src").to_path_buf()], vec![]);
prj.write_config(config_with_ignored_paths);

prj.add_raw_source(
"src/example.sol",
r"
pragma solidity *;
contract A {
function testExample() public {}
}
",
)
.unwrap();

// Build and check for no warnings
cmd.args(["build", "--force"]);
let out = cmd.stdout_lossy();
// expect no warning as path is ignored
assert!(out.contains("Compiler run successful!"));
assert!(!out.contains("Compiler run successful with warnings:"));

// Reconfigure without ignored paths or error codes and check for warnings
let config_no_ignored = create_config(vec![], vec![]);
prj.write_config(config_no_ignored);

let out = cmd.stdout_lossy();
// expect warnings as path is not ignored
assert!(out.contains("Compiler run successful with warnings:"), "{out}");
assert!(out.contains("Warning") && out.contains("SPDX-License-Identifier"), "{out}");
});

// test that `forge build` does not print `(with warnings)` if there arent any
forgetest!(can_compile_without_warnings, |prj, cmd| {
let config = Config {
Expand Down

0 comments on commit d43f28e

Please sign in to comment.