pkg grep: use capfd instead of executable for tests

This commit is contained in:
Todd Gamblin 2022-12-10 11:59:59 -08:00
parent 8035eeb36d
commit aa3b6e598f

View File

@ -297,19 +297,19 @@ def test_pkg_hash(mock_packages):
@pytest.mark.skipif(not spack.cmd.pkg.get_grep(), reason="grep is not installed")
def test_pkg_grep(mock_packages, capsys):
def test_pkg_grep(mock_packages, capfd):
# only splice-* mock packages have the string "splice" in them
with capsys.disabled():
output = pkg("grep", "-l", "splice", output=str)
pkg("grep", "-l", "splice", output=str)
output, _ = capfd.readouterr()
assert output.strip() == "\n".join(
spack.repo.path.get_pkg_class(name).module.__file__
for name in ["splice-a", "splice-h", "splice-t", "splice-vh", "splice-z"]
)
# ensure that this string isn't fouhnd
output = pkg("grep", "abcdefghijklmnopqrstuvwxyz", output=str, fail_on_error=False)
pkg("grep", "abcdefghijklmnopqrstuvwxyz", output=str, fail_on_error=False)
assert pkg.returncode == 1
output, _ = capfd.readouterr()
assert output.strip() == ""
# ensure that we return > 1 for an error