wscript 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # Federico Pellegrin, 2017 (fedepell)
  4. #
  5. # Simple script to demonstrate integration of Java Unit testing inside
  6. # standard waf_unit_test using either TestNG or JUnit
  7. #
  8. def test_results(bld):
  9. """
  10. Custom post- function that prints out test results.
  11. """
  12. lst = getattr(bld, 'utest_results', [])
  13. if not lst:
  14. return
  15. for (f, code, out, err) in lst:
  16. print(out.decode('utf-8'))
  17. print(err.decode('utf-8'))
  18. def options(opt):
  19. opt.load('java waf_unit_test javatest')
  20. def configure(conf):
  21. conf.load('java javatest')
  22. def build(bld):
  23. bld(features = 'javac',
  24. name = 'mainprog',
  25. srcdir = 'src/', # folder containing the sources to compile
  26. outdir = 'src', # folder where to output the classes (in the build directory)
  27. sourcepath = ['src'],
  28. basedir = 'src', # folder containing the classes and other files to package (must match outdir)
  29. )
  30. bld(features = 'javac javatest',
  31. srcdir = 'test/', # folder containing the sources to compile
  32. outdir = 'test', # folder where to output the classes (in the build directory)
  33. sourcepath = ['test'],
  34. classpath = [ 'src' ],
  35. basedir = 'test', # folder containing the classes and other files to package (must match outdir)
  36. use = ['JAVATEST', 'mainprog'],
  37. ut_str = 'java -cp ${CLASSPATH} ${JTRUNNER} ${SRC}',
  38. jtest_source = bld.path.ant_glob('test/*.xml'),
  39. # For JUnit do first JUnit configuration and no need to use jtest_source:
  40. # ut_str = 'java -cp ${CLASSPATH} ${JTRUNNER} [TestClass]',
  41. )
  42. bld.add_post_fun(test_results)