Ticket #7993: scripts_7993_doctest_error_handling.patch

File scripts_7993_doctest_error_handling.patch, 6.0 KB (added by wjp, 10 years ago)
  • sage-doctest

    # HG changeset patch
    # User Willem Jan Palenstijn <wjp@usecode.org>
    # Date 1264013535 28800
    # Node ID e45460522cac41831165aaa86b621a2099cf90b9
    # Parent  16b3b23d6da3ad7f44fa356ae9a8adedb71521d8
    #7993: clean up error handling in sage-doctest
    
    diff -r 16b3b23d6da3 -r e45460522cac sage-doctest
    a b  
    55# Sage's custom doctesting tags and framework built on top of
    66# Python's doctest functionality.  In particular, this allows for
    77# sage: prompts, preparsing, optional doctests, random behavior, etc.
     8#
     9# Return value in process exit code:
     10# 0: all tests passed
     11# 1: file not found
     12# 2: KeyboardInterrupt
     13# 3: doctest process was terminated by a signal
     14# 4: the doctesting framework raised an exception
     15# 100: failed doctests
    816####################################################################
    917
    1018# System imports
     
    152160        return n
    153161
    154162def test_code(filename):
     163    # Process exit codes for the generated doctest runner script:
     164    # 0: everything passed
     165    # 1-253: number of failed doctests
     166    # 254: >= 254 doctests failed
     167    # 255: exception raised by doctesting framework
    155168    dict = { 'DIR'             : repr(os.path.join(SAGE_ROOT, 'local', 'bin')),
    156169             'FILENAME'        : repr(filename),
    157170             'OUTPUT_FILENAME' : repr(filename + '.timeit.sobj'),
     
    171184    m = sys.modules[__name__]
    172185    m.__file__ = %(FILENAME)s
    173186
    174     # configure special sage doc test runner
    175     runner = sagedoctest.SageDocTestRunner(checker=None, verbose=verbose, optionflags=0)
    176     runner._collect_timeit_stats = do_timeit
    177     runner._reset_random_seed = True
     187    try:
    178188
    179     runner = sagedoctest.testmod_returning_runner(m,
    180                    # filename=%(FILENAME)s,
    181                    verbose=verbose,
    182                    globs=globals(),
    183                    runner=runner)
    184     runner.save_timeit_stats_to_file_named(output_filename)
     189        # configure special sage doc test runner
     190        runner = sagedoctest.SageDocTestRunner(checker=None, verbose=verbose, optionflags=0)
     191        runner._collect_timeit_stats = do_timeit
     192        runner._reset_random_seed = True
     193
     194        runner = sagedoctest.testmod_returning_runner(m,
     195                       # filename=%(FILENAME)s,
     196                       verbose=verbose,
     197                       globs=globals(),
     198                       runner=runner)
     199        runner.save_timeit_stats_to_file_named(output_filename)
     200    except:
     201        quit_sage(verbose=False)
     202        import traceback
     203        traceback.print_exc(file=sys.stdout)
     204        sys.exit(255)
    185205    quit_sage(verbose=False)
     206    if runner.failures > 254:
     207        sys.exit(254)
    186208    sys.exit(runner.failures)
    187209""" % dict
    188210
     
    656678        s, numfail = post_process(out, file, f)
    657679        s += err
    658680
    659         if numfail == 0 and e > 0 and verbose:
     681        if e == 255:
     682            # The doctesting code raised an exception
     683            if not verbose:
     684                print "Exception raised by doctesting framework. Use -verbose for details."
     685            sys.exit(4)
     686
     687        if numfail == 0 and e > 0:
    660688            numfail = e
    661689        if numfail > 0:
    662690            if not (verbose or gdb or memcheck or massif or cachegrind):
    663691                print s
    664             sys.exit(4)
    665         elif e != 0:
     692            sys.exit(100)
     693        elif e < 0:
    666694            if not verbose:
    667                 print "A mysterious error (perhaps a memory error?) occurred, which may have crashed doctest."
     695                print "The doctested process was killed by signal %s" % (-e)
    668696            sys.exit(3)
    669697        else:
    670698            delete_tmpfiles()
  • sage-ptest

    diff -r 16b3b23d6da3 -r e45460522cac sage-ptest
    a b  
    164164    finished_time = result[2]
    165165    ol = result[3]
    166166    if ret != 0:
    167         if ret == -4:
     167        if ret == -100:
    168168            numfail = ol.count('Expected:') + ol.count('Expected nothing') + ol.count('Exception raised:')
    169169            failed.append(abs(F)+(" # %s doctests failed" % numfail))
    170170            ret = numfail
     171        elif ret == -4:
     172            failed.append(abs(F)+" # Exception from doctest framework")
    171173        elif ret == -3:
    172             failed.append(abs(F)+" # Segfault")
     174            failed.append(abs(F)+" # Killed/crashed")
    173175        elif ret == -2:
    174176            failed.append(abs(F)+" # KeyboardInterrupt")
    175177        elif ret == -1:
  • sage-test

    diff -r 16b3b23d6da3 -r e45460522cac sage-test
    a b  
    8585    # value in the second byte.
    8686    err = err // 256
    8787
    88     # Check the process exit codes that sage-doctest returns
     88    # Check the process exit code that sage-doctest returns
    8989
    9090    if err == 1: # process exit code 1: File not found
    9191        failed.append(sage_test_command(F)+" # File not found")
    9292    elif err == 2: # process exit code 2: KeyboardInterrupt
    9393        failed.append(sage_test_command(F)+" # KeyboardInterrupt")
    9494        raise KeyboardInterrupt
    95     elif err == 3: # process exit code 3: Segfault
    96         failed.append(sage_test_command(F)+" # Segfault")
    97     elif err == 4: # process exit code 4: Failures
     95    elif err == 3: # process exit code 3: Terminated by signal
     96        failed.append(sage_test_command(F)+" # Killed/crashed")
     97    elif err == 4: # process exit code 4: Unhandled doctest exception
     98        failed.append(sage_test_command(F)+" # Exception from doctest framework")
     99    elif err == 100: # process exit code 100: Regular doctest failures
    98100        failed.append(sage_test_command(F))
    99101    elif err != 0:
    100102        failed.append(sage_test_command(F))
     
    110112    if not os.path.exists(F):
    111113        if F[:6] != "__test" and not F.endswith('.png'):
    112114            print "ERROR: File %s is missing" % os.path.join(os.curdir, F)
    113             failed.append(os.path.join(os.curdir, F))
     115            failed.append(os.path.join(os.curdir, F) + " # File not found")
    114116        return 1
    115117
    116118    extra_opts = ''