X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=unit_test%2Funit_init.m;fp=unit_test%2Funit_init.m;h=b692a80b8827096576728ee3de0be5773ab7c9a3;hp=0000000000000000000000000000000000000000;hb=ef3085ef3c40eab925219bad1c6dbb2c6e106727;hpb=33e4dd7a64f35fb22774d59af11f5670ab566fbc diff --git a/unit_test/unit_init.m b/unit_test/unit_init.m new file mode 100644 index 0000000..b692a80 --- /dev/null +++ b/unit_test/unit_init.m @@ -0,0 +1,41 @@ +function unit_init(verbosity, global_vars) + ## Initialize the global structure unittest_results, which is needed + ## in all functions of the *unittest module. Debugging information + ## is printed if verbosity==1. global_vars is a cell array of the + ## names of the global variables used in the tests. + ## + ## e.g. unit_init(1, {"g", "a", "x"}) + + global unittest_results; + + unittest_results.verbose = 0; + unittest_results.eval_globals = {}; + if (nargin > 0) + if (!isscalar(verbosity) || verbosity < 0 || verbosity > 1) + warning("unit_init: verbose must be 0 or 1"); + else + unittest_results.verbose = verbosity; + endif + + if (nargin == 2 && iscell(global_vars)) + for i = 1:length(global_vars) + unittest_results.eval_globals{i} = strcat("global ", global_vars{i}, ";"); + endfor + else + error("global_vars must be a cell array"); + endif + + if (nargin > 2) + usage("expecting 2 arguments only"); + end + endif + + unittest_results.total = 0; # number of testcases attempted + unittest_results.pass = 0; # number of expected passed + unittest_results.fail = 0; # number of unexpected failures + unittest_results.upass = 0; # number of unexpected passes + unittest_results.xfail = 0; # number of expected failures + unittest_results.unresolved = 0; # number of unresolved testcases + + default_eval_print_flag = 0; +endfunction