-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add simple test mechanism for interactive commands #140
Comments
Ok, I think I have one for you. It's called Test::Cmd -- although it isn't a core routine. It is in CPAN though and works down to perl 5.6. Written by Neil Bowers and with over 6000 testers. You can try out the attached test script, which has 36 tests of bc. By default it will attempt to locate bc in ../bin/bc relative to the bin in which it is executing-- which is expected to be PerlPowerTools/t. But you can put the path to bc on the command line and it'll use that. If you think this is worth adding, I'd like to create a branch called test_scripts (or maybe issue_140 if you prefer), I'll then write whatever test scripts I can, commit them to that branch, and then push it to the repo for review and possible merge into master. |
As far as I can tell, Test::Cmd doesn't do what I want. I'd like something where I can send one line of input to a command then get it's output, and then send another line, and get it's output. Think about testing things like bc or ed where you want to see the state of their buffers after every input. The answer is probably something with IPC::Open3, but I'd like a better interface to it so it makes sense in our tests. |
If I understand you correctly, I can do just that with Test::Cmd. For example:
I could have set up the 36 tests of My script produces this output:
What my script doesn't do is catch a problem arising from some kind of state error, since every execution is independent of the previous one. But those errors are highly subject to the order of input. I was striving for basic functionality testing first. It takes 3.8 seconds to run that set of tests on my desktop computer. Sure, it might be faster if you could set up a pipeline between the input generator and Another way to approach this is to do what I did in the units script. I modified it to allow it to be require'd in the test script, and provided a You should give P.S. As a point of comparison, the 28 tests in units.t take 1.47 seconds to execute on my machine vs 3.8 seconds for the 36 tests in bc.t. |
While I'm here I may as well save you the trouble of trying bc.t yourself. There's not much to it besides the table that defines the tests, Here's what that looks like:
The rest is a foreach loop and an invocation of Test::Cmd run() as described in my previous message. |
You haven't done what I'm imagining with Test::Cmd: you gave it all the input at once and got the final output. This issue is about not doing that. I want to give one line of input, get the output, give another line of input. This way you know if a particular line of input did what it should do without having to do a lot of ad-hoc work to match up input with output. The tests for bc are fine, but they aren't what I'm talking about here. But, we don't really need Test::Cmd for that. All of that can be done with IPC::Open3 just as easily, and if we can avoid a dependency we should. Installing things in the GitHub Actions already takes too long. I looked at the tests you had for t/units.t and I'm about to merge a major refactor of it so it's table-oriented like you just saw. There are some other modulino tricks I added too. It's fine that you added the |
Besides what I just wrote, you should add those tests to bc. That's good work, just for a different issue. :) |
Ah, ok that helps. I wasn't against a solution using IPC::Open3. I'd love to see a working example. Maybe I can use it instead of Test::Cmd. I do get your point about minimizing dependencies in the CI environment. A drawback to using Test::Cmd is the process overhead. Even though it might only take 3 seconds to run 30 or so tests, we have 120 scripts to test and so that adds up. A faster solution would be better. I fiddled with Open3 a bit but so far a working example has eluded me. Maybe I'll have better luck tomorrow. |
After working through this issue in multiple ways, I've come to the conclusion that it's not possible to get this working on Windows. If it were, we'd have a CPAN module to do it. If it can't work on Windows, it's not something we can do here. |
There are some commands that take interactive input, such as
bc
ored
. I'd like to have a test mechanism where we can either provide input line by line and test the result (output), or provide a series of lines and test the final output. This sort of thing already exists and just needs to be here.The text was updated successfully, but these errors were encountered: