@@ -87,7 +87,7 @@ def wrapper(*pargs, **kwargs):
8787 return wrapper
8888
8989
90- def merge_files (args ):
90+ def merge_files (args , base_path ):
9191 """Merges coverage files."""
9292
9393 try :
@@ -107,11 +107,25 @@ def merge_files(args):
107107
108108 try :
109109 with args .out .open ("w" , encoding = 'utf-8' ) as jf :
110- json .dump (merged , jf )
110+ if args .xml :
111+ sc .print_xml (merged , source_paths = [str (base_path )], with_branches = args .branch ,
112+ xml_package_depth = args .xml_package_depth , outfile = jf )
113+ else :
114+ json .dump (merged , jf , indent = (4 if args .pretty_print else None ))
115+
116+ # print human-readable table for merge results
117+ if not args .silent :
118+ sc .print_coverage (merged , outfile = sys .stdout , skip_covered = args .skip_covered ,
119+ missing_width = args .missing_width )
120+
111121 except Exception as e :
112122 warnings .warn (str (e ))
113123 return 1
114124
125+ if args .fail_under :
126+ if merged ['summary' ]['percent_covered' ] < args .fail_under :
127+ return 2
128+
115129 return 0
116130
117131
@@ -168,15 +182,15 @@ def main():
168182 args = ap .parse_args (sys .argv [1 :])
169183
170184
171- if args .merge :
172- if not args .out : ap .error ("--out is required with --merge" )
173- return merge_files (args )
174-
175-
176185 base_path = Path (args .script ).resolve ().parent if args .script \
177186 else Path ('.' ).resolve ()
178187
179188
189+ if args .merge :
190+ if not args .out : ap .error ("--out is required with --merge" )
191+ return merge_files (args , base_path = base_path )
192+
193+
180194 file_matcher = sc .FileMatcher ()
181195
182196 if args .source :
0 commit comments