Add a cd test
This commit is contained in:
parent
7a79fe88e2
commit
8c6773f33e
@ -100,7 +100,13 @@ def run_command_in_subshell(
|
|||||||
|
|
||||||
if cd_arg:
|
if cd_arg:
|
||||||
prefix = "-" if len(cd_arg) == 1 else "--"
|
prefix = "-" if len(cd_arg) == 1 else "--"
|
||||||
location = location_emulator(f"{prefix}{cd_arg}", f"/{spec.dag_hash()}")
|
loc_args = [f"{prefix}{cd_arg}"]
|
||||||
|
|
||||||
|
# don't add spec for cd if using env since spec hash is not the env
|
||||||
|
if not (cd_arg == "e" or cd_arg == "env"):
|
||||||
|
loc_args.append(f"/{spec.dag_hash()}")
|
||||||
|
|
||||||
|
location = location_emulator(*loc_args)
|
||||||
os.chdir(location)
|
os.chdir(location)
|
||||||
|
|
||||||
os.execvp(cmd[0], cmd)
|
os.execvp(cmd[0], cmd)
|
||||||
|
@ -2,13 +2,18 @@
|
|||||||
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
# Spack Project Developers. See the top-level COPYRIGHT file for details.
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
|
||||||
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import spack.error
|
import spack.error
|
||||||
|
from spack.cmd.common.env_utility import run_command_in_subshell
|
||||||
|
from spack.context import Context
|
||||||
from spack.main import SpackCommand
|
from spack.main import SpackCommand
|
||||||
|
from spack.spec import Spec
|
||||||
|
|
||||||
build_env = SpackCommand("build-env")
|
build_env = SpackCommand("build-env")
|
||||||
|
|
||||||
@ -58,6 +63,30 @@ def test_pickle(tmpdir):
|
|||||||
assert "PATH" in environment
|
assert "PATH" in environment
|
||||||
|
|
||||||
|
|
||||||
|
# TODO params [i, b, c] require a spec that has proceeded with a directory
|
||||||
|
# TODO praram [e] requires an active env
|
||||||
|
@pytest.mark.parametrize("cd_key", ["r", "spack-root"])
|
||||||
|
@pytest.mark.usefixtures("config", "mock_packages", "working_env")
|
||||||
|
def test_cd(cd_key, tmpdir, monkeypatch, capfd):
|
||||||
|
"""test that a subshell will navigate using spack cd before running commands"""
|
||||||
|
cmd = "pwd" if sys.platform != "win32" else "Get-Location"
|
||||||
|
def mock_execvp(_, args):
|
||||||
|
"""os.execvp will kill take over the pytest process when it is successful"""
|
||||||
|
result = subprocess.check_output(args, universal_newlines=True)
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
with tmpdir.as_cwd():
|
||||||
|
monkeypatch.setattr(os, "execvp", mock_execvp)
|
||||||
|
|
||||||
|
pwd = os.getcwd()
|
||||||
|
spec = Spec("zlib").concretized()
|
||||||
|
run_command_in_subshell(spec, Context.BUILD, [cmd], cd_arg=cd_key)
|
||||||
|
|
||||||
|
output = capfd.readouterr()
|
||||||
|
assert pwd not in output.out
|
||||||
|
assert output.err == ""
|
||||||
|
|
||||||
|
|
||||||
def test_failure_when_uninstalled_deps(config, mock_packages):
|
def test_failure_when_uninstalled_deps(config, mock_packages):
|
||||||
with pytest.raises(
|
with pytest.raises(
|
||||||
spack.error.SpackError, match="Not all dependencies of dttop are installed"
|
spack.error.SpackError, match="Not all dependencies of dttop are installed"
|
||||||
|
Loading…
Reference in New Issue
Block a user