Ticket #8641: trac_8641-doctest_exit_codes.patch

File trac_8641-doctest_exit_codes.patch, 2.3 KB (added by Mitesh Patel, 12 years ago)

Combined patch rebased vs 4.4.4.alpha0 + #8891. Replaces all previous.

  • sage-test

    # HG changeset patch
    # User Mitesh Patel <qed777@gmail.com>
    # Date 1276507681 25200
    # Node ID 2ff7303467880d41a42446db4f6c567b60e74f43
    # Parent  41c43d811d77ebc06c2fc223c3bb7bd36c8322c6
    trac 8641: return nonzero code if tests fail.  Dan Drake, John Palmieri
    
    diff --git a/sage-test b/sage-test
    a b def strip_automount_prefix(filename): 
    2323    """
    2424    Strip prefixes added on automounted filesystems in some cases,
    2525    which make the absolute path appear hidden.
    26    
     26
    2727    AUTHOR:
    2828        -- Kate Minola
    2929    """
    def skip(F): 
    7676failed = []
    7777
    7878def test(F, cmd):
     79    from subprocess import call
    7980    t = time.time()
    8081    if skip(F):
    8182        return 0
    8283    s = os.path.join(SAGE_ROOT, 'local', 'bin', 'sage-%s' % cmd) + ' "%s"' % F
    83     err = os.system(s)
    84     # On unix systems, the return value of os.system has the process return
    85     # value in the second byte.
    86     err = err // 256
     84    err = call(s, shell=True)
    8785
    8886    # Check the process exit code that sage-doctest returns
    8987
    def test_file(F): 
    120118        extra_opts = ' -force_lib'
    121119
    122120    base, ext = os.path.splitext(F)
     121    err = 0
    123122    if ext in ['.py', '.spyx', '.pyx', '.tex', '.pxi', '.sage', '.rst']:
    124         test(F, 'doctest ' + opts + extra_opts)
     123        err = err | test(F, 'doctest ' + opts + extra_opts)
    125124    elif (os.path.isdir(F) and  not '#' in F and
    126125          not os.sep + 'notes' in F):
    127126        ld = os.listdir(F)
    128127        if not ('__nodoctest__' in ld):
    129128            for L in ld:
    130                 k = test_file(os.path.join(F, L))
    131     return 0
     129                err = err | test_file(os.path.join(F, L))
     130    return err
    132131
    133132files = argv[1:]
    134133
    if len(files) == 0: 
    163162    print "     -randorder     -- if given, randomize *order* of tests"
    164163    print "     -randorder=seed-- use seed to get same random order"
    165164    print "     -sagenb        -- test all sagenb files"
    166    
     165
    167166    sys.exit(1)
    168167
    169168files.sort()
    170        
     169
     170err = 0
    171171for F in files:
    172172    try:
    173         test_file(F)
     173        err = err | test_file(F)
    174174    except KeyboardInterrupt:
    175175        print "Aborting further tests."
     176        err = 2
    176177        break
    177    
     178
    178179print " "
    179180print "-"*int(70)
    180181
    else: 
    185186    print "\n\t" + "\n\t".join(failed)
    186187
    187188print "Total time for all tests: %.1f seconds"%(time.time() - t0)
     189sys.exit(err)