From 693c4d8f3ad59dd8d9efa750398510e4a7f0f4ae Mon Sep 17 00:00:00 2001
From: Todd Gamblin <tgamblin@llnl.gov>
Date: Tue, 27 Jul 2021 14:47:44 -0700
Subject: spack style: improve tests for failure cases

This fixes the bad bootstrap test for spack style, and it refines the
asserrtions on other failure cases.
---
 lib/spack/spack/test/cmd/style.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/lib/spack/spack/test/cmd/style.py b/lib/spack/spack/test/cmd/style.py
index 65a301bc27..af0fc47d24 100644
--- a/lib/spack/spack/test/cmd/style.py
+++ b/lib/spack/spack/test/cmd/style.py
@@ -129,14 +129,15 @@ def test_changed_files_all_files(flake8_package):
 @pytest.mark.skipif(sys.version_info >= (3, 6), reason="doesn't apply to newer python")
 def test_fail_on_old_python():
     """Ensure that `spack style` runs but fails with older python."""
-    style(fail_on_error=False)
-    assert style.returncode != 0
+    output = style(fail_on_error=False)
+    assert "spack style requires Python 3.6" in output
 
 
 @skip_old_python
 def test_bad_root(tmpdir):
     """Ensure that `spack style` doesn't run on non-spack directories."""
-    style("--root", str(tmpdir), fail_on_error=False)
+    output = style("--root", str(tmpdir), fail_on_error=False)
+    assert "This does not look like a valid spack root" in output
     assert style.returncode != 0
 
 
@@ -156,10 +157,12 @@ def test_style_is_package(tmpdir):
 def test_bad_bootstrap(monkeypatch):
     """Ensure we fail gracefully when we can't bootstrap spack style."""
     monkeypatch.setattr(spack.cmd.style, "tool_order", [
-        ("foobartool", "foobartool"),  # bad package to force concretization failure
+        ("isort", "py-isort@4.3:4.0"),  # bad spec to force concretization failure
     ])
-    style(fail_on_error=False)
-    assert style.returncode != 0
+    # zero out path to ensure we don't find isort
+    with pytest.raises(spack.error.SpackError) as e:
+        style(env={"PATH": ""})
+        assert "Couldn't bootstrap isort" in str(e)
 
 
 @pytest.fixture
-- 
cgit v1.2.3-70-g09d2