@@ -156,14 +156,66 @@ def test_generate_without_ref(self, tmp_path, monkeypatch):
156156 def test_generate_skips_clone_when_vcpkg_root_exists (self , tmp_path , monkeypatch ):
157157 monkeypatch .chdir (tmp_path )
158158 self ._make_vcpkg_env (tmp_path )
159- (tmp_path / "vcpkg" ).mkdir ()
159+ vcpkg_root = tmp_path / "vcpkg"
160+ vcpkg_root .mkdir ()
161+ # Existing bootstrap script and executable mean no clone/bootstrap is needed.
162+ (vcpkg_root / "bootstrap-vcpkg.sh" ).write_text ("#!/bin/sh\n exit 0\n " )
163+ (vcpkg_root / "vcpkg" ).write_text ("#!/bin/sh\n exit 0\n " )
160164
161165 cfg = HatchCppVcpkgConfiguration (vcpkg_ref = "2024.01.12" )
166+ monkeypatch .setattr (cfg , "_is_vcpkg_working" , lambda : True )
162167 commands = cfg .generate (None )
163168
164- # When vcpkg_root already exists, no clone or checkout happens
169+ # When vcpkg_root already exists with a working executable , no clone or bootstrap happens.
165170 assert not any ("git clone" in cmd for cmd in commands )
166171 assert not any ("checkout" in cmd for cmd in commands )
172+ assert not any ("bootstrap-vcpkg" in cmd for cmd in commands )
173+ assert any ("vcpkg" in cmd and "install" in cmd for cmd in commands )
174+
175+ def test_generate_reclones_when_vcpkg_root_exists_but_empty (self , tmp_path , monkeypatch ):
176+ monkeypatch .chdir (tmp_path )
177+ self ._make_vcpkg_env (tmp_path )
178+ (tmp_path / "vcpkg" ).mkdir ()
179+
180+ cfg = HatchCppVcpkgConfiguration (vcpkg_ref = "2024.01.12" )
181+ commands = cfg .generate (None )
182+
183+ assert any (cmd .startswith ('rm -rf "vcpkg"' ) for cmd in commands )
184+ assert any ("git clone" in cmd for cmd in commands )
185+ assert any ("checkout 2024.01.12" in cmd for cmd in commands )
186+ assert any ("bootstrap-vcpkg" in cmd for cmd in commands )
187+ assert any ("vcpkg" in cmd and "install" in cmd for cmd in commands )
188+
189+ def test_generate_bootstraps_when_vcpkg_executable_missing (self , tmp_path , monkeypatch ):
190+ monkeypatch .chdir (tmp_path )
191+ self ._make_vcpkg_env (tmp_path )
192+ vcpkg_root = tmp_path / "vcpkg"
193+ vcpkg_root .mkdir ()
194+ (vcpkg_root / "bootstrap-vcpkg.sh" ).write_text ("#!/bin/sh\n exit 0\n " )
195+
196+ cfg = HatchCppVcpkgConfiguration (vcpkg_ref = "2024.01.12" )
197+ commands = cfg .generate (None )
198+
199+ assert not any ("git clone" in cmd for cmd in commands )
200+ assert any ("bootstrap-vcpkg" in cmd for cmd in commands )
201+ assert any ("vcpkg" in cmd and "install" in cmd for cmd in commands )
202+
203+ def test_generate_reclones_when_vcpkg_exists_but_not_working (self , tmp_path , monkeypatch ):
204+ monkeypatch .chdir (tmp_path )
205+ self ._make_vcpkg_env (tmp_path )
206+ vcpkg_root = tmp_path / "vcpkg"
207+ vcpkg_root .mkdir ()
208+ (vcpkg_root / "bootstrap-vcpkg.sh" ).write_text ("#!/bin/sh\n exit 0\n " )
209+ (vcpkg_root / "vcpkg" ).write_text ("#!/bin/sh\n exit 1\n " )
210+
211+ cfg = HatchCppVcpkgConfiguration (vcpkg_ref = "2024.01.12" )
212+ monkeypatch .setattr (cfg , "_is_vcpkg_working" , lambda : False )
213+ commands = cfg .generate (None )
214+
215+ assert any (cmd .startswith ('rm -rf "vcpkg"' ) for cmd in commands )
216+ assert any ("git clone" in cmd for cmd in commands )
217+ assert any ("checkout 2024.01.12" in cmd for cmd in commands )
218+ assert any ("bootstrap-vcpkg" in cmd for cmd in commands )
167219 assert any ("vcpkg" in cmd and "install" in cmd for cmd in commands )
168220
169221 def test_generate_no_vcpkg_json (self , tmp_path , monkeypatch ):
0 commit comments