@@ -128,14 +128,42 @@ impl ACommand {
128
128
/// ```txt
129
129
/// Android Debug Bridge version <num>.<num>.<num>
130
130
/// Version <num>.<num>.<num>-<no spaces>
131
- /// Installed as <ANDROID_SDK_HOME>/platform-tools/adb<optional extension>
131
+ /// Installed as <ANDROID_SDK_HOME>/platform-tools/adb[.exe]
132
132
/// Running on <OS/kernel version> (<CPU arch>)
133
133
/// ```
134
134
pub fn version ( mut self ) -> Result < Vec < String > , String > {
135
+ #[ cfg( debug_assertions) ]
136
+ static TRIPLE : LazyLock < Regex > = LazyLock :: new ( || {
137
+ Regex :: new ( r"^Android Debug Bridge version \d+.\d+.\d+$" )
138
+ . unwrap_or_else ( |_| unreachable ! ( ) )
139
+ } ) ;
140
+ #[ cfg( debug_assertions) ]
141
+ static DISTRO : LazyLock < Regex > = LazyLock :: new ( || {
142
+ Regex :: new ( r"^Version \d+.\d+.\d+-\S+$" ) . unwrap_or_else ( |_| unreachable ! ( ) )
143
+ } ) ;
144
+
135
145
self . 0 . arg ( "version" ) ;
136
146
// typically 5 allocs (after `lines`).
137
147
// ideally 0, if we didn't use `lines`.
138
- Ok ( self . run ( ) ?. lines ( ) . map ( str:: to_string) . collect ( ) )
148
+ Ok ( self
149
+ . run ( ) ?
150
+ . lines ( )
151
+ . enumerate ( )
152
+ . map ( |( i, ln) | {
153
+ debug_assert ! ( match i {
154
+ 0 => TRIPLE . is_match( ln) ,
155
+ 1 => DISTRO . is_match( ln) ,
156
+ 2 =>
157
+ // missing test for valid path
158
+ ln. starts_with( "Installed as " )
159
+ && ( ln. ends_with( "adb" ) || ln. ends_with( "adb.exe" ) ) ,
160
+ // missing test for x86/ARM (both 64b)
161
+ 3 => ln. starts_with( "Running on " ) ,
162
+ _ => unreachable!( "Expected < 5 lines" ) ,
163
+ } ) ;
164
+ ln. to_string ( )
165
+ } )
166
+ . collect ( ) )
139
167
}
140
168
141
169
/// General executor
0 commit comments