|
15 | 15 | from fab.tools.ar import Ar |
16 | 16 | from fab.tools.category import Category |
17 | 17 | from fab.tools.compiler import Compiler, FortranCompiler, Gfortran, Ifort |
18 | | -from fab.tools.compiler_wrapper import Mpif90 |
| 18 | +from fab.tools.compiler_wrapper import Mpicc, Mpif90 |
| 19 | +from fab.tools.linker import Linker |
19 | 20 | from fab.tools.tool_repository import ToolRepository |
20 | 21 |
|
21 | 22 | from tests.conftest import call_list |
@@ -125,6 +126,33 @@ def test_get_default(stub_tool_repository, stub_fortran_compiler, |
125 | 126 | assert isinstance(ar, Ar) |
126 | 127 |
|
127 | 128 |
|
| 129 | +def test_get_default_linker_with_wrapper(stub_tool_repository, |
| 130 | + stub_fortran_compiler, |
| 131 | + stub_c_compiler) -> None: |
| 132 | + """ |
| 133 | + Tests that we get the right linker if compiler wrapper are used. |
| 134 | + """ |
| 135 | + |
| 136 | + # Add a linker around a compiler wrapper, to test that the compiler |
| 137 | + # wrapper is recognised as a Fortran compiler: |
| 138 | + linker = Linker(Mpif90(stub_fortran_compiler)) |
| 139 | + linker._is_available = True |
| 140 | + stub_tool_repository.add_tool(linker) |
| 141 | + for_link = stub_tool_repository.get_default(Category.LINKER, mpi=True, |
| 142 | + openmp=True, |
| 143 | + enforce_fortran_linker=True) |
| 144 | + assert for_link is linker |
| 145 | + |
| 146 | + # Now the same for a linker around a C compiler wrapper: |
| 147 | + linker = Linker(Mpicc(stub_c_compiler)) |
| 148 | + linker._is_available = True |
| 149 | + stub_tool_repository.add_tool(linker) |
| 150 | + cc_link = stub_tool_repository.get_default(Category.LINKER, mpi=True, |
| 151 | + openmp=True, |
| 152 | + enforce_fortran_linker=False) |
| 153 | + assert cc_link is linker |
| 154 | + |
| 155 | + |
128 | 156 | def test_get_default_error_invalid_category() -> None: |
129 | 157 | """ |
130 | 158 | Tests error handling in get_default, the category must be a Category, |
@@ -152,6 +180,11 @@ def test_get_default_error_missing_mpi() -> None: |
152 | 180 | assert str(err.value) == ("Invalid or missing openmp specification " |
153 | 181 | "for 'FORTRAN_COMPILER'.") |
154 | 182 |
|
| 183 | + with raises(RuntimeError) as err: |
| 184 | + tr.get_default(Category.LINKER, mpi=True, openmp=True) |
| 185 | + assert str(err.value) == ("Invalid or missing enforce_fortran_linker " |
| 186 | + "specification for 'LINKER'.") |
| 187 | + |
155 | 188 |
|
156 | 189 | def test_get_default_error_missing_openmp() -> None: |
157 | 190 | """ |
|
0 commit comments