@@ -204,11 +204,20 @@ pub fn run_clang_tidy(
204
204
205
205
#[ cfg( test) ]
206
206
mod test {
207
+ use std:: { env, path:: PathBuf , process:: Command } ;
208
+
209
+ use regex:: Regex ;
210
+
211
+ use crate :: { clang_tools:: get_clang_tool_exe, common_fs:: FileObj } ;
212
+
213
+ use super :: run_clang_tidy;
214
+
215
+ // ***************** test for regex parsing of clang-tidy stdout
216
+
207
217
#[ test]
208
218
fn test_capture ( ) {
209
219
let src = "tests/demo/demo.hpp:11:11: warning: use a trailing return type for this function [modernize-use-trailing-return-type]" ;
210
- let pat =
211
- regex:: Regex :: new ( r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+)\]$" ) . unwrap ( ) ;
220
+ let pat = Regex :: new ( r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+)\]$" ) . unwrap ( ) ;
212
221
let cap = pat. captures ( src) . unwrap ( ) ;
213
222
assert_eq ! (
214
223
cap. get( 0 ) . unwrap( ) . as_str( ) ,
@@ -224,4 +233,36 @@ mod test {
224
233
. as_str( )
225
234
)
226
235
}
236
+
237
+ #[ test]
238
+ fn use_extra_args ( ) {
239
+ let exe_path = get_clang_tool_exe (
240
+ "clang-tidy" ,
241
+ env:: var ( "CLANG_VERSION" ) . unwrap_or ( "" . to_string ( ) ) . as_str ( ) ,
242
+ )
243
+ . unwrap ( ) ;
244
+ let mut cmd = Command :: new ( exe_path) ;
245
+ let file = FileObj :: new ( PathBuf :: from ( "tests/demo/demo.cpp" ) ) ;
246
+ let extra_args = vec ! [ "-std=c++17" , "-Wall" ] ;
247
+ let tidy_advice = run_clang_tidy (
248
+ & mut cmd,
249
+ & file,
250
+ "" , // use .clang-tidy config file
251
+ 0 , // check all lines
252
+ & None , // no database path
253
+ & Some ( extra_args) , // <---- the reason for this test
254
+ & None , // no deserialized database
255
+ ) ;
256
+ // since `cmd` was passed as a mutable reference, we can inspect the args that were added
257
+ let mut args = cmd
258
+ . get_args ( )
259
+ . map ( |arg| arg. to_str ( ) . unwrap ( ) )
260
+ . collect :: < Vec < & str > > ( ) ;
261
+ assert_eq ! ( file. name. to_string_lossy( ) , args. pop( ) . unwrap( ) ) ;
262
+ assert_eq ! (
263
+ vec![ "--extra-arg" , "\" -std=c++17\" " , "--extra-arg" , "\" -Wall\" " ] ,
264
+ args
265
+ ) ;
266
+ assert ! ( !tidy_advice. is_empty( ) ) ;
267
+ }
227
268
}
0 commit comments