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

Document --match-path and --no-match-path for forge test #50

Closed
onbjerg opened this issue Feb 23, 2022 · 3 comments · Fixed by #61
Closed

Document --match-path and --no-match-path for forge test #50

onbjerg opened this issue Feb 23, 2022 · 3 comments · Fixed by #61
Labels
A-forge Area: forge good first issue Good for newcomers T-new Type: new docs

Comments

@onbjerg
Copy link
Member

onbjerg commented Feb 23, 2022

See foundry-rs/foundry#662

The relevant file this should be updated in is ./src/forge/tests.md

@onbjerg onbjerg added T-enhancement Type: enhance existing docs good first issue Good for newcomers A-forge Area: forge T-new Type: new docs and removed T-enhancement Type: enhance existing docs labels Feb 23, 2022
@rootulp
Copy link
Contributor

rootulp commented Feb 24, 2022

I took a stab at documenting this but I'm observing unexpected behavior. I have a forge project that looks like

$ tree .
...
└── src
    ├── Contract.sol
    └── test
        ├── ContractA.t.sol
        ├── ContractB.t.sol
        └── ContractC.t.sol

I'm observing no tests run when I expect all three tests to run

$ forge test --match-path './src/test/*'
compiling...
no files changed, compilation skipped.

I'm observing no tests run when I expect testA to run

> forge test --match-path './src/test/ContractA.t.sol'
compiling...
no files changed, compilation skipped.

I'm observing all tests run when I expect no tests to run

$ forge test --no-match-path './src/test/*'
compiling...
no files changed, compilation skipped.
Running 1 test for ContractA.json:ContractA
[PASS] testA() (gas: 120)

Running 1 test for ContractB.json:ContractB
[PASS] testB() (gas: 120)

Running 1 test for ContractC.json:ContractC
[PASS] testC() (gas: 142)

@lattejed can you please help me understand if I'm using these flags incorrectly?

@lattejed
Copy link

--match-path <PATH_PATTERN>
    only run test methods in source files at path matching regex. Requires absolute path

--no-match-path <PATH_PATTERN_INVERSE>
    only run test methods in source files at path not matching regex. Requires absolute path

They require an absolute path. Internally that pattern gets prefixed with a ^ and matched against the absolute paths of contract source files.

If the ergonomics of that are too awkward, feel free to file an issue. I can revisit that

@rootulp
Copy link
Contributor

rootulp commented Feb 24, 2022

Thanks! It works as expected now.

$ forge test --match-path '/Users/rootulp/git/hello_foundry/src/test/*'
compiling...
no files changed, compilation skipped.
Running 1 test for ContractA.json:ContractA
[PASS] testA() (gas: 120)

Running 1 test for ContractB.json:ContractB
[PASS] testB() (gas: 120)

Running 1 test for ContractC.json:ContractC
[PASS] testC() (gas: 142)

$ forge test --no-match-path '/Users/rootulp/git/hello_foundry/src/test/*'
compiling...
no files changed, compilation skipped.

rootulp added a commit to rootulp/foundry-book that referenced this issue Feb 24, 2022
rootulp added a commit to rootulp/foundry-book that referenced this issue Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-forge Area: forge good first issue Good for newcomers T-new Type: new docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants