Changeset c5b2c22 in autowaf


Ignore:
Timestamp:
Sep 23, 2017, 12:41:28 PM (8 weeks ago)
Author:
David Robillard <d@…>
Branches:
master
Parents:
33ab2c6
Message:

Improve testing API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • autowaf.py

    r33ab2c6 rc5b2c22  
    711711        cd_to_orig_dir(ctx, top_level)
    712712
    713 def run_test(ctx, appname, test, desired_status=0, dirs=['src'], name='', header=False):
     713def run_test(ctx, appname, test, desired_status=0, dirs=['src'], name='', header=False, quiet=False):
    714714    """Run an individual test.
    715715
     
    721721    ctx.autowaf_tests[appname]['total'] += 1
    722722
     723    out = (None,None)
    723724    if type(test) == list:
    724725        name       = test[0]
    725726        returncode = test[1]
     727    elif callable(test):
     728        returncode = test()
    726729    else:
    727730        s = test
    728731        if type(test) == type([]):
    729732            s = ' '.join(i)
    730         if header:
     733        if header and not quiet:
    731734            Logs.pprint('Green', '\n** Test %s' % s)
    732735        cmd = test
     
    736739            name = test
    737740
    738         if Options.options.verbose_tests:
    739             proc = subprocess.Popen(cmd, shell=True)
    740         else:
    741             proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    742 
     741        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    743742        out = proc.communicate()
    744743        returncode = proc.returncode
    745744
    746     if returncode == desired_status:
    747         Logs.pprint('GREEN', '** Pass %s' % name)
    748         return True
     745    success = desired_status is None or returncode == desired_status
     746    if success:
     747        if not quiet:
     748            Logs.pprint('GREEN', '** Pass %s' % name)
    749749    else:
    750750        Logs.pprint('RED', '** FAIL %s' % name)
    751         if type(test) != list:
    752             Logs.pprint('NORMAL', out[1])
    753751        ctx.autowaf_tests_failed += 1
    754752        ctx.autowaf_tests[appname]['failed'] += 1
    755         return False
     753        if type(test) != list and not callable(test):
     754            Logs.pprint('RED', test)
     755
     756    if Options.options.verbose_tests and type(test) != list and not callable(test):
     757        sys.stdout.write(out[0])
     758        sys.stderr.write(out[1])
     759
     760    return (success, out)
    756761
    757762def tests_name(ctx, appname, name='*'):
     
    765770    ctx.autowaf_local_tests_total  = 0
    766771    Logs.pprint('GREEN', '\n** Begin %s tests' % tests_name(ctx, appname, name))
     772    class Handle:
     773        def __enter__(self):
     774            pass
     775        def __exit__(self, type, value, traceback):
     776            end_tests(ctx, appname, name)
     777    return Handle()
    767778
    768779def end_tests(ctx, appname, name='*'):
Note: See TracChangeset for help on using the changeset viewer.