1717 RunnerSynthesizedTextEntryStatus status,
1818 NSString * _Nullable message
1919);
20+ static RunnerSynthesizedTextEntryResult *RunnerTextEntryUnavailable (NSString *message);
21+ static RunnerSynthesizedTextEntryResult *RunnerTextEntryFailed (NSString *message);
2022static RunnerSynthesizedTextEntryResult *RunnerSynthesizeTextWithMode (
2123 id application,
2224 NSString *text,
@@ -66,37 +68,35 @@ + (RunnerSynthesizedTextEntryResult *)replaceTextWithApplication:(id)application
6668 SEL processID = NSSelectorFromString (@" processID" );
6769
6870 NSString *missing = RunnerRequireTextClass (recordClass, @" XCSynthesizedEventRecord" );
69- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
71+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
7072 missing = RunnerRequireTextClass (pathClass, @" XCPointerEventPath" );
71- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
73+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
7274 missing = RunnerRequireTextSelector (recordClass, initRecord, @" initWithName:" );
73- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
75+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
7476 missing = RunnerRequireTextSelector (recordClass, addPath, @" addPointerEventPath:" );
75- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
77+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
7678 missing = RunnerRequireTextSelector (recordClass, setTargetProcessID, @" setTargetProcessID:" );
77- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
79+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
7880 missing = RunnerRequireTextSelector (recordClass, synthesize, @" synthesizeWithError:" );
79- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
81+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
8082 missing = RunnerRequireTextSelector (pathClass, initPath, @" initForTextInput" );
81- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
83+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
8284 missing = RunnerRequireTextSelector (pathClass, typeText, @" typeText:atOffset:typingSpeed:shouldRedact:" );
83- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
85+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
8486 if (replace) {
8587 missing = RunnerRequireTextSelector (pathClass, typeKey, @" typeKey:modifiers:atOffset:" );
86- if (missing != nil ) return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, missing);
88+ if (missing != nil ) return RunnerTextEntryUnavailable ( missing);
8789 }
8890 if (![application respondsToSelector: processID]) {
89- return RunnerTextEntryResult (
90- RunnerSynthesizedTextEntryStatusUnavailable,
91+ return RunnerTextEntryUnavailable (
9192 @" private XCTest text synthesis unavailable: XCUIApplication missing processID"
9293 );
9394 }
9495
9596 NSInteger targetProcessID =
9697 ((RunnerTextMsgSendInteger)objc_msgSend)(application, processID);
9798 if (targetProcessID <= 0 ) {
98- return RunnerTextEntryResult (
99- RunnerSynthesizedTextEntryStatusUnavailable,
99+ return RunnerTextEntryUnavailable (
100100 @" private XCTest text synthesis unavailable: could not resolve target process ID"
101101 );
102102 }
@@ -107,8 +107,7 @@ + (RunnerSynthesizedTextEntryResult *)replaceTextWithApplication:(id)application
107107 );
108108 id selectionPath = ((RunnerTextMsgSendInitPath)objc_msgSend)([pathClass alloc ], initPath);
109109 if (selectionRecord == nil || selectionPath == nil ) {
110- return RunnerTextEntryResult (
111- RunnerSynthesizedTextEntryStatusFailed,
110+ return RunnerTextEntryFailed (
112111 @" private XCTest text synthesis failed: could not create the selection event"
113112 );
114113 }
@@ -130,8 +129,7 @@ + (RunnerSynthesizedTextEntryResult *)replaceTextWithApplication:(id)application
130129 );
131130 if (!selected) {
132131 NSString *detail = selectionError.localizedDescription ?: @" synthesizeWithError returned false" ;
133- return RunnerTextEntryResult (
134- RunnerSynthesizedTextEntryStatusFailed,
132+ return RunnerTextEntryFailed (
135133 [NSString stringWithFormat: @" private XCTest text selection failed: %@ " , detail]
136134 );
137135 }
@@ -142,8 +140,7 @@ + (RunnerSynthesizedTextEntryResult *)replaceTextWithApplication:(id)application
142140 );
143141 id path = ((RunnerTextMsgSendInitPath)objc_msgSend)([pathClass alloc ], initPath);
144142 if (record == nil || path == nil ) {
145- return RunnerTextEntryResult (
146- RunnerSynthesizedTextEntryStatusFailed,
143+ return RunnerTextEntryFailed (
147144 @" private XCTest text synthesis failed: could not create the text event"
148145 );
149146 }
@@ -155,19 +152,15 @@ + (RunnerSynthesizedTextEntryResult *)replaceTextWithApplication:(id)application
155152 BOOL ok = ((RunnerTextMsgSendSynthesize)objc_msgSend)(record, synthesize, &error);
156153 if (!ok) {
157154 NSString *detail = error.localizedDescription ?: @" synthesizeWithError returned false" ;
158- return RunnerTextEntryResult (
159- RunnerSynthesizedTextEntryStatusFailed,
155+ return RunnerTextEntryFailed (
160156 [NSString stringWithFormat: @" private XCTest text synthesis failed: %@ " , detail]
161157 );
162158 }
163159 return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusSucceeded, nil );
164160 } @catch (NSException *exception) {
165161 NSString *name = exception.name ?: @" NSException" ;
166162 NSString *reason = exception.reason ?: @" private XCTest text synthesis failed" ;
167- return RunnerTextEntryResult (
168- RunnerSynthesizedTextEntryStatusFailed,
169- [NSString stringWithFormat: @" %@ : %@ " , name, reason]
170- );
163+ return RunnerTextEntryFailed ([NSString stringWithFormat: @" %@ : %@ " , name, reason]);
171164 }
172165}
173166
@@ -181,6 +174,14 @@ + (RunnerSynthesizedTextEntryResult *)replaceTextWithApplication:(id)application
181174 return result;
182175}
183176
177+ static RunnerSynthesizedTextEntryResult *RunnerTextEntryUnavailable (NSString *message) {
178+ return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusUnavailable, message);
179+ }
180+
181+ static RunnerSynthesizedTextEntryResult *RunnerTextEntryFailed (NSString *message) {
182+ return RunnerTextEntryResult (RunnerSynthesizedTextEntryStatusFailed, message);
183+ }
184+
184185static NSString * _Nullable RunnerRequireTextClass (Class cls, NSString *name) {
185186 if (cls == Nil ) {
186187 return [NSString stringWithFormat: @" private XCTest text synthesis unavailable: missing %@ " , name];
0 commit comments