foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Fixes #7350. Added support for absolute paths for "forge test --match-path"

Open matthewliu10 opened this issue 11 months ago • 7 comments

Motivation

Related to #7350 .

forge test --match-path absolute_path will report No tests match the provided pattern, only relative path works.

--match-path should work for both absolute path and relative path.

Solution

If the path given by the user is absolute, and the path given to the function is relative, it uses the canonicalize() function to turn the path given to the function into an absolute path so that the paths can be compared.

Notes

I initially tried converting both paths into their canonical forms using canonicalize and directly comparing them, however this failed on the can_test_with_match_path test because it would attempt to canonicalize "*src/ATest.t.sol" which causes an error.

There may be cases where the paths refer to the same location but is_match() still returns false. For example, if the user inputs "/home/user/a/b/../..//c/", it may not match with "/home/user/c/" even though they are equivalent. Note: canonicalize() resolves any symbolic links, relative path components, and removes any redundant components in the path.

Tests

The following 5 tests fail when running cargo test --all --all-features:

cmd::can_install_missing_deps_build cmd::can_install_missing_deps_test cmd::can_update_library_with_outdated_nested_dependency config::can_parse_default_fs_permissions ext_integration::snekmate

However, the following 4 tests still failed when I reverted the changes that I made (reverted code to the original code that I pulled from the repo):

cmd::can_install_missing_deps_build cmd::can_install_missing_deps_test cmd::can_update_library_with_outdated_nested_dependency ext_integration::snekmate

The following test failed when I ran cargo test --all --all-features, but passed when I ran it individually:

config::can_parse_default_fs_permissions

matthewliu10 avatar Mar 11 '24 14:03 matthewliu10