Commits

Ned Batchelder  committed 8440082

The cmdline code now returns a status code.

  • Participants
  • Parent commits 90c5f53

Comments (0)

Files changed (2)

 - If tracing, canonical_filename_cache overlaps with should_trace_cache.  Skip
     canonical_filename_cache. Maybe it isn't even worth it...
 
+
 * Accuracy
 
 - Record magic number of module to ensure code hasn't changed
     sense together.
 - Do I still need the lines in annotate_file that deal specially with "else"?
 
+
 * Power
 
 - API for getting coverage data.
 - Track callers of functions (ala std module trace)
 - Method/Class/Module coverage reporting.
 
+
 * Convenience
 
 - Why can't you specify execute (-x) and report (-r) in the same invocation?
 - Support 2.3 - 3.0?
     http://pythonology.blogspot.com/2009/02/making-code-run-on-python-20-through-30.html
 
+
 * Beauty
 
 - HTML report
 - Dynamic effects in HTML report
 - Footer in reports pointing to coverage home page.
 
+
 * Community
 
 - New docs, rather than pointing to Gareth's
 - Point discussion to TIP
 - PEP 8 compliance?
 
+
+* Programmability
+
++ Don't use sys.exit in CoverageScript.
++ Remove singleton
+    + Initialization of instance variables in the class.
+
+
 * Modernization
 
 + Decide on minimum supported version
 - Get rid of the recursive nonsense.
 - Docstrings.
 + Remove huge document-style comments.
-+ Remove singleton
-    + Initialization of instance variables in the class.
 - Better names:
     + self.cache -> self.cache_filename -> CoverageData.filename
     + self.usecache -> CoverageData.use_file
     + lineno
     + filename
 
+
 * Correctness
 
 - What does -p (parallel mode) mean with -e (erase data)?
 
+
 * Tests
 
 + Switch to a real test runner, like nose.

File coverage/cmdline.py

 COVERAGE_FILE environment variable to save it somewhere else.
 """.strip()
 
+
 class CoverageScript:
     def __init__(self):
         import coverage
             print error
             print
         print USAGE % self.covpkg.__dict__
-        sys.exit(1)
 
     def command_line(self, argv, help_fn=None):
         # Collect the command-line options.
         help_fn = help_fn or self.help
+        OK, ERR = 0, 1
         settings = {}
         optmap = {
             '-a': 'annotate',
 
         if settings.get('help'):
             help_fn()
+            return OK
 
         # Check for conflicts and problems in the options.
         for i in ['erase', 'execute']:
                 if settings.get(i) and settings.get(j):
                     help_fn("You can't specify the '%s' and '%s' "
                               "options at the same time." % (i, j))
+                    return ERR
 
         args_needed = (settings.get('execute')
                        or settings.get('annotate')
                   or args_needed)
         if not action:
             help_fn("You must specify at least one of -e, -x, -c, -r, or -a.")
+            return ERR
         if not args_needed and args:
             help_fn("Unexpected arguments: %s" % " ".join(args))
+            return ERR
         
         # Do something.
         self.coverage.parallel_mode = settings.get('parallel-mode')
         if settings.get('execute'):
             if not args:
                 help_fn("Nothing to do.")
+                return ERR
             # Create the runtime environment the script on the cmdline expects.
             sys.argv = args
             sys.path[0] = os.path.dirname(sys.argv[0])
         if settings.get('annotate'):
             reporter = AnnotateReporter(self.coverage, ignore_errors)
             reporter.report(args, directory, omit_prefixes=omit)
-
+        
+        return OK
     
 # Main entrypoint.  This is installed as the script entrypoint, so don't
 # refactor it away...
 def main():
-    CoverageScript().command_line(sys.argv[1:])
+    return CoverageScript().command_line(sys.argv[1:])