aruba
aruba copied to clipboard
Aruba doesn't seem to be able to run commands that accept input using Unix input redirection
Summary
I am using Aruba and RSpec to test a CLI. The CLI accepts input files both as arguments and via STDIN.
The Aruba testing framework can perform the first command but does not seem to be able to do the second.
Expected Behavior
The expectation is that both commands should run successfully. I am not sure if this is a bug or an improvement. But I think that since it is a standard way of writing CLIs that the framework for testing them should support it.
All of these should be supported.
run("ruby myprog.rb input.csv")
run("ruby myprog.rb < input.csv")
run("cat input.csv | ruby myprog.rb")
Current Behavior
run("ruby myprog.rb input.csv") # succeeds
run("ruby myprog.rb < input.csv") # fails
This is the error message that is being displayed.
got: "/Users/dev/Projects/Test/run.rb:54:in `each': No such file or directory @ rb_sysopen - < (Errno::ENOENT)
The expectation is that both commands should run successfully. I am not sure if this is a bug or if am suggesting an improvement.
Possible Solution
Steps to Reproduce (for bugs)
- Find a program that accepts input via STDIN ( perhaps
more
can work. ) - Run the command and pass the file as an argument in the command line.
more input.csv
- Run the command use STDIN to provide the input in the command line.
more < input.csv
- Create an Aruba/RSpec test to run the first command
run( more input.csv)
- Create an Aruba/Rspec test to run the second coomand
run(more < input.csv)
Context & Motivation
CLIs are supposed to conform to the POSIX standard and behavior and those are all standard behaviors for most command line apps.
Your Environment
-
Version used:
aruba (0.14.6)
rspec (3.8.0)
-
Operating System and version:
MacOS (10.16.2)
-
Link to your project:
N/A
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.
@luismadrigal, Does it work if you use run("ruby myprog.rb <input.csv")
instead? (Notice the lack of spacing between <
and input.csv
).
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.
I've had problems similar to this:
When the tested executable checks for stdin, it freezes: it seems to find an open, empty pipe and hangs waiting for input.
After I added reading from stdin almost all tests broke. I worked around this by using an ENV variable to turn of reading from stdin for most tests.
Where I was testing pipes I continued to get errors until I wrapped the run command in a bash shell:
When I run bash -c "echo 'http://example.com/does_not_exist' | mdqt get"
These are ugly workarounds but without them nothing worked anymore.
In a way this is the correct workaround since Aruba does not emulate a full shell when running commands.
Some documentation should be added for this at least. I don't know if we can reliably detect attempts to add input redirection in the command and then warn or abort.