You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
proposal: testing: allow regexps to specify example output #18831
I have a program that part of the output there is a time duration, that i would like to give an example for.
I think that making a regular expression optional won't harm anything in the simplicity of the example tests.
In the current example system I can't test this program.
Note that you'll also need to introduce an alternative prefix (not Output:) or you'll break existing tests for people that for example wrote Output: \d expecting a literal match with "\d".
you could sanitize the output before printing.
(e.g. use regexp to replace the number with a fixed number before print
them.)
Not only does this not require a new facility, it also allows the users to
use older versions of Go.
I saw in the code that there is unsorted option for the output, you use it by prefixing the output: unsorted Output:. (it is not documented)
We could do something similar, so it won't break non-regex output.
I think we'd prefer not to further complicate output tests. Doing something like replacing the time with "TIMESTAMP" in the output would be better. Or just don't print it in the first place.
changed the title [-]proposal: [testable example] write expected output using regular expressions[/-][+]proposal: testing: allow regexps to specify example output[/+]on Jan 30, 2017
Activity
mvdan commentedon Jan 28, 2017
Why do you need this, exactly? Is the plaintext output too big or non-deterministic?
The point of output lines is readability and simplicity, and I think regexes would just add complexity.
posener commentedon Jan 28, 2017
I have a program that part of the output there is a time duration, that i would like to give an example for.
I think that making a regular expression optional won't harm anything in the simplicity of the example tests.
In the current example system I can't test this program.
ALTree commentedon Jan 28, 2017
Note that you'll also need to introduce an alternative prefix (not
Output:) or you'll break existing tests for people that for example wroteOutput: \dexpecting a literal match with"\d".minux commentedon Jan 29, 2017
posener commentedon Jan 29, 2017
I saw in the code that there is
unsortedoption for the output, you use it by prefixing the output:unsorted Output:. (it is not documented)We could do something similar, so it won't break non-regex output.
rsc commentedon Jan 30, 2017
I think we'd prefer not to further complicate output tests. Doing something like replacing the time with "TIMESTAMP" in the output would be better. Or just don't print it in the first place.
[-]proposal: [testable example] write expected output using regular expressions[/-][+]proposal: testing: allow regexps to specify example output[/+]bradfitz commentedon Jan 30, 2017
I also don't want to do anything here. The whole point of examples to be simple.
Once you need a way to normalize the output, you've already failed at being simple.
rsc commentedon Jan 30, 2017
Declining for @golang/proposal-review
gopherbot commentedon Jan 31, 2017
CL https://golang.org/cl/36050 mentions this issue.