4040import subprocess
4141import argparse
4242
43- from vcast_utils import dump , checkVectorCASTVersion , getVectorCASTEncoding , checkProjectResults
43+ from vcast_utils import dump , checkVectorCASTVersion , getVectorCASTEncoding
4444try :
4545 from safe_open import open
4646except :
4747 pass
4848
49- try :
50- import math
51- INF = math .inf
52- except Exception :
53- INF = float ("inf" ) # Py2-compatible
5449encFmt = getVectorCASTEncoding ()
5550
5651fileList = []
@@ -121,43 +116,28 @@ def has_branches_covered(line):
121116
122117def get_function_name_line_number (file_path , function , initial_guess ):
123118
124- with open (file_path , "rb" ) as fd :
119+ with open (file_path ,"rb" ) as fd :
125120 lines = [line .decode (encFmt , "replace" ) for line in fd .readlines ()]
121+
122+ line_number_closest_so_far = initial_guess ;
123+ delta = 9999999999 ;
126124
127- if initial_guess is None or initial_guess >= len (lines ):
128- initial_guess = len (lines ) - 1
129-
130- line_number_closest_so_far = initial_guess
131- delta = INF
132-
133- for count , line in enumerate (reversed (lines [:initial_guess + 1 ])):
134- if function in line .replace (" " , "" ):
125+ # print(function, line_number_closest_so_far, delta, initial_guess)
126+ for count , line in enumerate (reversed (lines [:initial_guess + 1 ])):
127+ if function in line .replace (" " ,"" ):
135128 line_num = initial_guess - count
136129 if abs (line_num - initial_guess ) < delta :
137130 line_number_closest_so_far = line_num
138131 delta = abs (line_num - initial_guess )
139-
140- return line_number_closest_so_far + 1 # convert 0-based to 1-based
141-
132+ # print(function, line_number_closest_so_far, delta, initial_guess)
133+
134+ # print(line_number_closest_so_far + 1,function)
135+ return line_number_closest_so_far + 1 ## add one since python starts from 0
142136
143137def runCoverageResultsMP (mpFile , verbose = False , testName = "" , source_root = "" ):
144138
145139 with VCProjectApi (mpFile ) as vcproj :
146-
147- anyLocalResults , anyImportedResults = checkProjectResults (vcproj )
148-
149- if anyImportedResults :
150- importedResultsError = " ** LCOV results does not processing imported results at this time\n \n "
151- print (importedResultsError )
152- return importedResultsError
153-
154- if not anyLocalResults :
155- localResultsError = " ** No local results in project to process\n \n "
156- print (localResultsError )
157- return localResultsError
158-
159140 api = vcproj .project .cover_api
160-
161141 results = runGcovResults (api , verbose = verbose , testName = vcproj .project .name , source_root = source_root )
162142
163143 return results
@@ -173,7 +153,7 @@ def runGcovResults(api, verbose = False, testName = "", source_root = "") :
173153 except :
174154 prj_dir = os .getcwd ().replace ("\\ " ,"/" ) + "/"
175155
176- # get a sorted listed of all the files with the proj directory stripped off
156+ # get a sorted listed of all the files with the proj directory stripped off
177157 for file in api .SourceFile .all ():
178158 if file .display_name == "" :
179159 continue
0 commit comments