-
Notifications
You must be signed in to change notification settings - Fork 352
adding a autoplay tests to verify the prompt output is not changing #51
Conversation
tests/recorder/recorder.go
Outdated
@@ -0,0 +1,233 @@ | |||
package main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package is really cool! I have been suffering with the problem of how to test clis for close to half a year and this is really nice approach. How would you feel about making this an external package? I would love to use it for some projects i'm working on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought about it. I do make some assumptions about what is being recorded (ie go run
is hardcoded) so some abstractions need to be made. Now the hard part, what to call it. I am leaning towards oscillo
(as in the scope for tracing), or we could be puny and call it goscillo
which seems a bit obnoxious :)
Btw, if you need basic cli testing and dont need to deal with fancy interactive prompts, then I have a useful project I use for testing most of my cli projects: https://github.com/coryb/osht, it makes testing via bash very easy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice! Thanks for sharing. This looks like a great option for "not fancy" prompts. And I agree goscillo seems a bit... forced. Naming things is hard, survey
used to be called probe
which changed for obvious reasons haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, i really liked autoplay although I also like the connection between "scope" and watching the cli do its thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autoplay
works for me. I am in the process of making the abstractions necessary to make it a generic replay tool. I will update the PR when it is done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, created github.com/coryb/autoplay repo with the recorder code moved over, I added you as a contributor to that repo. I have updated the tests.
The travis tests seem to be failing, but it works on my system, so I will have to debug that one now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Got the invite, will take a look now. Thanks! I think it would be really cool to build this library up a bit to support writing test suites around it. For example, I might want to create an in-memory server before running a recorded test to verify that its output matches what the server is sending
I haven't gotten a chance to run the tests yet but they pass in travis so I assume it works. I'll pull this down and test it tonight or tomorrow at the latest |
I am struggling with this one, shooting in the dark at the moment. On travis in mid execution |
I am going to put this work on hold, too many odd issues with Readline. I started playing around with |
Damn, okay - thanks for trying. I have been struggling with this for awhile so i know the pain you've been experiencing. Thanks for looking into the windows bug, I thought I reviewed that PR on my windows machine before merging it but I guess something slipped through. |
@coryb i just tried to run the tests on a windows laptop and was not running into errors apart from poor unicode support, what sort of errors are you seeing on your side? |
Very strange, my only windows access currently is a vagrant VM, but when I ran
This is via Not sure how you were testing. So this could be something via vagrant although I dont see how, or perhaps you are using a different terminal other than |
Hm, so I only ran the various multiline prompts, i'll check confirm later tonight. I am running |
remove usage of bufio.Scanner
Improved behavior when there was no help message present
Woot! Updated autoplay tests and they are passing under Travis now. |
Sweet, I think it's probably rather out of date with the recent changes, but once it's ready i'll get this in. |
Hmm, I did the merge but the PR seems pretty messed up. I think I will just nuke this PR and make a new one that is clean. |
@AlecAivazis, this stuff is for #46. As mentioned in the issue, expect doesn't look like it will work out after all, so I wrote something that will basically simulate the autoexpect functionality to record a program interaction and then generate go-code that we can use for verifying prompts.
This PR really consists of 2 things:
tests/recorder/recorder.go
tests/autoplay/*.go
To run the autoplay tests you need to be in the tests directory so:
To generate a new test or to update an existing test after changes you can run:
Which will update the existing tests.
The test structure is all identical. We capture input and output to the program via the recorder process which when played back will re-execute the program and provide the input while waiting for the output. If the output does not match the autoplay tests will just
panic
with a message about what it was expecting and what it got (and fail the travis build).I would just look at
tests/autoplay/selectThanInput.go
to get an idea of what is generated andtests/recorder/recorder.go
to see how it is generated. All the rest of the stuff intests/autoplay
is just the same stuff generated with different input/output.Anyway, play around with it and let me know what you think.