1use std::path::PathBuf;
2
3#[cfg(test)]
4mod logging_env;
5
6#[cfg(feature = "client")]
7pub use crate::client::test::get_simulator_devices;
8
9#[cfg(feature = "server")]
10pub use crate::server::test::run_conformu_tests;
11
12pub(crate) fn resolve_path(path_hint: &'static str, exe_name: &'static str) -> PathBuf {
13 use std::env;
14
15 env::split_paths(&env::var_os("PATH").unwrap_or_default())
16 .chain(std::iter::once(path_hint.into()))
17 .map(|path| path.join(exe_name))
18 .find(|path| path.exists())
19 .unwrap_or_else(|| panic!("{exe_name} not found in either PATH or the standard installation directory {path_hint}"))
20}
21
22macro_rules! cmd {
23 ($windows_path_hint:literal, $name:literal) => {
24 tokio::process::Command::new(if cfg!(windows) {
25 use std::sync::LazyLock;
26 static RESOLVED_PATH: LazyLock<std::path::PathBuf> = LazyLock::new(|| {
28 $crate::test::resolve_path($windows_path_hint, concat!($name, ".exe"))
29 });
30 &RESOLVED_PATH
31 } else {
32 std::path::Path::new($name)
34 })
35 .kill_on_drop(true)
36 .stdin(Stdio::null())
37 };
38}
39
40#[cfg(test)]
41pub(crate) async fn run_proxy_tests<T: ?Sized + crate::api::RetrieavableDevice>() -> eyre::Result<()>
42{
43 use crate::Server;
44 use crate::api::CargoServerInfo;
45 use crate::client::test::get_simulator_devices;
46 use crate::server::test::run_conformu_tests;
47 use net_literals::addr;
48
49 let proxy = Server {
50 devices: get_simulator_devices().await?.clone(),
51 listen_addr: addr!("127.0.0.1:0"),
52 ..Server::new(CargoServerInfo!())
53 };
54
55 let proxy = proxy.bind().await?;
56
57 let server_url = format!("http://{}/", proxy.listen_addr());
59
60 tokio::select! {
61 proxy_result = proxy.start() => match proxy_result? {},
62 tests_result = run_conformu_tests::<T>(server_url, 0) => tests_result,
63 }
64}