Test no longer assumes compilers exist in /usr.
- makes a fake gcc instead, and tests that.
This commit is contained in:
parent
64c83638ff
commit
84e21703bd
@ -1,8 +1,16 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from tempfile import mkdtemp
|
||||||
|
|
||||||
|
from llnl.util.filesystem import set_executable, mkdirp
|
||||||
|
|
||||||
import spack.spec
|
import spack.spec
|
||||||
import spack.cmd.compiler
|
import spack.cmd.compiler
|
||||||
import spack.compilers
|
import spack.compilers
|
||||||
|
from spack.version import Version
|
||||||
from spack.test.mock_packages_test import *
|
from spack.test.mock_packages_test import *
|
||||||
|
|
||||||
|
test_version = '4.5-spacktest'
|
||||||
|
|
||||||
class MockArgs(object):
|
class MockArgs(object):
|
||||||
def __init__(self, add_paths=[], scope=None, compiler_spec=None, all=None):
|
def __init__(self, add_paths=[], scope=None, compiler_spec=None, all=None):
|
||||||
@ -12,23 +20,62 @@ def __init__(self, add_paths=[], scope=None, compiler_spec=None, all=None):
|
|||||||
self.all = all
|
self.all = all
|
||||||
|
|
||||||
|
|
||||||
|
def make_mock_compiler():
|
||||||
|
"""Make a directory containing a fake, but detectable compiler."""
|
||||||
|
mock_compiler_dir = mkdtemp()
|
||||||
|
bin_dir = os.path.join(mock_compiler_dir, 'bin')
|
||||||
|
mkdirp(bin_dir)
|
||||||
|
|
||||||
|
gcc_path = os.path.join(bin_dir, 'gcc')
|
||||||
|
gxx_path = os.path.join(bin_dir, 'g++')
|
||||||
|
gfortran_path = os.path.join(bin_dir, 'gfortran')
|
||||||
|
|
||||||
|
with open(gcc_path, 'w') as f:
|
||||||
|
f.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
|
||||||
|
set_executable(gcc_path)
|
||||||
|
shutil.copy(gcc_path, gxx_path)
|
||||||
|
shutil.copy(gcc_path, gfortran_path)
|
||||||
|
|
||||||
|
return mock_compiler_dir
|
||||||
|
|
||||||
|
|
||||||
class CompilerCmdTest(MockPackagesTest):
|
class CompilerCmdTest(MockPackagesTest):
|
||||||
""" Test compiler commands for add and remove """
|
""" Test compiler commands for add and remove """
|
||||||
|
|
||||||
|
|
||||||
def test_compiler_remove(self):
|
def test_compiler_remove(self):
|
||||||
args = MockArgs(all=True, compiler_spec='gcc@4.5.0')
|
args = MockArgs(all=True, compiler_spec='gcc@4.5.0')
|
||||||
spack.cmd.compiler.compiler_remove(args)
|
spack.cmd.compiler.compiler_remove(args)
|
||||||
compilers = spack.compilers.all_compilers()
|
compilers = spack.compilers.all_compilers()
|
||||||
self.assertTrue(spack.spec.CompilerSpec("gcc@4.5.0") not in compilers)
|
self.assertTrue(spack.spec.CompilerSpec("gcc@4.5.0") not in compilers)
|
||||||
|
|
||||||
|
|
||||||
def test_compiler_add(self):
|
def test_compiler_add(self):
|
||||||
# Probably not a good a assumption but might try finding local
|
# compilers available by default.
|
||||||
# compilers
|
old_compilers = set(spack.compilers.all_compilers())
|
||||||
# installed in /usr
|
|
||||||
compilers = spack.compilers.all_compilers()
|
# add our new compiler and find again.
|
||||||
s = set(compilers)
|
compiler_dir = make_mock_compiler()
|
||||||
args = MockArgs(add_paths=["/usr"])
|
|
||||||
spack.cmd.compiler.compiler_find(args)
|
try:
|
||||||
new_compilers = spack.compilers.all_compilers()
|
args = MockArgs(add_paths=[compiler_dir])
|
||||||
new_compiler = [x for x in new_compilers if x not in s]
|
spack.cmd.compiler.compiler_find(args)
|
||||||
self.assertTrue(new_compiler)
|
|
||||||
|
# ensure new compiler is in there
|
||||||
|
new_compilers = set(spack.compilers.all_compilers())
|
||||||
|
new_compiler = new_compilers - old_compilers
|
||||||
|
self.assertTrue(new_compiler)
|
||||||
|
self.assertTrue(new_compiler.pop().version == Version(test_version))
|
||||||
|
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(compiler_dir, ignore_errors=True)
|
||||||
|
Loading…
Reference in New Issue
Block a user