From 2d2e40c678d7ff9bc531023ec13a44a0a9eecd98 Mon Sep 17 00:00:00 2001
From: Jonathan Maw <jonathan.maw@codethink.co.uk>
Date: Thu, 18 Oct 2018 15:24:42 +0100
Subject: [PATCH] tests: Add a test for the interactive failure shell

This test checks that the interactive failure shell stages the cached
build tree.
---
 dev-requirements.txt            |  1 +
 tests/integration/build-tree.py | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/dev-requirements.txt b/dev-requirements.txt
index c88b4c7237..1cee187464 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -9,3 +9,4 @@ pytest-pep8
 pytest-pylint
 pytest-xdist
 pytest-timeout
+pexpect
diff --git a/tests/integration/build-tree.py b/tests/integration/build-tree.py
index 9fe22095ac..535a70b1b3 100644
--- a/tests/integration/build-tree.py
+++ b/tests/integration/build-tree.py
@@ -1,6 +1,7 @@
 import os
 import pytest
 import shutil
+import pexpect
 
 from tests.testutils import cli, cli_integration, create_artifact_share
 
@@ -29,6 +30,31 @@ def test_buildtree_staged(cli_integration, tmpdir, datafiles):
     res.assert_success()
 
 
+# Check that a failed build causes a shell that stages the buildtree
+@pytest.mark.datafiles(DATA_DIR)
+def test_buildtree_staged_interactive(cli_integration, tmpdir, datafiles):
+    # i.e. tests that cached build trees are staged by `bst shell --build`
+    project = os.path.join(datafiles.dirname, datafiles.basename)
+    element_name = 'build-shell/buildtree-fail.bst'
+
+    # Start an interactive session and intercept the interactive prompt
+    child = pexpect.spawn('bst', ['--no-colors', 'build', element_name], cwd=project)
+
+    # Ensure starting a shell is a valid option
+    child.expect('\(s\)hell')
+
+    # Wait for the interactive prompt
+    child.expect('Choice: \[continue\]:')
+
+    # Start a shell and wait for the shell's prompt
+    child.sendline('s')
+    child.expect('\]\$')
+
+    # Read the contents of the file we added
+    child.sendline('cat test')
+    child.expect('Hi')
+
+
 # Check that build shells work when pulled from a remote cache
 # This is to roughly simulate remote execution
 @pytest.mark.datafiles(DATA_DIR)
-- 
GitLab