wscript 1.6 KB

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