Skip to content

Commit

Permalink
Cross-platform support and auto-discovery for test tools
Browse files Browse the repository at this point in the history
  • Loading branch information
RReverser committed Dec 13, 2024
1 parent 177b632 commit eb68014
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
4 changes: 1 addition & 3 deletions src/test_utils/conformu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::process::Stdio;
use tokio::io::{AsyncBufReadExt, BufReader};
use tokio::process::Command;

/// The kind of test to run with ConformU.
#[derive(Debug, Clone, Copy)]
Expand All @@ -22,10 +21,9 @@ impl ConformU {

/// Run the specified test with ConformU against the specified device URL.
pub async fn run(self, device_url: &str) -> eyre::Result<()> {
let mut conformu = Command::new(r"C:\Program Files\ASCOM\ConformU\conformu.exe")
let mut conformu = cmd!(r"C:\Program Files\ASCOM\ConformU", "conformu")
.arg(self.as_arg())
.arg(device_url)
.stdin(Stdio::null())
.stdout(Stdio::piped())
.spawn()?;

Expand Down
22 changes: 22 additions & 0 deletions src/test_utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
#[cfg(test)]
mod logging_env;

macro_rules! cmd {
($windows_path_hint:literal, $name:literal) => {
tokio::process::Command::new(if cfg!(windows) {
static ADD_COMMON_PATH: std::sync::Once = std::sync::Once::new();

ADD_COMMON_PATH.call_once(|| {
let mut path = std::env::var_os("PATH").unwrap_or_default();
path.push(concat!(";", $windows_path_hint));
unsafe {
std::env::set_var("PATH", path);
}
});

concat!($name, ".exe")
} else {
$name
})
.kill_on_drop(true)
.stdin(Stdio::null())
};
}

#[cfg(feature = "server")]
mod conformu;
#[cfg(feature = "server")]
Expand Down
22 changes: 12 additions & 10 deletions src/test_utils/omnisim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use net_literals::addr;
use std::net::SocketAddr;
use std::process::Stdio;
use std::sync::{Arc, Weak};
use tokio::process::{Child, Command};
use tokio::process::Child;
use tokio::sync::Mutex;

/// A helper that manages [ASCOM Alpaca Simulators](https://github.com/ASCOMInitiative/ASCOM.Alpaca.Simulators).
Expand All @@ -23,15 +23,17 @@ impl OmniSim {
async fn new() -> eyre::Result<Self> {
const ADDR: SocketAddr = addr!("127.0.0.1:32323");

let mut server =
Command::new(r"C:\Program Files\ASCOM\OmniSimulator\ascom.alpaca.simulators.exe")
.arg(format!("--urls=http://{ADDR}"))
.arg("--set-no-browser")
.stdin(Stdio::null())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.kill_on_drop(true)
.spawn()?;
let mut server = cmd!(
r"C:\Program Files\ASCOM\OmniSimulator",
"ascom.alpaca.simulators"
)
.arg(format!("--urls=http://{ADDR}"))
.arg("--set-no-browser")
.stdin(Stdio::null())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.kill_on_drop(true)
.spawn()?;

tokio::select! {
() = async {
Expand Down

0 comments on commit eb68014

Please sign in to comment.