@@ -237,15 +237,55 @@ def getTargetValidityProblems(self):
237237 return problems
238238
239239 def getCoverageProblems (self ):
240- """Verify that each rule and each exclusion has the right number of tests
241- that applies to it. TODO: Also check that each target has the right
240+ """Verify that each target, rule and exclusion has the right number of tests
241+ that applies to it. Also check that each target has the right
242242 number of tests. In particular left-wildcard targets should have at least
243243 three tests. Right-wildcard targets should have at least ten tests.
244244
245245 Returns an array of strings reporting any coverage problems if they exist,
246246 or empty list if coverage is sufficient.
247247 """
248248 problems = self ._determineTestApplication ()
249+
250+ # First, check each target has the right number of tests
251+ myTestTargets = []
252+
253+ # Only take tests which are not excluded into account
254+ for test in self .tests :
255+ if not self .excludes (test .url ):
256+ urlParts = urlparse (test .url )
257+ hostname = urlParts .hostname
258+ myTestTargets .append (hostname )
259+
260+ for target in self .targets :
261+ actual_count = 0
262+ needed_count = 1
263+
264+ if target .startswith ("*." ):
265+ needed_count = 3
266+
267+ if target .endswith (".*" ):
268+ needed_count = 10
269+
270+ # non-wildcard target always have a implicit test url, if is it not excluded
271+ if not "*" in target and not self .excludes (("http://%s/" % target )):
272+ continue
273+
274+ # '*.example.com' match 'www.example.com' but not 'secure.account.exmple.com'
275+ pattern = target .replace ('.' , '\.' ).replace ('*' , '[^\.]+' )
276+ pattern = '^' + pattern + '$'
277+
278+ for test in myTestTargets :
279+ if regex .search (pattern , test ) is not None :
280+ actual_count += 1
281+
282+ if not actual_count < needed_count :
283+ break
284+
285+ if actual_count < needed_count :
286+ problems .append ("%s: Not enough tests (%d vs %d) for %s" % (
287+ self .filename , actual_count , needed_count , target ))
288+
249289 # Next, make sure each rule or exclusion has sufficient tests.
250290 for rule in self .rules :
251291 needed_count = 1 + len (regex .findall ("[+*?|]" , rule .fromPattern ))
0 commit comments