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

--match-contract and --match-test changed to glob pattern #3916

Closed
wants to merge 4 commits into from

Conversation

jatkz
Copy link
Contributor

@jatkz jatkz commented Dec 20, 2022

Motivation

Closes #1230

Solution

Patterns take a comma separated string which converts to a vector of globs. Jaro Winkler got lowered a little because glob symbols mess with prefix.

edit: I rebased a few times so its cleaner when it gets reviewed the first time, i did some refactoring.

@jatkz jatkz changed the title patterns changed to glob --match-contract and --match-test changed to glob pattern Dec 20, 2022
@jatkz jatkz force-pushed the globs branch 2 times, most recently from 71c091c to e315634 Compare December 21, 2022 02:21
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for taking this on.

love the test.

I have some concerns about the leading *.

Is this now required when trying to match parts of the name?

This would be breaking behavior.

could you provide some examples of how matching will change with this PR?

@@ -71,8 +70,8 @@ contract Dummy {}
.unwrap();

// set up command
cmd.args(["test", "--match-test", "testA.*", "--no-match-test", "testB.*"]);
cmd.args(["--match-contract", "TestC.*", "--no-match-contract", "TestD.*"]);
cmd.args(["test", "--match-test", "*testA*", "--no-match-test", "*testB*"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the leading * now necessary?

@mattsse mattsse added T-feature Type: feature C-forge Command: forge labels Dec 21, 2022
@jatkz
Copy link
Contributor Author

jatkz commented Dec 21, 2022

thanks for taking this on.

love the test.

I have some concerns about the leading *.

Is this now required when trying to match parts of the name?

Ohh, you are right. It is a silly mistake on my part.

I tested without the leading * and it works fine. I can go through and fix everything this evening.

Thank you for your review

@mattsse
Copy link
Member

mattsse commented Dec 22, 2022

@mds1 wdyt?

I think this is an overall improvement but is technically breaking, right? since no more regex. however this is more in line with how other tools do test matching via cli

@gakonst
Copy link
Member

gakonst commented Dec 22, 2022

I believe people use some regex syntax to exclude stuff, do we still support this here?

@mds1
Copy link
Collaborator

mds1 commented Dec 22, 2022

Will look soon! @jatokz Do you mind leaving a comment here with some examples of what works / what doesn't work for each matcher (contract, test, path), compared to what did/didn't work before?

From reading the conversation here my main concern would be removing regex support, as I do think that's useful (and have found it useful myself). With good naming conventions + regex it's easy to target only certain test functions during development, so I want to better understand the tradeoffs of this PR

@jatkz
Copy link
Contributor Author

jatkz commented Dec 23, 2022

I believe people use some regex syntax to exclude stuff, do we still support this here?

in this pr, the exclude patterns are also changed to comma separated globs

@mds1 sure! made some progress, going to spend some time to try and get a good list

@gakonst
Copy link
Member

gakonst commented Dec 25, 2022

Thanks king - appreciate the effort

@jatkz
Copy link
Contributor Author

jatkz commented Dec 26, 2022

hope everyone had a good holiday

@mds1 I came up with a few examples:

  1. Case Sensitive:
    testComputeCreate2Address
    test_createAdress

glob => *[cC]reate*
re => .*[cC]reate.* OR (?i)(.*create.*)

  1. Match where contains Set or Update
    testSetFoo
    testUpdateBar

glob => *Set*,*Update*
re => .*(Set|Update).*

  1. Contain both words in any order

glob => doesnt seem possible with this lib so would have to do a comma sep list of every combination
re => (?=.*Foo)(?=.*Bar).*

  1. Both words in order

glob => *Foo*Bar*
re => .*Foo.*Bar.*

  1. Negation in front without using exclude param

testFooDooBar - No
testDooBar - yes

glob => *[!Foo]Bar* <= mismatch only if foo in front
re => ^((?!Foo).)*Bar <= mismatch if foo in there at all, im sure there is a way to do it more specific

there are some other globs patterns available here: https://docs.rs/glob/latest/glob/struct.Pattern.html

@mds1
Copy link
Collaborator

mds1 commented Dec 27, 2022

Thanks for those comparisons, that was helpful!

Seems simple enough of a change UX-wise. In general I think I'm indifferent on globs vs. regex, and since globs can accomplish pretty much the same thing, this lgtm. It may be worth including something similar to those comparisons in the book too, to help users migrate.

@gakonst Seems this will be a breaking change that may break some scripts/workflows/CIs, so we should try to communicate this once merged since I suspect these are commonly used features

@gakonst
Copy link
Member

gakonst commented Dec 27, 2022

SGTM - Can we document these in the book after we merge so that we can point people to a resource to modify their scripts?

@jatkz
Copy link
Contributor Author

jatkz commented Dec 27, 2022

i linked a pr for the book, its kind of minimalist,

I can add the regex comparison as well if you think its good

@gakonst
Copy link
Member

gakonst commented Dec 28, 2022

Yeah would love to get more examples in the book as well now that we're on it - go for it. Lgtm pending @mds1 approval

@mds1
Copy link
Collaborator

mds1 commented Dec 29, 2022

I haven’t tested the PR or reviewed the code (prob won’t be able to until after the holidays) but conceptually it lgtm!

@gakonst
Copy link
Member

gakonst commented Jan 3, 2023

@mds1 LMK when you get a chance to try!

@mds1
Copy link
Collaborator

mds1 commented Jan 4, 2023

Testing with --mt and seems to be working. Two comments:

  1. It only works if I put quotes around the glob, which is tedious. Can we make it work without quotes? For example forge test --mt test* finds nothing, but forge test --mt "test*" runs all tests
  2. Currently it's case sensitive, which I think is consistent with the prior UX right?

@jatkz
Copy link
Contributor Author

jatkz commented Jan 4, 2023

  1. Yes, I'm going to try to get that fixed soon. edit: see below, from what I know I'm not sure if there is anyway around it?

  2. I tested prior regex just now and it is consistent

@jatkz
Copy link
Contributor Author

jatkz commented Jan 5, 2023

Update on 1) from testing on my machine, since I am using a bash shell the test* was being changed to test because it functioned like a glob in my shell and there was a test directory so it matched to that.

One way to verify that this is true for you also is to do forge test --mt test\* since that escapes into literal *.

It seems that will introduce a new issue that does not occur with regex?

I'm open to any additional changes that could improve further.

@mds1
Copy link
Collaborator

mds1 commented Jan 9, 2023

Ah yes escaping with forge test --mt test\* does work. But it seems this is true even if there are no directory matches. For example testing on the forge-std repo I can't run forge test --mt *Storage* to run all storage-related tests. @mattsse @gakonst curious your thoughts on this?

@gakonst
Copy link
Member

gakonst commented Jan 17, 2023

Would like to get this in a place where it doesn't require quotes or escapes, like it is currently..Can we not parse it as String from CLI, and bring it in the right form/global format internally?

@zerosnacks
Copy link
Member

Is this PR still desired? Personally I prefer the regex pattern as it is much more expressive

Moving this outside of the 1.0 milestone as it is a breaking change

@zerosnacks zerosnacks modified the milestone: v1.0.0 Jul 31, 2024
@zerosnacks zerosnacks added the Cmd-forge-test Command: forge test label Jul 31, 2024
@mds1
Copy link
Collaborator

mds1 commented Jul 31, 2024

I'd be ok closing this, since I haven't seen any complaints about the current behavior

@zerosnacks zerosnacks closed this Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-test Command: forge test T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider accepting globs or multiple patterns for --match-contract and --match-test
5 participants