6
6
// (https://github.com/snipsco/dinghy): cargo dinghy install, then cargo dinghy
7
7
// test.
8
8
9
- use std:: env;
10
9
use std:: fs:: { self , File } ;
11
10
use std:: io:: Write ;
12
11
use std:: path:: Path ;
13
- use std:: process;
14
12
use std:: process:: Command ;
13
+ use std:: { env, process} ;
15
14
16
15
macro_rules! t {
17
- ( $e: expr) => ( match $e {
18
- Ok ( e) => e,
19
- Err ( e) => panic!( "{} failed with: {e}" , stringify!( $e) ) ,
20
- } )
16
+ ( $e: expr) => {
17
+ match $e {
18
+ Ok ( e) => e,
19
+ Err ( e) => panic!( "{} failed with: {e}" , stringify!( $e) ) ,
20
+ }
21
+ } ;
21
22
}
22
23
23
24
// Step one: Wrap as an app
24
25
fn package_as_simulator_app ( crate_name : & str , test_binary_path : & Path ) {
25
26
println ! ( "Packaging simulator app" ) ;
26
27
drop ( fs:: remove_dir_all ( "ios_simulator_app" ) ) ;
27
28
t ! ( fs:: create_dir( "ios_simulator_app" ) ) ;
28
- t ! ( fs:: copy( test_binary_path,
29
- Path :: new( "ios_simulator_app" ) . join( crate_name) ) ) ;
29
+ t ! ( fs:: copy(
30
+ test_binary_path,
31
+ Path :: new( "ios_simulator_app" ) . join( crate_name)
32
+ ) ) ;
30
33
31
34
let mut f = t ! ( File :: create( "ios_simulator_app/Info.plist" ) ) ;
32
- t ! ( f. write_all( format!( r#"
35
+ t ! ( f. write_all(
36
+ format!(
37
+ r#"
33
38
<?xml version="1.0" encoding="UTF-8"?>
34
39
<!DOCTYPE plist PUBLIC
35
40
"-//Apple//DTD PLIST 1.0//EN"
@@ -42,7 +47,11 @@ fn package_as_simulator_app(crate_name: &str, test_binary_path: &Path) {
42
47
<string>com.rust.unittests</string>
43
48
</dict>
44
49
</plist>
45
- "# , crate_name) . as_bytes( ) ) ) ;
50
+ "# ,
51
+ crate_name
52
+ )
53
+ . as_bytes( )
54
+ ) ) ;
46
55
}
47
56
48
57
// Step two: Start the iOS simulator
@@ -57,8 +66,10 @@ fn start_simulator() {
57
66
for line in stdout. lines ( ) {
58
67
if line. contains ( "rust_ios" ) {
59
68
if found_rust_sim {
60
- panic ! ( "Duplicate rust_ios simulators found. Please \
61
- double-check xcrun simctl list.") ;
69
+ panic ! (
70
+ "Duplicate rust_ios simulators found. Please \
71
+ double-check xcrun simctl list."
72
+ ) ;
62
73
}
63
74
simulator_exists = true ;
64
75
simulator_booted = line. contains ( "(Booted)" ) ;
@@ -69,62 +80,67 @@ fn start_simulator() {
69
80
if simulator_exists == false {
70
81
println ! ( "Creating iOS simulator" ) ;
71
82
Command :: new ( "xcrun" )
72
- . arg ( "simctl" )
73
- . arg ( "create" )
74
- . arg ( "rust_ios" )
75
- . arg ( "com.apple.CoreSimulator.SimDeviceType.iPhone-SE" )
76
- . arg ( "com.apple.CoreSimulator.SimRuntime.iOS-10-2" )
77
- . check_status ( ) ;
83
+ . arg ( "simctl" )
84
+ . arg ( "create" )
85
+ . arg ( "rust_ios" )
86
+ . arg ( "com.apple.CoreSimulator.SimDeviceType.iPhone-SE" )
87
+ . arg ( "com.apple.CoreSimulator.SimRuntime.iOS-10-2" )
88
+ . check_status ( ) ;
78
89
} else if simulator_booted == true {
79
90
println ! ( "Shutting down already-booted simulator" ) ;
80
91
Command :: new ( "xcrun" )
81
- . arg ( "simctl" )
82
- . arg ( "shutdown" )
83
- . arg ( "rust_ios" )
84
- . check_status ( ) ;
92
+ . arg ( "simctl" )
93
+ . arg ( "shutdown" )
94
+ . arg ( "rust_ios" )
95
+ . check_status ( ) ;
85
96
}
86
97
87
98
println ! ( "Starting iOS simulator" ) ;
88
99
// We can't uninstall the app (if present) as that will hang if the
89
100
// simulator isn't completely booted; just erase the simulator instead.
90
- Command :: new ( "xcrun" ) . arg ( "simctl" ) . arg ( "erase" ) . arg ( "rust_ios" ) . check_status ( ) ;
91
- Command :: new ( "xcrun" ) . arg ( "simctl" ) . arg ( "boot" ) . arg ( "rust_ios" ) . check_status ( ) ;
101
+ Command :: new ( "xcrun" )
102
+ . arg ( "simctl" )
103
+ . arg ( "erase" )
104
+ . arg ( "rust_ios" )
105
+ . check_status ( ) ;
106
+ Command :: new ( "xcrun" )
107
+ . arg ( "simctl" )
108
+ . arg ( "boot" )
109
+ . arg ( "rust_ios" )
110
+ . check_status ( ) ;
92
111
}
93
112
94
113
// Step three: Install the app
95
114
fn install_app_to_simulator ( ) {
96
115
println ! ( "Installing app to simulator" ) ;
97
116
Command :: new ( "xcrun" )
98
- . arg ( "simctl" )
99
- . arg ( "install" )
100
- . arg ( "booted" )
101
- . arg ( "ios_simulator_app/" )
102
- . check_status ( ) ;
117
+ . arg ( "simctl" )
118
+ . arg ( "install" )
119
+ . arg ( "booted" )
120
+ . arg ( "ios_simulator_app/" )
121
+ . check_status ( ) ;
103
122
}
104
123
105
124
// Step four: Run the app
106
125
fn run_app_on_simulator ( ) {
107
126
println ! ( "Running app" ) ;
108
127
let output = t ! ( Command :: new( "xcrun" )
109
- . arg( "simctl" )
110
- . arg( "launch" )
111
- . arg( "--console" )
112
- . arg( "booted" )
113
- . arg( "com.rust.unittests" )
114
- . output( ) ) ;
128
+ . arg( "simctl" )
129
+ . arg( "launch" )
130
+ . arg( "--console" )
131
+ . arg( "booted" )
132
+ . arg( "com.rust.unittests" )
133
+ . output( ) ) ;
115
134
116
135
println ! ( "status: {}" , output. status) ;
117
136
println ! ( "stdout --\n {}\n " , String :: from_utf8_lossy( & output. stdout) ) ;
118
137
println ! ( "stderr --\n {}\n " , String :: from_utf8_lossy( & output. stderr) ) ;
119
138
120
139
let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
121
- let passed = stdout. lines ( )
122
- . find ( |l|
123
- ( l. contains ( "PASSED" ) &&
124
- l. contains ( "tests" ) ) ||
125
- l. contains ( "test result: ok" )
126
- )
127
- . unwrap_or ( false ) ;
140
+ let passed = stdout
141
+ . lines ( )
142
+ . find ( |l| ( l. contains ( "PASSED" ) && l. contains ( "tests" ) ) || l. contains ( "test result: ok" ) )
143
+ . unwrap_or ( false ) ;
128
144
129
145
println ! ( "Shutting down simulator" ) ;
130
146
Command :: new ( "xcrun" )
0 commit comments