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

test: modify some flaky tests #7293

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 2 additions & 16 deletions crates/forge/tests/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ contract Dummy {
// tests build output is as expected
forgetest_init!(exact_build_output, |prj, cmd| {
cmd.args(["build", "--force"]);
let (stdout, _) = cmd.unchecked_output_lossy();
// Expected output from build
let expected = r#"Compiling 24 files with 0.8.23
Solc 0.8.23 finished in 2.36s
Compiler run successful!
"#;

// skip all dynamic parts of the output (numbers)
let expected_words =
expected.split(|c: char| c == ' ').filter(|w| !w.chars().next().unwrap().is_numeric());
let output_words =
stdout.split(|c: char| c == ' ').filter(|w| !w.chars().next().unwrap().is_numeric());

for (expected, output) in expected_words.zip(output_words) {
assert_eq!(expected, output, "expected: {}, output: {}", expected, output);
}
let stdout = cmd.stdout_lossy();
assert!(stdout.contains("Compiling"), "\n{stdout}");
});
5 changes: 2 additions & 3 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ forgetest_init!(can_install_missing_deps_build, |prj, cmd| {

// checks that extra output works
forgetest_init!(can_build_skip_contracts, |prj, cmd| {
prj.clear_cache();
prj.clear();

// only builds the single template contract `src/*`
cmd.args(["build", "--skip", "tests", "--skip", "scripts"]);
Expand All @@ -1573,8 +1573,6 @@ forgetest_init!(can_build_skip_contracts, |prj, cmd| {
});

forgetest_init!(can_build_skip_glob, |prj, cmd| {
prj.clear_cache();

prj.add_test(
"Foo",
r"
Expand All @@ -1585,6 +1583,7 @@ function test_run() external {}
.unwrap();

// only builds the single template contract `src/*` even if `*.t.sol` or `.s.sol` is absent
prj.clear();
cmd.args(["build", "--skip", "*/test/**", "--skip", "*/script/**"]);
cmd.unchecked_output().stdout_matches_path(
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/can_build_skip_glob.stdout"),
Expand Down
6 changes: 6 additions & 0 deletions crates/test-utils/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ impl TestProject {
&self.paths().artifacts
}

/// Removes the project's cache and artifacts directory.
pub fn clear(&self) {
self.clear_cache();
self.clear_artifacts();
}

/// Removes this project's cache file.
pub fn clear_cache(&self) {
let _ = fs::remove_file(self.cache());
Expand Down
Loading