11import glob
22import os
3- from typing import Dict , List , Optional
3+ import re
4+ from typing import Dict , List , Optional , Tuple
45
56import click
67
@@ -60,9 +61,24 @@ def is_file(f: str) -> bool:
6061 is_flag = True ,
6162 help = "Scan testCompile/default-testCompile/createdFiles.lst for *.lst files generated by `mvn compile` and use them as test inputs." , # noqa: E501
6263)
64+ @click .option (
65+ '--exclude' ,
66+ 'exclude_rules' ,
67+ required = False ,
68+ multiple = True ,
69+ help = "Exclude tests matching the given Python regular expression pattern. Can be specified multiple times." ,
70+ )
6371@click .argument ('source_roots' , required = False , nargs = - 1 )
6472@launchable .subset
65- def subset (client , source_roots , test_compile_created_file , is_scan_test_compile_lst ):
73+ def subset (client , source_roots , test_compile_created_file , is_scan_test_compile_lst , exclude_rules : Tuple [str , ...]):
74+
75+ # Compile exclude rules
76+ compiled_exclude_rules = []
77+ for rule in exclude_rules :
78+ try :
79+ compiled_exclude_rules .append (re .compile (rule ))
80+ except re .error as e :
81+ raise click .BadParameter ("Invalid regular expression '{}': {}" .format (rule , e ))
6682
6783 def file2class_test_path (f : str ) -> List [Dict [str , str ]]:
6884 # remove extension
@@ -74,7 +90,13 @@ def file2class_test_path(f: str) -> List[Dict[str, str]]:
7490
7591 def file2test (f : str ) -> Optional [List ]:
7692 if is_file (f ):
77- return file2class_test_path (f )
93+ test_path = file2class_test_path (f )
94+
95+ for pattern in compiled_exclude_rules :
96+ if pattern .search (test_path [0 ]["name" ]):
97+ return None
98+
99+ return test_path
78100 else :
79101 return None
80102
0 commit comments