|
3 | 3 | # SPDX-License-Identifier: MIT
|
4 | 4 |
|
5 | 5 | import platform
|
| 6 | +import shutil |
6 | 7 | import sys
|
7 | 8 | import textwrap
|
8 | 9 |
|
@@ -147,3 +148,44 @@ def test_validate_pyproject_config_empty():
|
147 | 148 | pyproject_config = tomllib.loads(textwrap.dedent(''))
|
148 | 149 | config = mesonpy._validate_pyproject_config(pyproject_config)
|
149 | 150 | assert config == {}
|
| 151 | + |
| 152 | + |
| 153 | +@pytest.mark.skipif( |
| 154 | + sys.version_info < (3, 8), |
| 155 | + reason="unittest.mock doesn't support the required APIs for this test", |
| 156 | +) |
| 157 | +def test_invalid_build_dir(package_pure, tmp_path, mocker): |
| 158 | + meson = mocker.spy(mesonpy.Project, '_run') |
| 159 | + |
| 160 | + # configure the project |
| 161 | + project = mesonpy.Project(package_pure, tmp_path) |
| 162 | + assert len(meson.call_args_list) == 1 |
| 163 | + assert meson.call_args_list[0].args[1][1] == 'setup' |
| 164 | + assert '--reconfigure' not in meson.call_args_list[0].args[1] |
| 165 | + project.build() |
| 166 | + meson.reset_mock() |
| 167 | + |
| 168 | + # subsequent builds with the same build directory result in a setup --reconfigure |
| 169 | + project = mesonpy.Project(package_pure, tmp_path) |
| 170 | + assert len(meson.call_args_list) == 1 |
| 171 | + assert meson.call_args_list[0].args[1][1] == 'setup' |
| 172 | + assert '--reconfigure' in meson.call_args_list[0].args[1] |
| 173 | + project.build() |
| 174 | + meson.reset_mock() |
| 175 | + |
| 176 | + # corrupting the build direcory setup is run again |
| 177 | + tmp_path.joinpath('build/meson-private/coredata.dat').unlink() |
| 178 | + project = mesonpy.Project(package_pure, tmp_path) |
| 179 | + assert len(meson.call_args_list) == 1 |
| 180 | + assert meson.call_args_list[0].args[1][1] == 'setup' |
| 181 | + assert '--reconfigure' not in meson.call_args_list[0].args[1] |
| 182 | + project.build() |
| 183 | + meson.reset_mock() |
| 184 | + |
| 185 | + # removing the build directory things should still work |
| 186 | + shutil.rmtree(tmp_path.joinpath('build')) |
| 187 | + project = mesonpy.Project(package_pure, tmp_path) |
| 188 | + assert len(meson.call_args_list) == 1 |
| 189 | + assert meson.call_args_list[0].args[1][1] == 'setup' |
| 190 | + assert '--reconfigure' not in meson.call_args_list[0].args[1] |
| 191 | + project.build() |
0 commit comments