diff --git a/src/core/adb.rs b/src/core/adb.rs index a918628..5f741d1 100644 --- a/src/core/adb.rs +++ b/src/core/adb.rs @@ -128,14 +128,42 @@ impl ACommand { /// ```txt /// Android Debug Bridge version .. /// Version ..- - /// Installed as /platform-tools/adb + /// Installed as /platform-tools/adb[.exe] /// Running on () /// ``` pub fn version(mut self) -> Result, String> { + #[cfg(debug_assertions)] + static TRIPLE: LazyLock = LazyLock::new(|| { + Regex::new(r"^Android Debug Bridge version \d+.\d+.\d+$") + .unwrap_or_else(|_| unreachable!()) + }); + #[cfg(debug_assertions)] + static DISTRO: LazyLock = LazyLock::new(|| { + Regex::new(r"^Version \d+.\d+.\d+-\S+$").unwrap_or_else(|_| unreachable!()) + }); + self.0.arg("version"); // typically 5 allocs (after `lines`). // ideally 0, if we didn't use `lines`. - Ok(self.run()?.lines().map(str::to_string).collect()) + Ok(self + .run()? + .lines() + .enumerate() + .map(|(i, ln)| { + debug_assert!(match i { + 0 => TRIPLE.is_match(ln), + 1 => DISTRO.is_match(ln), + 2 => + // missing test for valid path + ln.starts_with("Installed as ") + && (ln.ends_with("adb") || ln.ends_with("adb.exe")), + // missing test for x86/ARM (both 64b) + 3 => ln.starts_with("Running on "), + _ => unreachable!("Expected < 5 lines"), + }); + ln.to_string() + }) + .collect()) } /// General executor