jeudi 29 janvier 2015

tcltest unit tests: how to check if constraint is active to enable code reuse

We are using tcltest to do our unit testing but we are finding it difficult to reuse code within our test suite.


We have a test that is executed multiple times for different system configurations. I created a proc which contains this test and reuse it everywhere instead of duplicating the test's code many times throughout the suite.


For example:



proc test_config { config_name} {
test $test_name {} -constraints $config_name -body {
<test body>
} -returnCodes ok
}


The problem is that I sometimes want to only test certain configurations. I pass the configuration name as a parameter to the proc as shown above, but the -constraints {} part of the test does not look up the $config_name parameter as expected. The test is always skipped unless I hard code the configuration name, but using a proc is not possible and I would need to duplicate the code everywhere just to hardcode the constraint.


Is there a way to look if the constraint is enabled in the tcltest configuration?


Something like this:



proc test_config { config_name} {
testConstraint X [expr { ::tcltest::isConstraintActive $config_name } ]
test $test_name {} -constraints X -body {
<test body>
} -returnCodes ok
}


So, is there a function in tcltest doing something like ::tcltest::isConstraintActive $config_name?


Aucun commentaire:

Enregistrer un commentaire