@@ -13,6 +13,7 @@ import {
1313 XCODE_SELECT_LINK_PATH ,
1414 xcodeVersionFromLink ,
1515 xcodeVersionFromSdk ,
16+ xcodeVersionFromXcodeBuild ,
1617} from "./platform" ;
1718import {
1819 checkExpectedLogMessages ,
@@ -228,6 +229,74 @@ test.serial(
228229 } ,
229230) ;
230231
232+ test . serial (
233+ "xcodeVersionFromXcodeBuild returns undefined for non-zero exit code" ,
234+ async ( t ) => {
235+ const logger = new RecordingLogger ( ) ;
236+
237+ const which = sinon . stub ( io , "which" ) . resolves ( "/path/to/xcrun" ) ;
238+ const exec = sinon . stub < [ ] , Promise < number > > ( ) . resolves ( 1 ) ;
239+ const runner = sinon . createStubInstance ( toolrunner . ToolRunner , { exec } ) ;
240+ const toolrunnerStub = sinon . stub ( toolrunner , "ToolRunner" ) . returns ( runner ) ;
241+
242+ await t . notThrowsAsync ( async ( ) => {
243+ const result = await xcodeVersionFromXcodeBuild ( logger ) ;
244+
245+ t . is ( result , undefined ) ;
246+
247+ t . is ( which . callCount , 1 ) ;
248+ t . deepEqual ( which . args [ 0 ] , [ "xcrun" , true ] ) ;
249+
250+ t . is ( toolrunnerStub . callCount , 1 ) ;
251+ t . is ( exec . callCount , 1 ) ;
252+
253+ checkExpectedLogMessages ( t , logger . messages , [
254+ "xcodebuild returned exit code 1" ,
255+ ] ) ;
256+ } ) ;
257+ } ,
258+ ) ;
259+
260+ test . serial (
261+ "xcodeVersionFromXcodeBuild extracts version from xcrun stdout" ,
262+ async ( t ) => {
263+ const logger = new RecordingLogger ( ) ;
264+
265+ const which = sinon . stub ( io , "which" ) . resolves ( "/path/to/xcrun" ) ;
266+
267+ let stdoutListener : ( ( data : Buffer ) => void ) | undefined = undefined ;
268+ const exec = sinon . stub < [ ] , Promise < number > > ( ) . callsFake ( async ( ) => {
269+ if ( stdoutListener !== undefined ) {
270+ stdoutListener ( Buffer . from ( "Xcode 26.5" ) ) ;
271+ stdoutListener ( Buffer . from ( "Build version 26F9" ) ) ;
272+ }
273+ return 0 ;
274+ } ) ;
275+ const runner = sinon . createStubInstance ( toolrunner . ToolRunner , { exec } ) ;
276+
277+ const toolrunnerStub = sinon
278+ . stub ( toolrunner , "ToolRunner" )
279+ . callsFake ( ( _cmd , _args , opts : ExecOptions ) => {
280+ stdoutListener = opts . listeners ?. stdout ;
281+ return runner ;
282+ } ) ;
283+
284+ await t . notThrowsAsync ( async ( ) => {
285+ const result = await xcodeVersionFromXcodeBuild ( logger ) ;
286+
287+ t . not ( result , undefined ) ;
288+ t . is ( result ?. major , 26 ) ;
289+ t . is ( result ?. minor , 5 ) ;
290+
291+ t . is ( which . callCount , 1 ) ;
292+ t . deepEqual ( which . args [ 0 ] , [ "xcrun" , true ] ) ;
293+
294+ t . is ( toolrunnerStub . callCount , 1 ) ;
295+ t . is ( exec . callCount , 1 ) ;
296+ } ) ;
297+ } ,
298+ ) ;
299+
231300test . serial (
232301 "xcodeVersionFromSdk returns undefined for non-zero exit code" ,
233302 async ( t ) => {
0 commit comments