|
| 1 | +import pytest |
| 2 | + |
| 3 | +from distutils.util import split_quoted, is_mingw |
| 4 | +from distutils.errors import DistutilsPlatformError, CCompilerError |
| 5 | + |
| 6 | + |
| 7 | +class TestMingw32CCompiler: |
| 8 | + @pytest.mark.skipif(not is_mingw(), reason='not on mingw') |
| 9 | + def test_compiler_type(self): |
| 10 | + from distutils.cygwinccompiler import Mingw32CCompiler |
| 11 | + |
| 12 | + compiler = Mingw32CCompiler() |
| 13 | + assert compiler.compiler_type == 'mingw32' |
| 14 | + |
| 15 | + @pytest.mark.skipif(not is_mingw(), reason='not on mingw') |
| 16 | + def test_set_executables(self, monkeypatch): |
| 17 | + from distutils.cygwinccompiler import Mingw32CCompiler |
| 18 | + |
| 19 | + monkeypatch.setenv('CC', 'cc') |
| 20 | + monkeypatch.setenv('CXX', 'c++') |
| 21 | + |
| 22 | + compiler = Mingw32CCompiler() |
| 23 | + |
| 24 | + assert compiler.compiler == split_quoted('cc -O -Wall') |
| 25 | + assert compiler.compiler_so == split_quoted('cc -shared -O -Wall') |
| 26 | + assert compiler.compiler_cxx == split_quoted('c++ -O -Wall') |
| 27 | + assert compiler.linker_exe == split_quoted('cc') |
| 28 | + assert compiler.linker_so == split_quoted('cc -shared') |
| 29 | + |
| 30 | + @pytest.mark.skipif(not is_mingw(), reason='not on mingw') |
| 31 | + def test_runtime_library_dir_option(self): |
| 32 | + from distutils.cygwinccompiler import Mingw32CCompiler |
| 33 | + |
| 34 | + compiler = Mingw32CCompiler() |
| 35 | + with pytest.raises(DistutilsPlatformError): |
| 36 | + compiler.runtime_library_dir_option('/usr/lib') |
| 37 | + |
| 38 | + @pytest.mark.skipif(not is_mingw(), reason='not on mingw') |
| 39 | + def test_cygwincc_error(self, monkeypatch): |
| 40 | + import distutils.cygwinccompiler |
| 41 | + |
| 42 | + monkeypatch.setattr(distutils.cygwinccompiler, 'is_cygwincc', lambda _: True) |
| 43 | + |
| 44 | + with pytest.raises(CCompilerError): |
| 45 | + distutils.cygwinccompiler.Mingw32CCompiler() |
0 commit comments