TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: Any suggestion on how to test CLI applications?

3 pointsby pdappollonioover 5 years ago
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?

3 comments

westurnerover 5 years ago
pytest-docker-pexpect: <a href="https:&#x2F;&#x2F;github.com&#x2F;nvbn&#x2F;pytest-docker-pexpect" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nvbn&#x2F;pytest-docker-pexpect</a><p>Pexpect: <a href="https:&#x2F;&#x2F;pexpect.readthedocs.io&#x2F;en&#x2F;stable&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pexpect.readthedocs.io&#x2F;en&#x2F;stable&#x2F;</a><p>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: <a href="http:&#x2F;&#x2F;doc.pytest.org&#x2F;en&#x2F;latest&#x2F;tmpdir.html" rel="nofollow">http:&#x2F;&#x2F;doc.pytest.org&#x2F;en&#x2F;latest&#x2F;tmpdir.html</a><p>sarge.Capture.expect() takes a regex and returns None if there&#x27;s no match: <a href="https:&#x2F;&#x2F;sarge.readthedocs.io&#x2F;en&#x2F;latest&#x2F;tutorial.html#looking-for-specific-patterns-in-child-process-output" rel="nofollow">https:&#x2F;&#x2F;sarge.readthedocs.io&#x2F;en&#x2F;latest&#x2F;tutorial.html#looking...</a>
verdvermover 5 years ago
<a href="https:&#x2F;&#x2F;github.com&#x2F;sstephenson&#x2F;bats" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;sstephenson&#x2F;bats</a> sstephenson&#x2F;bats: Bash Automated Testing System - GitHub
bryanrasmussenover 5 years ago
If you like Cucumber <a href="https:&#x2F;&#x2F;github.com&#x2F;cucumber&#x2F;aruba" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cucumber&#x2F;aruba</a>