66// (https://github.com/snipsco/dinghy): cargo dinghy install, then cargo dinghy
77// test.
88
9- use std::env;
109use std::fs::{self, File};
1110use std::io::Write;
1211use std::path::Path;
13- use std::process;
1412use std::process::Command;
13+ use std::{env, process};
1514
1615macro_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+ };
2122}
2223
2324// Step one: Wrap as an app
2425fn package_as_simulator_app(crate_name: &str, test_binary_path: &Path) {
2526 println!("Packaging simulator app");
2627 drop(fs::remove_dir_all("ios_simulator_app"));
2728 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+ ));
3033
3134 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#"
3338 <?xml version="1.0" encoding="UTF-8"?>
3439 <!DOCTYPE plist PUBLIC
3540 "-//Apple//DTD PLIST 1.0//EN"
@@ -42,7 +47,11 @@ fn package_as_simulator_app(crate_name: &str, test_binary_path: &Path) {
4247 <string>com.rust.unittests</string>
4348 </dict>
4449 </plist>
45- "#, crate_name).as_bytes()));
50+ "#,
51+ crate_name
52+ )
53+ .as_bytes()
54+ ));
4655}
4756
4857// Step two: Start the iOS simulator
@@ -57,8 +66,10 @@ fn start_simulator() {
5766 for line in stdout.lines() {
5867 if line.contains("rust_ios") {
5968 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+ );
6273 }
6374 simulator_exists = true;
6475 simulator_booted = line.contains("(Booted)");
@@ -69,62 +80,67 @@ fn start_simulator() {
6980 if simulator_exists == false {
7081 println!("Creating iOS simulator");
7182 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();
7889 } else if simulator_booted == true {
7990 println!("Shutting down already-booted simulator");
8091 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();
8596 }
8697
8798 println!("Starting iOS simulator");
8899 // We can't uninstall the app (if present) as that will hang if the
89100 // 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();
92111}
93112
94113// Step three: Install the app
95114fn install_app_to_simulator() {
96115 println!("Installing app to simulator");
97116 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();
103122}
104123
105124// Step four: Run the app
106125fn run_app_on_simulator() {
107126 println!("Running app");
108127 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());
115134
116135 println!("status: {}", output.status);
117136 println!("stdout --\n{}\n", String::from_utf8_lossy(&output.stdout));
118137 println!("stderr --\n{}\n", String::from_utf8_lossy(&output.stderr));
119138
120139 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);
128144
129145 println!("Shutting down simulator");
130146 Command::new("xcrun")
0 commit comments