@@ -8,7 +8,7 @@ mod tests {
8
8
use super :: common:: check_request_received_using;
9
9
use std:: fs;
10
10
use std:: path:: PathBuf ;
11
- use std:: process:: { Command , Stdio } ;
11
+ use std:: process:: { Command , ExitStatus , Stdio } ;
12
12
use webbrowser:: Browser ;
13
13
14
14
// to run this test, run it as:
@@ -27,7 +27,7 @@ mod tests {
27
27
// build test glue code
28
28
let mut glue_dir = PathBuf :: from ( & app_dir) ;
29
29
glue_dir. push ( "testglue" ) ;
30
- run_cmd ( & glue_dir, " glue code build failed", & [ "./build" ] ) ;
30
+ run_cmd ( & glue_dir, & [ "./build" ] ) . expect ( " glue code build failed") ;
31
31
32
32
// invoke server
33
33
check_request_received_using ( uri, & ipv4, |url, _port| {
@@ -48,42 +48,58 @@ mod tests {
48
48
. collect :: < Vec < String > > ( )
49
49
. join ( "\n " ) ;
50
50
fs:: write ( & swift_src, new_code) . expect ( "failed to modify ContentView.swift" ) ;
51
+ let revert_code = || fs:: write ( & swift_src, & old_code) . expect ( "failed to revert code" ) ;
52
+ let handle_exec_result = |result : std:: io:: Result < ExitStatus > , err_msg : & str | {
53
+ revert_code ( ) ;
54
+ let success = match result {
55
+ Ok ( status) => status. success ( ) ,
56
+ Err ( _) => false ,
57
+ } ;
58
+ if !success {
59
+ eprintln ! ( "{err_msg}" ) ;
60
+ std:: process:: exit ( 1 ) ;
61
+ }
62
+ } ;
51
63
52
64
// build app
53
- run_cmd (
65
+ let exec_result = run_cmd (
54
66
& app_dir,
55
- "failed to build ios app" ,
56
67
& [
57
68
"xcrun" ,
58
69
"xcodebuild" ,
59
70
"-project" ,
60
71
"test-ios-app.xcodeproj" ,
61
- "-scheme" ,
62
- "test-ios-app" ,
63
72
"-configuration" ,
64
73
"Debug" ,
74
+ "-sdk" ,
75
+ "iphonesimulator" ,
65
76
"-destination" ,
66
77
"platform=iOS Simulator,name=iphone-latest" ,
67
- "-derivedDataPath" ,
68
- "build" ,
78
+ "-arch" ,
79
+ if cfg ! ( target_arch = "aarch64" ) {
80
+ "arm64"
81
+ } else {
82
+ "x86_64"
83
+ } ,
69
84
] ,
70
85
) ;
86
+ handle_exec_result ( exec_result, "failed to build ios app" ) ;
71
87
72
88
// launch app on simulator
73
- run_cmd (
89
+ let exec_result = run_cmd (
74
90
& app_dir,
75
- "failed to install app on simulator" ,
76
91
& [
77
92
"xcrun" ,
78
93
"simctl" ,
79
94
"install" ,
80
95
"booted" ,
81
- "build/Build/Products/ Debug-iphonesimulator/test-ios-app.app" ,
96
+ "build/Debug-iphonesimulator/test-ios-app.app" ,
82
97
] ,
83
98
) ;
84
- run_cmd (
99
+ handle_exec_result ( exec_result, "failed to install app on simulator" ) ;
100
+
101
+ let exec_result = run_cmd (
85
102
& app_dir,
86
- "failed to launch app on simulator" ,
87
103
& [
88
104
"xcrun" ,
89
105
"simctl" ,
@@ -92,9 +108,10 @@ mod tests {
92
108
"in.rootnet.webbrowser.test-ios-app" ,
93
109
] ,
94
110
) ;
111
+ handle_exec_result ( exec_result, "failed to launch app on simulator" ) ;
95
112
96
113
// revert to the old code
97
- fs :: write ( & swift_src , & old_code ) . expect ( "failed to modify ContentView.swift" ) ;
114
+ revert_code ( ) ;
98
115
} )
99
116
. await ;
100
117
}
@@ -118,13 +135,12 @@ mod tests {
118
135
assert ! ( Browser :: is_available( ) , "should have found a browser" ) ;
119
136
}
120
137
121
- fn run_cmd ( app_dir : & PathBuf , failure_msg : & str , args : & [ & str ] ) {
122
- let _ = Command :: new ( args[ 0 ] )
138
+ fn run_cmd ( app_dir : & PathBuf , args : & [ & str ] ) -> std :: io :: Result < ExitStatus > {
139
+ Command :: new ( args[ 0 ] )
123
140
. args ( & args[ 1 ..] )
124
141
. stdout ( Stdio :: inherit ( ) )
125
142
. stderr ( Stdio :: inherit ( ) )
126
143
. current_dir ( app_dir)
127
144
. status ( )
128
- . expect ( failure_msg) ;
129
145
}
130
146
}
0 commit comments