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)
Task generator method
feature: | test |
---|
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
Display an execution 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: register 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: register 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: