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

testscript: cmpregex #116

Open
myitcv opened this issue Nov 20, 2020 · 0 comments
Open

testscript: cmpregex #116

myitcv opened this issue Nov 20, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@myitcv
Copy link
Collaborator

myitcv commented Nov 20, 2020

Raising as an idea for discussion, because I plan to implement this locally first of all.

Consider:

go test 
env time='\d(\.\d+)?'
cmpregex stdout out.golden

-- out.golden --
$$ go test
Hello, world... from the test!
PASS
ok         _/home/gopher   ${time}s

Would succeed when matched against:

$ go test
Hello, world... from the test!
PASS
ok         _/home/gopher   0.042s

cmpregex is similar to cmpenv, except that it treats $ variable values as a regular expression (with the exception of $$ which expands to $).

Comparison of the arguments to cmpregex then proceeds as follows:

  • the reference input has $$ expanded to $
  • the reference input is split around $ variables to give the parts of the input
  • verify that each $ actually expands to a regular expression that compiles
  • walking through the input parts, the reference part is matched against the prefix of the comparison
  • if the prefix does not match, a diff is printed for the prefix
  • else match the next $-specified regular expression or fail
  • continue until all the parts and $-specified regular expressions have been visited and/or the comparison has been consumed

This may or may not belong in the standard library of functions that come with testscript.

@myitcv myitcv added the enhancement New feature or request label Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant