@@ -458,7 +458,7 @@ extension SubprocessWindowsTests {
458458extension SubprocessWindowsTests {
459459 @Test ( . enabled( if: SubprocessWindowsTests . hasAdminPrivileges ( ) ) )
460460 func testPlatformOptionsRunAsUser( ) async throws {
461- try await self . withTemporaryUser { username, password in
461+ try await self . withTemporaryUser { username, password, succeed in
462462 // Use public directory as working directory so the newly created user
463463 // has access to it
464464 let workingDirectory = FilePath ( " C: \\ Users \\ Public " )
@@ -501,6 +501,12 @@ extension SubprocessWindowsTests {
501501 }
502502 return String ( decodingCString: pointer, as: UTF16 . self)
503503 }
504+ // On CI, we might failed to create user due to privilege issues
505+ // There's nothing much we can do in this case
506+ guard succeed else {
507+ // If we fail to create the user, skip this test
508+ return true
509+ }
504510 // CreateProcessWithLogonW doesn't appear to work when running in a container
505511 return whoamiResult. terminationStatus == . unhandledException( STATUS_DLL_INIT_FAILED) && userName ( ) == " ContainerAdministrator "
506512 }
@@ -735,16 +741,16 @@ extension SubprocessWindowsTests {
735741// MARK: - User Utils
736742extension SubprocessWindowsTests {
737743 private func withTemporaryUser(
738- _ work: ( String , String ) async throws -> Void
744+ _ work: ( String , String , Bool ) async throws -> Void
739745 ) async throws {
740746 let username : String = " TestUser \( randomString ( length: 5 , lettersOnly: true ) ) "
741747 let password : String = " Password \( randomString ( length: 10 ) ) "
742748
743- func createUser( withUsername username: String , password: String ) {
744- username. withCString (
749+ func createUser( withUsername username: String , password: String ) -> Bool {
750+ return username. withCString (
745751 encodedAs: UTF16 . self
746752 ) { usernameW in
747- password. withCString (
753+ return password. withCString (
748754 encodedAs: UTF16 . self
749755 ) { passwordW in
750756 var userInfo : USER_INFO_1 = USER_INFO_1 ( )
@@ -765,15 +771,19 @@ extension SubprocessWindowsTests {
765771 & error
766772 )
767773 guard status == NERR_Success else {
768- Issue . record ( " Failed to create user with error: \( error) " )
769- return
774+ return false
770775 }
776+ return true
771777 }
772778 }
773779 }
774780
775- createUser ( withUsername: username, password: password)
781+ let succeed = createUser ( withUsername: username, password: password)
782+
776783 defer {
784+ guard succeed else {
785+ return
786+ }
777787 // Now delete the user
778788 let status = username. withCString (
779789 encodedAs: UTF16 . self
@@ -785,7 +795,7 @@ extension SubprocessWindowsTests {
785795 }
786796 }
787797 // Run work
788- try await work ( username, password)
798+ try await work ( username, password, succeed )
789799 }
790800
791801 private static func hasAdminPrivileges( ) -> Bool {
0 commit comments