Unit testing system for C/C++/D providing test execution:
The tests are declared by adding the test feature to programs:
def options(opt):
opt.load('compiler_cxx waf_unit_test')
def configure(conf):
conf.load('compiler_cxx waf_unit_test')
def build(bld):
bld(features='cxx cxxprogram test', source='main.cpp', target='app')
# or
bld.program(features='test', source='main2.cpp', target='app2')
When the build is executed, the program ‘test’ will be built and executed without arguments. The success/failure is detected by looking at the return code. The status and the standard output/error are stored on the build context.
The results can be displayed by registering a callback function. Here is how to call the predefined callback:
def build(bld):
bld(features='cxx cxxprogram test', source='main.c', target='app')
from waflib.Tools import waf_unit_test
bld.add_post_fun(waf_unit_test.summary)
By passing –dump-test-scripts the build outputs corresponding python files (with extension _run.py) that are useful for debugging purposes.
Task generator method
feature: | test |
---|
Task generator method
Override and return tup[1] to interrupt the build immediately if a test does not run
Bases: waflib.Task.Task
Execute a unit test
Always execute the task if waf –alltests was used or no tests if waf --notests was used
In general, tests may require any library built anywhere in the project. Override this method if fewer paths are needed
Execute the test. The execution is always successful, and the results are stored on self.generator.bld.utest_results for postprocessing.
Override add_test_results to interrupt the build
Display an execution summary:
def build(bld):
bld(features='cxx cxxprogram test', source='main.c', target='app')
from waflib.Tools import waf_unit_test
bld.add_post_fun(waf_unit_test.summary)
If any of the tests fail waf will exit with that exit code. This is useful if you have an automated build system which need to report on errors from the tests. You may use it like this:
- def build(bld):
- bld(features=’cxx cxxprogram test’, source=’main.c’, target=’app’) from waflib.Tools import waf_unit_test bld.add_post_fun(waf_unit_test.set_exit_code)
Provide the --alltests, --notests and --testcmd command-line options.
Decorator that registers a task generator method that will be executed when the object attribute feature contains the corresponding key(s):
from waflib.Task import feature
@feature('myfeature')
def myfunction(self):
print('that is my feature!')
def build(bld):
bld(features='myfeature')
Parameters: | k (list of string) – feature names |
---|
Decorator that registers method as a task generator method. The function must accept a task generator as first parameter:
from waflib.TaskGen import taskgen_method
@taskgen_method
def mymethod(self):
pass
Parameters: | func (function) – task generator method to add |
---|---|
Return type: | function |
Decorator that registers a task generator method which will be executed after the functions of given name(s):
from waflib.TaskGen import feature, after
@feature('myfeature')
@after_method('fun2')
def fun1(self):
print('feature 1!')
@feature('myfeature')
def fun2(self):
print('feature 2!')
def build(bld):
bld(features='myfeature')
Parameters: | k (list of string) – method names |
---|
Features defined in this module: