
Ask HN: Any suggestion on how to test CLI applications? - pdappollonio
Hello HN!<p>I&#x27;ve been looking at alternatives on how to test command line applications, specifically, for example, exit codes, output messages and whatnot. I&#x27;ve seen &quot;bats&quot; https:&#x2F;&#x2F;github.com&#x2F;sstephenson&#x2F;bats and Bazel for testing but I&#x27;m curious as what other tools people use in a day to day basis. UI testing is nice with tools like Cypress.io and maybe there&#x27;s something out there that isn&#x27;t as popular but it&#x27;s useful.<p>Thoughts?
======
westurner
pytest-docker-pexpect: [https://github.com/nvbn/pytest-docker-
pexpect](https://github.com/nvbn/pytest-docker-pexpect)

Pexpect:
[https://pexpect.readthedocs.io/en/stable/](https://pexpect.readthedocs.io/en/stable/)

pytest with subprocess.popen (or Sarge) may be sufficient for checking return
codes and checking stdout and stderr output streams. Pytest has tmp_path and
tmpdir fixtures that provide less test isolation than Docker containers:
[http://doc.pytest.org/en/latest/tmpdir.html](http://doc.pytest.org/en/latest/tmpdir.html)

sarge.Capture.expect() takes a regex and returns None if there's no match:
[https://sarge.readthedocs.io/en/latest/tutorial.html#looking...](https://sarge.readthedocs.io/en/latest/tutorial.html#looking-
for-specific-patterns-in-child-process-output)

------
verdverm
[https://github.com/sstephenson/bats](https://github.com/sstephenson/bats)
sstephenson/bats: Bash Automated Testing System - GitHub

------
bryanrasmussen
If you like Cucumber
[https://github.com/cucumber/aruba](https://github.com/cucumber/aruba)

