@@ -82,6 +82,49 @@ def test_false_when_no_makefile(self, tmp_path):
8282 b = Builder (prefix , top )
8383 assert b .is_make_generator () is False
8484
85+ def write_cache (self , build_dir , generator ):
86+ with open (os .path .join (build_dir , "CMakeCache.txt" ), "w" ) as f :
87+ f .write ("CMAKE_GENERATOR:INTERNAL={}\n " .format (generator ))
88+ f .write ("CMAKE_GENERATOR_INSTANCE:INTERNAL=\n " )
89+
90+ def test_true_for_unix_makefiles_cache (self , tmp_path ):
91+ prefix = MockPrefix (str (tmp_path ))
92+ top = str (tmp_path / "top" )
93+ build_dir = os .path .join (top , "build" )
94+ os .makedirs (build_dir )
95+ self .write_cache (build_dir , "Unix Makefiles" )
96+ with open (os .path .join (build_dir , "Makefile" ), "w" ) as f :
97+ f .write ("" )
98+ b = Builder (prefix , top )
99+ assert b .is_make_generator () is True
100+
101+ def test_false_for_nmake_cache (self , tmp_path ):
102+ prefix = MockPrefix (str (tmp_path ))
103+ top = str (tmp_path / "top" )
104+ build_dir = os .path .join (top , "build" )
105+ os .makedirs (build_dir )
106+ self .write_cache (build_dir , "NMake Makefiles" )
107+ with open (os .path .join (build_dir , "Makefile" ), "w" ) as f :
108+ f .write ("" )
109+ b = Builder (prefix , top )
110+ assert b .is_make_generator () is False
111+
112+ def test_false_for_ninja_cache (self , tmp_path ):
113+ prefix = MockPrefix (str (tmp_path ))
114+ top = str (tmp_path / "top" )
115+ build_dir = os .path .join (top , "build" )
116+ os .makedirs (build_dir )
117+ self .write_cache (build_dir , "Ninja" )
118+ b = Builder (prefix , top )
119+ assert b .is_make_generator () is False
120+
121+ def test_get_generator_no_cache (self , tmp_path ):
122+ prefix = MockPrefix (str (tmp_path ))
123+ top = str (tmp_path / "top" )
124+ os .makedirs (top )
125+ b = Builder (prefix , top )
126+ assert b .get_generator () is None
127+
85128
86129# ── show_log / show_logs ─────────────────────────────────────────────────────
87130
@@ -214,6 +257,52 @@ def test_configure_with_generator(self, tmp_path):
214257 idx = args .index ('-G' )
215258 assert args [idx + 1 ] == "Ninja"
216259
260+ def test_configure_default_generator_env (self , tmp_path , monkeypatch ):
261+ monkeypatch .setenv ("CGET_DEFAULT_GENERATOR" , "NMake Makefiles" )
262+ prefix = MockPrefix (str (tmp_path ))
263+ top = str (tmp_path / "top" )
264+ os .makedirs (top )
265+ b = Builder (prefix , top )
266+ src_dir = str (tmp_path / "src" )
267+ os .makedirs (src_dir )
268+
269+ with mock .patch .object (b , 'cmake' ) as mock_cmake :
270+ b .configure (src_dir )
271+ args = mock_cmake .call_args [1 ]['args' ]
272+ assert '-G' in args
273+ idx = args .index ('-G' )
274+ assert args [idx + 1 ] == "NMake Makefiles"
275+
276+ def test_configure_generator_overrides_env (self , tmp_path , monkeypatch ):
277+ monkeypatch .setenv ("CGET_DEFAULT_GENERATOR" , "NMake Makefiles" )
278+ prefix = MockPrefix (str (tmp_path ))
279+ top = str (tmp_path / "top" )
280+ os .makedirs (top )
281+ b = Builder (prefix , top )
282+ src_dir = str (tmp_path / "src" )
283+ os .makedirs (src_dir )
284+
285+ with mock .patch .object (b , 'cmake' ) as mock_cmake :
286+ b .configure (src_dir , generator = "Ninja" )
287+ args = mock_cmake .call_args [1 ]['args' ]
288+ idx = args .index ('-G' )
289+ assert args [idx + 1 ] == "Ninja"
290+ assert "NMake Makefiles" not in args
291+
292+ def test_configure_empty_generator_env_ignored (self , tmp_path , monkeypatch ):
293+ monkeypatch .setenv ("CGET_DEFAULT_GENERATOR" , "" )
294+ prefix = MockPrefix (str (tmp_path ))
295+ top = str (tmp_path / "top" )
296+ os .makedirs (top )
297+ b = Builder (prefix , top )
298+ src_dir = str (tmp_path / "src" )
299+ os .makedirs (src_dir )
300+
301+ with mock .patch .object (b , 'cmake' ) as mock_cmake :
302+ b .configure (src_dir )
303+ args = mock_cmake .call_args [1 ]['args' ]
304+ assert '-G' not in args
305+
217306 def test_configure_with_install_prefix (self , tmp_path ):
218307 prefix = MockPrefix (str (tmp_path ))
219308 top = str (tmp_path / "top" )
0 commit comments