wscript (1599B)
1 #! /usr/bin/env python 2 # encoding: utf-8 3 # Thomas Nagy, 2016 (ita) 4 5 top = '.' 6 out = 'build' 7 8 import functools 9 from waflib import Utils, Logs 10 11 def configure(conf): 12 pass 13 14 def fun1(): 15 return 0 16 17 def fun2(arg1, arg2): 18 return 1 19 20 def fun(arg1, arg2, task, one=1, two=2): 21 print(arg1, arg2, task, one, two) 22 23 par1 = functools.partial(fun, 'arg1') 24 par2 = functools.partial(par1, 'arg2', one=11, two=22) 25 26 def fun3(): 27 return 32 28 par3 = functools.partial(par1, 'arg2', one=11, two=22) 29 30 def build(bld): 31 32 bld.failure = 0 33 def disp(color, result): 34 Logs.pprint(color, result) 35 if color == 'RED': 36 bld.failure=1 37 def stop_status(bld): 38 if bld.failure: 39 bld.fatal('One or several test failed, check the outputs above') 40 bld.add_post_fun(stop_status) 41 42 def simple_hash(fun): 43 status = '' 44 try: 45 Utils.h_cmd(fun) 46 except Exception as e: 47 status = str(e) 48 return status 49 50 def hash_test(name, fun): 51 ret = simple_hash(fun) 52 if not ret: 53 color = "GREEN" 54 else: 55 color = "RED" 56 ret = ret or 'ok' 57 disp(color, '%s\t\t%s' % (name, ret)) 58 59 hash_test('simple function 1', fun1) 60 hash_test('simple function 2', fun1) 61 hash_test('simple partial', par1) 62 hash_test('nested partial', par2) 63 64 def hash_twice(name, fun): 65 try: 66 ret1 = Utils.h_cmd(fun) 67 ret2 = Utils.h_cmd(fun) 68 except Exception as e: 69 msg = str(e) 70 color = 'RED' 71 else: 72 if ret1 == ret2: 73 msg = 'ok %r' % ret1 74 color = 'GREEN' 75 else: 76 msg = '%r != %r' % (ret1, ret2) 77 color = 'RED' 78 disp(color, '%s\t\t%s' % (name, msg)) 79 80 hash_twice('consistent on fun3', fun3) 81 hash_twice('consistent on par3', par3) 82