Skip to content
Snippets Groups Projects
Unverified Commit d5ffec1b authored by Massimiliano Culpo's avatar Massimiliano Culpo Committed by GitHub
Browse files

Unify tests for compiler command in the same file (#16891)

* Unify tests for compiler command in the same file

Tests for the "spack compiler" command were previously
scattered among different files.

* Tests should use mutable_config, since they modify the compiler list
parent 76142124
No related branches found
No related tags found
No related merge requests found
......@@ -2,12 +2,13 @@
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
import pytest
import os
import llnl.util.filesystem
import spack.main
import spack.version
compiler = spack.main.SpackCommand('compiler')
......@@ -24,6 +25,40 @@ def no_compilers_yaml(mutable_config, monkeypatch):
os.remove(compilers_yaml)
@pytest.fixture
def mock_compiler_version():
return '4.5.3'
@pytest.fixture()
def mock_compiler_dir(tmpdir, mock_compiler_version):
"""Return a directory containing a fake, but detectable compiler."""
tmpdir.ensure('bin', dir=True)
bin_dir = tmpdir.join('bin')
gcc_path = bin_dir.join('gcc')
gxx_path = bin_dir.join('g++')
gfortran_path = bin_dir.join('gfortran')
gcc_path.write("""\
#!/bin/sh
for arg in "$@"; do
if [ "$arg" = -dumpversion ]; then
echo '%s'
fi
done
""" % mock_compiler_version)
# Create some mock compilers in the temporary directory
llnl.util.filesystem.set_executable(str(gcc_path))
gcc_path.copy(gxx_path, mode=True)
gcc_path.copy(gfortran_path, mode=True)
return str(tmpdir)
@pytest.mark.regression('11678,13138')
def test_compiler_find_without_paths(no_compilers_yaml, working_env, tmpdir):
with tmpdir.as_cwd():
......@@ -38,3 +73,33 @@ def test_compiler_find_without_paths(no_compilers_yaml, working_env, tmpdir):
output = compiler('find', '--scope=site')
assert 'gcc' in output
def test_compiler_remove(mutable_config, mock_packages):
args = spack.util.pattern.Bunch(
all=True, compiler_spec='gcc@4.5.0', add_paths=[], scope=None
)
spack.cmd.compiler.compiler_remove(args)
compilers = spack.compilers.all_compiler_specs()
assert spack.spec.CompilerSpec("gcc@4.5.0") not in compilers
def test_compiler_add(
mutable_config, mock_packages, mock_compiler_dir, mock_compiler_version
):
# Compilers available by default.
old_compilers = set(spack.compilers.all_compiler_specs())
args = spack.util.pattern.Bunch(
all=None,
compiler_spec=None,
add_paths=[mock_compiler_dir],
scope=None
)
spack.cmd.compiler.compiler_find(args)
# Ensure new compiler is in there
new_compilers = set(spack.compilers.all_compiler_specs())
new_compiler = new_compilers - old_compilers
assert any(c.version == spack.version.Version(mock_compiler_version)
for c in new_compiler)
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
import pytest
import llnl.util.filesystem
import spack.cmd.compiler
import spack.compilers
import spack.spec
import spack.util.pattern
from spack.version import Version
test_version = '4.5.3'
@pytest.fixture()
def mock_compiler_dir(tmpdir):
"""Return a directory containing a fake, but detectable compiler."""
tmpdir.ensure('bin', dir=True)
bin_dir = tmpdir.join('bin')
gcc_path = bin_dir.join('gcc')
gxx_path = bin_dir.join('g++')
gfortran_path = bin_dir.join('gfortran')
gcc_path.write("""\
#!/bin/sh
for arg in "$@"; do
if [ "$arg" = -dumpversion ]; then
echo '%s'
fi
done
""" % test_version)
# Create some mock compilers in the temporary directory
llnl.util.filesystem.set_executable(str(gcc_path))
gcc_path.copy(gxx_path, mode=True)
gcc_path.copy(gfortran_path, mode=True)
return str(tmpdir)
@pytest.mark.usefixtures('config', 'mock_packages')
class TestCompilerCommand(object):
def test_compiler_remove(self):
args = spack.util.pattern.Bunch(
all=True, compiler_spec='gcc@4.5.0', add_paths=[], scope=None
)
spack.cmd.compiler.compiler_remove(args)
compilers = spack.compilers.all_compiler_specs()
assert spack.spec.CompilerSpec("gcc@4.5.0") not in compilers
def test_compiler_add(self, mock_compiler_dir):
# Compilers available by default.
old_compilers = set(spack.compilers.all_compiler_specs())
args = spack.util.pattern.Bunch(
all=None,
compiler_spec=None,
add_paths=[mock_compiler_dir],
scope=None
)
spack.cmd.compiler.compiler_find(args)
# Ensure new compiler is in there
new_compilers = set(spack.compilers.all_compiler_specs())
new_compiler = new_compilers - old_compilers
assert any(c.version == Version(test_version) for c in new_compiler)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment