Mercurial > octave
changeset 28040:a077eadd1325
test.m: Fix onCleanup error when testing rand.cc (bug #57456).
* test.m: Add code to clear any %!share variables created during tests.
Call __clearfcn directly, rather than setting it up to execute at the
end of the test() function with an onCleanup block.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 03 Feb 2020 13:46:20 -0800 |
parents | cc0b31003932 |
children | 5e44268dca6f |
files | scripts/testfun/test.m |
diffstat | 1 files changed, 11 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/testfun/test.m Sun Feb 02 14:49:04 2020 +0100 +++ b/scripts/testfun/test.m Mon Feb 03 13:46:20 2020 -0800 @@ -125,7 +125,7 @@ ## @end deftypefn ## Programming Note: All variables for test() must use the internal prefix "__". -## Shared variables are eval'ed into the current workspace and therefore might +## %!share variables are eval'ed into the current workspace and therefore might ## collide with the names used in the test.m function itself. function [__n, __nmax, __nxfail, __nbug, __nskip, __nrtskip, __nregression] = test (__name, __flag = "normal", __fid = []) @@ -747,9 +747,6 @@ end_unwind_protect endfor - ## Clear any functions created during test run. - __clear_functions = onCleanup (@() eval (__clearfcn, "")); - ## Verify test file did not leak file descriptors. if (! isempty (setdiff (fopen ("all"), __fid_list_orig))) warning ("test: file %s leaked file descriptors\n", __file); @@ -769,6 +766,16 @@ __file, sprintf (" %s", __leaked_vars{:})); endif + ## Clear any shared variables + ## This is necessary in case any onCleanup actions need to be triggered. + __shared_vars = strtrim (ostrsplit (__shared, ",")); + if (! isempty (__shared_vars)) + clear (__shared_vars{:}); + endif + + ## Clear any functions created during test run. + eval (__clearfcn, ""); + if (nargout == 0) if (__tests || __xfail || __xbug || __xskip || __xrtskip) if (__xfail || __xbug)