@@ -63,6 +63,45 @@ final class ShellInstallTests: XCTestCase {
6363
6464 // ---- the commands ----
6565
66+ // ---- the iOS shell package (DM_SHELL_PACKAGE) ----
67+
68+ private func makeTree ( _ files : [ String ] ) throws -> String {
69+ let dir = NSTemporaryDirectory ( ) + " shellpkg- " + UUID ( ) . uuidString
70+ for f in files {
71+ try FileManager . default . createDirectory ( atPath : ( dir + " / " + f as NSString ) . deletingLastPathComponent , withIntermediateDirectories : true )
72+ FileManager . default . createFile ( atPath : dir + " / " + f , contents : Data ( ) )
73+ }
74+ try FileManager . default . createDirectory ( atPath : dir , withIntermediateDirectories : true )
75+ addTeardownBlock { try? FileManager . default . removeItem ( atPath : dir ) }
76+ return dir
77+ }
78+
79+ func testShellPackagePrefersTheBundleThenTheCheckout ( ) throws {
80+ let bundle = try makeTree ( [ " frontend-ios/Package.swift " ] )
81+ let checkout = try makeTree ( [ " frontend-ios/Package.swift " ] )
82+ XCTAssertEqual ( ShellInstall . shellPackage ( resources : bundle , repo : checkout ) , bundle + " /frontend-ios " )
83+ XCTAssertEqual ( ShellInstall . shellPackage ( resources : nil , repo : checkout ) , checkout + " /frontend-ios " )
84+ let bare = try makeTree ( [ ] )
85+ XCTAssertEqual ( ShellInstall . shellPackage ( resources : bare , repo : checkout ) , checkout + " /frontend-ios " )
86+ XCTAssertNil ( ShellInstall . shellPackage ( resources : bare , repo : bare ) )
87+ XCTAssertNil ( ShellInstall . shellPackage ( resources : nil , repo : " " ) )
88+ }
89+
90+ /// The failure of the report: the repo is an engine in the store (no frontend-ios in it), the release app carries the package.
91+ func testStoreEngineGetsTheBundledPackage ( ) throws {
92+ let store = try makeTree ( [ " engine/id/dm/ios/tools/build_shell.sh " ] ) + " /engine/id "
93+ let bundle = try makeTree ( [ " frontend-ios/Package.swift " , " frontend-ios/AppIcon.icon/icon.json " ] )
94+ let package = try XCTUnwrap ( ShellInstall . shellPackage ( resources : bundle , repo : store ) )
95+ let env = ShellInstall . projectEnvironment ( root : " /R " , frameworks : [ ] , bundleID : " b " , team : " T " , python : " /py " , path : " /p " ,
96+ home : " /h " , user : " u " , package : package )
97+ let path = try XCTUnwrap ( env [ " DM_SHELL_PACKAGE " ] )
98+ XCTAssertTrue ( FileManager . default . fileExists ( atPath : path + " /Package.swift " ) )
99+ XCTAssertTrue ( FileManager . default . fileExists ( atPath : path + " /AppIcon.icon " ) )
100+ XCTAssertFalse ( path . hasPrefix ( store ) )
101+ XCTAssertNil ( ShellInstall . projectEnvironment ( root : " /R " , frameworks : [ ] , bundleID : " b " , team : " T " , python : " /py " , path : " /p " ,
102+ home : " /h " , user : " u " ) [ " DM_SHELL_PACKAGE " ] )
103+ }
104+
66105 func testCommandsAreExact ( ) {
67106 let root = " /R/NX2Apple-shell "
68107 XCTAssertEqual ( ShellInstall . buildArguments ( workDir : " /W " , team : " T " ) , [ " --shell-framework " , " /W/shell-framework " , " --team-id " , " T " ] )
@@ -272,6 +311,7 @@ final class ShellInstallTests: XCTestCase {
272311 env | sort > " \( state ) /shell-env.txt "
273312 if [ " ${DM_ENTITLEMENTS+set} " = set ] && [ -z " $DM_ENTITLEMENTS " ]; then touch " $SHELL_DIR/entitlements-empty " ; else rm -f " $SHELL_DIR/entitlements-empty " ; fi
274313 """ )
314+ try write ( repo + " /frontend-ios/Package.swift " , " // swift-tools-version: 5.9 \n " )
275315 return repo
276316 }
277317
@@ -313,6 +353,7 @@ final class ShellInstallTests: XCTestCase {
313353 var i = ShellInstaller ( xcrun : f . xcrun , repo : f . repo , python : " /usr/bin/python3 " , root : f . root , device : device , team : team )
314354 i . deviceName = " Z "
315355 i . pollInterval = 0.02
356+ i . resources = nil
316357 return i
317358 }
318359
@@ -362,7 +403,7 @@ final class ShellInstallTests: XCTestCase {
362403 XCTAssertEqual ( try String ( contentsOfFile : save ) , " my save " )
363404 let env = try String ( contentsOfFile : state + " /shell-env.txt " )
364405 for line in [ " DM_BUNDLE_ID=org.nxnative.shell " , " DM_SHELL_FRAMEWORKS= \( f . framework ) " , " DM_TEAM_ID=TEAM123456 " ,
365- " SHELL_DIR= \( f . root ) /project " , " DM_XCODE_DERIVED_DATA= \( f . root ) /derived-data " , " FONT_PY=/usr/bin/python3 " ] {
406+ " SHELL_DIR= \( f . root ) /project " , " DM_XCODE_DERIVED_DATA= \( f . root ) /derived-data " , " FONT_PY=/usr/bin/python3 " , " DM_SHELL_PACKAGE= \( f . repo ) /frontend-ios " ] {
366407 XCTAssertTrue ( env . contains ( line ) , line )
367408 }
368409 let library = ShellLibrary . load ( root : f . root )
@@ -425,6 +466,15 @@ final class ShellInstallTests: XCTestCase {
425466 XCTAssertFalse ( calls . contains { $0 . hasPrefix ( " xcodebuild " ) || $0 . hasPrefix ( " devicectl device " ) } ) // nothing was signed or installed
426467 }
427468
469+ func testMissingShellPackageStopsBeforeTheScript ( ) throws {
470+ let f = try makeFixture ( )
471+ try fm . removeItem ( atPath : f . repo + " /frontend-ios " )
472+ let r = run ( f )
473+ XCTAssertEqual ( r . status , 1 )
474+ XCTAssertTrue ( r . output . contains ( " FAIL: The shared app could not be prepared: no frontend-ios Swift package " ) , r . output )
475+ XCTAssertFalse ( fm . fileExists ( atPath : state + " /shell-env.txt " ) , " build_shell.sh must not run " )
476+ }
477+
428478 func testCLIChecksItsArguments ( ) throws {
429479 var output = " "
430480 XCTAssertEqual ( ShellCLI . run ( [ " --install-shell " , " --framework " , " /x " ] , defaults : UserDefaults ( suiteName : " nspb-shell- " + UUID ( ) . uuidString ) ! ) { output += $0 } , 1 )
0 commit comments