polyhorn_cli/ios/commands/
test.rs

1use ansi_term::Colour::Red;
2use simctl::Simctl;
3
4use super::select_device;
5use crate::core::Executioner;
6use crate::ios::tasks::{self, IOSContext, IOSTask};
7use crate::Config;
8
9/// iOS specific implementation of the `polyhorn test` command.
10pub fn test(config: Config) {
11    let list = Simctl::new().list().unwrap();
12    let device = select_device(list.devices());
13
14    let (addr, _server) = crate::test::serve(crate::test::Device::IOS {
15        device: device.clone(),
16        runtime: list
17            .runtimes()
18            .iter()
19            .find(|runtime| runtime.identifier == device.runtime_identifier)
20            .unwrap()
21            .to_owned(),
22        device_type: list
23            .device_types()
24            .iter()
25            .find(|device_type| device_type.identifier == device.device_type_identifier)
26            .unwrap()
27            .to_owned(),
28    });
29
30    let result = Executioner::execute(
31        &[
32            IOSTask::InstallDependencies(tasks::InstallDependencies {
33                dependencies: vec![
34                    tasks::Dependency::cli(
35                        "resvg",
36                        &["resvg", "-V"],
37                        &["cargo", "install", "resvg"],
38                    ),
39                    tasks::Dependency::cli(
40                        "xcodegen",
41                        &["xcodegen", "--version"],
42                        &["brew", "install", "xcodegen"],
43                    ),
44                ],
45            }),
46            IOSTask::InstallTarget(tasks::InstallTarget("x86_64-apple-ios")),
47            IOSTask::BuildRuntimeLibraryV2(tasks::BuildRuntimeLibraryV2 {
48                cfg: "test",
49                target: "x86_64-apple-ios",
50                profile: "dev",
51                flags: &[],
52            }),
53            IOSTask::CreateUniversalBinary(tasks::CreateUniversalBinary),
54            IOSTask::GenerateXcassets(tasks::GenerateXcassets),
55            IOSTask::GenerateXcodeproj(tasks::GenerateXcodeproj),
56            IOSTask::BuildXcodeproj(tasks::BuildXcodeproj {
57                scheme: config.spec.app.name.clone() + "_iOS",
58                configuration: "Debug".to_owned(),
59                destination_platform: "iOS Simulator".to_owned(),
60                destination_name: device.name.clone(),
61            }),
62            IOSTask::BootIOSSimulator(tasks::BootIOSSimulator {
63                device: device.clone(),
64            }),
65            IOSTask::InstallOnIOSSimulator(tasks::InstallOnIOSSimulator {
66                device: device.clone(),
67                configuration: "Debug".to_owned(),
68            }),
69            IOSTask::RunOnIOSSimulator(tasks::RunOnIOSSimulator {
70                device: device.clone(),
71                env: vec![(
72                    "POLYHORN_TEST_FEEDBACK_URL".to_owned(),
73                    format!("http://{}/polyhorn/tests/test", addr),
74                )],
75            }),
76        ],
77        IOSContext {
78            config,
79            products: Default::default(),
80            universal_binary_path: None,
81        },
82    );
83
84    match result {
85        Ok(_) => {}
86        Err(error) => {
87            eprintln!("{}: {:?}", Red.bold().paint("error"), error);
88            std::process::exit(1);
89        }
90    }
91}