summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMassimiliano Culpo <massimiliano.culpo@gmail.com>2020-06-02 23:59:42 +0200
committerGitHub <noreply@github.com>2020-06-02 14:59:42 -0700
commitd5ffec1b2f3afff448880769ea37a530e3f3a5de (patch)
tree5a584938e498fb8ebe80c6b57bfb2f8102a8f11c /lib
parent76142124d2ac58f0499f6e3c0314e2b5c4ecc5fe (diff)
downloadspack-d5ffec1b2f3afff448880769ea37a530e3f3a5de.tar.gz
spack-d5ffec1b2f3afff448880769ea37a530e3f3a5de.tar.bz2
spack-d5ffec1b2f3afff448880769ea37a530e3f3a5de.tar.xz
spack-d5ffec1b2f3afff448880769ea37a530e3f3a5de.zip
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
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/test/cmd/compiler.py105
-rw-r--r--lib/spack/spack/test/cmd/compiler_command.py40
-rw-r--r--lib/spack/spack/test/cmd/test_compiler_cmd.py73
3 files changed, 105 insertions, 113 deletions
diff --git a/lib/spack/spack/test/cmd/compiler.py b/lib/spack/spack/test/cmd/compiler.py
new file mode 100644
index 0000000000..0476275a5f
--- /dev/null
+++ b/lib/spack/spack/test/cmd/compiler.py
@@ -0,0 +1,105 @@
+# 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 os
+
+import pytest
+
+import llnl.util.filesystem
+import spack.main
+import spack.version
+
+compiler = spack.main.SpackCommand('compiler')
+
+
+@pytest.fixture
+def no_compilers_yaml(mutable_config, monkeypatch):
+ """Creates a temporary configuration without compilers.yaml"""
+
+ for scope, local_config in mutable_config.scopes.items():
+ compilers_yaml = os.path.join(
+ local_config.path, scope, 'compilers.yaml'
+ )
+ if os.path.exists(compilers_yaml):
+ 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():
+ with open('gcc', 'w') as f:
+ f.write("""\
+#!/bin/bash
+echo "0.0.0"
+""")
+ os.chmod('gcc', 0o700)
+
+ os.environ['PATH'] = str(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)
diff --git a/lib/spack/spack/test/cmd/compiler_command.py b/lib/spack/spack/test/cmd/compiler_command.py
deleted file mode 100644
index 15949d08d4..0000000000
--- a/lib/spack/spack/test/cmd/compiler_command.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# 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 os
-
-import spack.main
-
-compiler = spack.main.SpackCommand('compiler')
-
-
-@pytest.fixture
-def no_compilers_yaml(mutable_config, monkeypatch):
- """Creates a temporary configuration without compilers.yaml"""
-
- for scope, local_config in mutable_config.scopes.items():
- compilers_yaml = os.path.join(
- local_config.path, scope, 'compilers.yaml'
- )
- if os.path.exists(compilers_yaml):
- os.remove(compilers_yaml)
-
-
-@pytest.mark.regression('11678,13138')
-def test_compiler_find_without_paths(no_compilers_yaml, working_env, tmpdir):
- with tmpdir.as_cwd():
- with open('gcc', 'w') as f:
- f.write("""\
-#!/bin/bash
-echo "0.0.0"
-""")
- os.chmod('gcc', 0o700)
-
- os.environ['PATH'] = str(tmpdir)
- output = compiler('find', '--scope=site')
-
- assert 'gcc' in output
diff --git a/lib/spack/spack/test/cmd/test_compiler_cmd.py b/lib/spack/spack/test/cmd/test_compiler_cmd.py
deleted file mode 100644
index 3c34f720ec..0000000000
--- a/lib/spack/spack/test/cmd/test_compiler_cmd.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# 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)