22
33import os
44import shutil
5+ import sysconfig
56from pathlib import Path
67from typing import TYPE_CHECKING
78
1819DIR = Path (__file__ ).parent .resolve ()
1920
2021
21- def configure_args (config : CMaker , * , init : bool = False ) -> Generator [str , None , None ]:
22+ def single_config (param : None | str ) -> bool :
23+ if param is None :
24+ return not sysconfig .get_platform ().startswith ("win" )
25+
26+ return param in {"Ninja" , "Makefiles" }
27+
28+
29+ @pytest .fixture (
30+ params = [
31+ pytest .param (None , id = "default" ),
32+ pytest .param ("Ninja" , id = "ninja" ),
33+ pytest .param (
34+ "Makefiles" ,
35+ id = "makefiles" ,
36+ marks = pytest .mark .skipif (
37+ sysconfig .get_platform ().startswith ("win" ), reason = "run on Windows only"
38+ ),
39+ ),
40+ pytest .param (
41+ "Others" ,
42+ id = "others" ,
43+ marks = pytest .mark .skipif (
44+ sysconfig .get_platform ().startswith ("win" ), reason = "run on Windows only"
45+ ),
46+ ),
47+ ]
48+ )
49+ def generator (
50+ request : pytest .FixtureRequest , monkeypatch : pytest .MonkeyPatch
51+ ) -> str | None :
52+ if request .param is None :
53+ monkeypatch .delenv ("CMAKE_GENERATOR" , raising = False )
54+ else :
55+ monkeypatch .setenv ("CMAKE_GENERATOR" , request .param )
56+
57+ return request .param
58+
59+
60+ def configure_args (
61+ config : CMaker , * , init : bool = False , single_config : bool = False
62+ ) -> Generator [str , None , None ]:
2263 yield f"-S{ config .source_dir } "
2364 yield f"-B{ config .build_dir } "
2465
25- if config . single_config :
66+ if single_config :
2667 yield f"-DCMAKE_BUILD_TYPE:STRING={ config .build_type } "
2768
2869 if init :
@@ -31,7 +72,11 @@ def configure_args(config: CMaker, *, init: bool = False) -> Generator[str, None
3172
3273
3374@pytest .mark .configure ()
34- def test_init_cache (fp , tmp_path ):
75+ def test_init_cache (
76+ generator : str ,
77+ tmp_path : Path ,
78+ fp ,
79+ ):
3580 fp .register (
3681 [fp .program ("cmake" ), "-E" , "capabilities" ],
3782 stdout = '{"version":{"string":"3.14.0"}}' ,
@@ -51,7 +96,9 @@ def test_init_cache(fp, tmp_path):
5196 {"SKBUILD" : True , "SKBUILD_VERSION" : "1.0.0" , "SKBUILD_PATH" : config .source_dir }
5297 )
5398
54- cmd = list (configure_args (config , init = True ))
99+ cmd = list (
100+ configure_args (config , init = True , single_config = single_config (generator ))
101+ )
55102 print ("Registering: cmake" , * cmd )
56103 fp .register ([fp .program ("cmake" ), * cmd ])
57104 fp .register ([fp .program ("cmake3" ), * cmd ])
@@ -87,7 +134,11 @@ def test_too_old(fp, monkeypatch):
87134
88135
89136@pytest .mark .configure ()
90- def test_cmake_args (tmp_path , fp ):
137+ def test_cmake_args (
138+ generator : str ,
139+ tmp_path : Path ,
140+ fp ,
141+ ):
91142 fp .register (
92143 [fp .program ("cmake" ), "-E" , "capabilities" ],
93144 stdout = '{"version":{"string":"3.15.0"}}' ,
@@ -99,24 +150,29 @@ def test_cmake_args(tmp_path, fp):
99150
100151 config = CMaker (
101152 CMake .default_search (),
102- source_dir = DIR / "packages/ simple_pure" ,
153+ source_dir = DIR / "packages" / " simple_pure" ,
103154 build_dir = tmp_path / "build" ,
104155 build_type = "Release" ,
105156 )
106157
107- cmd = list (configure_args (config ))
158+ cmd = list (configure_args (config , single_config = single_config ( generator ) ))
108159 cmd .append ("-DSOMETHING=one" )
109160 print ("Registering: cmake" , * cmd )
110161 fp .register ([fp .program ("cmake" ), * cmd ])
111162 fp .register ([fp .program ("cmake3" ), * cmd ])
112163
113164 config .configure (cmake_args = ["-DSOMETHING=one" ])
114-
165+ # config.configure might mutate config.single_config
166+ assert config .single_config == single_config (generator )
115167 assert len (fp .calls ) == 2
116168
117169
118170@pytest .mark .configure ()
119- def test_cmake_paths (tmp_path , fp ):
171+ def test_cmake_paths (
172+ generator : str ,
173+ tmp_path : Path ,
174+ fp ,
175+ ):
120176 fp .register (
121177 [fp .program ("cmake" ), "-E" , "capabilities" ],
122178 stdout = '{"version":{"string":"3.15.0"}}' ,
@@ -135,7 +191,7 @@ def test_cmake_paths(tmp_path, fp):
135191 module_dirs = [tmp_path / "module" ],
136192 )
137193
138- cmd = list (configure_args (config ))
194+ cmd = list (configure_args (config , single_config = single_config ( generator ) ))
139195 print ("Registering: cmake" , * cmd )
140196 fp .register ([fp .program ("cmake" ), * cmd ])
141197 fp .register ([fp .program ("cmake3" ), * cmd ])
0 commit comments