|
2 | 2 | #
|
3 | 3 | # SPDX-License-Identifier: MIT
|
4 | 4 |
|
| 5 | +import os |
| 6 | +import re |
5 | 7 | import shutil
|
6 | 8 | import subprocess
|
7 | 9 | import sys
|
| 10 | +import textwrap |
8 | 11 |
|
9 | 12 | from typing import List
|
10 | 13 |
|
@@ -95,3 +98,48 @@ def test_validate_config_settings_list():
|
95 | 98 | def test_validate_config_settings_tuple():
|
96 | 99 | config = mesonpy._validate_config_settings({'setup-args': ('-Done=1', '-Dtwo=2')})
|
97 | 100 | assert config['setup-args'] == ['-Done=1', '-Dtwo=2']
|
| 101 | + |
| 102 | + |
| 103 | +@pytest.mark.parametrize('meson', [None, 'meson']) |
| 104 | +def test_get_meson_command(monkeypatch, meson): |
| 105 | + # The MESON environment variable affects the meson executable lookup and breaks the test. |
| 106 | + monkeypatch.delenv('MESON', raising=False) |
| 107 | + assert mesonpy._get_meson_command(meson) == ['meson'] |
| 108 | + |
| 109 | + |
| 110 | +def test_get_meson_command_bad_path(monkeypatch): |
| 111 | + # The MESON environment variable affects the meson executable lookup and breaks the test. |
| 112 | + monkeypatch.delenv('MESON', raising=False) |
| 113 | + with pytest.raises(mesonpy.ConfigError, match=re.escape('meson executable "bad" not found')): |
| 114 | + mesonpy._get_meson_command('bad') |
| 115 | + |
| 116 | + |
| 117 | +def test_get_meson_command_bad_python_path(monkeypatch): |
| 118 | + # The MESON environment variable affects the meson executable lookup and breaks the test. |
| 119 | + monkeypatch.delenv('MESON', raising=False) |
| 120 | + with pytest.raises(mesonpy.ConfigError, match=re.escape('Could not find the specified meson: "bad-python-path.py"')): |
| 121 | + mesonpy._get_meson_command('bad-python-path.py') |
| 122 | + |
| 123 | + |
| 124 | +def test_get_meson_command_wrong_version(monkeypatch, tmp_path): |
| 125 | + # The MESON environment variable affects the meson executable lookup and breaks the test. |
| 126 | + monkeypatch.delenv('MESON', raising=False) |
| 127 | + meson = tmp_path / 'meson.py' |
| 128 | + meson.write_text(textwrap.dedent(''' |
| 129 | + print('0.0.1') |
| 130 | + ''')) |
| 131 | + with pytest.raises(mesonpy.ConfigError, match=r'Could not find meson version [0-9\.]+ or newer, found 0\.0\.1\.'): |
| 132 | + mesonpy._get_meson_command(os.fspath(meson)) |
| 133 | + |
| 134 | + |
| 135 | +def test_get_meson_command_error(monkeypatch, tmp_path): |
| 136 | + # The MESON environment variable affects the meson executable lookup and breaks the test. |
| 137 | + monkeypatch.delenv('MESON', raising=False) |
| 138 | + meson = tmp_path / 'meson.py' |
| 139 | + meson.write_text(textwrap.dedent(''' |
| 140 | + import sys |
| 141 | + print('Just testing', file=sys.stderr) |
| 142 | + sys.exit(1) |
| 143 | + ''')) |
| 144 | + with pytest.raises(mesonpy.ConfigError, match=re.escape('Could not execute meson: Just testing')): |
| 145 | + mesonpy._get_meson_command(os.fspath(meson)) |
0 commit comments