# HG changeset patch # User John W. Eaton # Date 1530304300 14400 # Node ID 48a9bd2d0a20f285a6054dfa10b7c63171aeb9bb # Parent 366d4b8f6668a2a58bd3197fb12e73e29ee4c07f also check for tests that leak global variables (bug #54180) * test.m: Also check for new global variables after running tests. Use "who" instead of "whos" when checking for variables in the base workspace. diff -r 366d4b8f6668 -r 48a9bd2d0a20 scripts/testfun/test.m --- a/scripts/testfun/test.m Fri Jun 29 22:23:49 2018 +0200 +++ b/scripts/testfun/test.m Fri Jun 29 16:31:40 2018 -0400 @@ -294,10 +294,13 @@ endif ## Track file descriptor leaks - __fid_list_orig = fopen ("all"); + __fid_list_orig = fopen ("all"); ## Track variable leaks - __variables_orig = evalin ("base", "whos"); + __base_variables_orig = evalin ("base", "who"); + + ## Track variable leaks + __global_variables_orig = who ("global"); ## Assume all tests will pass. __all_success = true; @@ -735,20 +738,26 @@ end_unwind_protect endfor - ## Clear any functions created during test run + ## Clear any functions created during test run. eval (__clearfcn, ""); - ## Verify test file did not leak file descriptors + ## 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); endif - ## Verify test file did not leak variables in to base workspace - __variables_post = evalin ("base", "whos"); - if (! size_equal (__variables_post, __variables_orig)) - __leaked_var = setdiff ({__variables_post.name}, {__variables_orig.name}); - warning ("test: file %s leaked variables:%s\n", - __file, sprintf (" %s", __leaked_var{:})); + ## Verify test file did not leak variables in to base workspace. + __leaked_vars = setdiff (evalin ("base", "who"), __base_variables_orig); + if (! isempty (__leaked_vars)) + warning ("test: file %s leaked variables to base workspace:%s\n", + __file, sprintf (" %s", __leaked_vars{:})); + endif + + ## Verify test file did not leak global variables. + __leaked_vars = setdiff (who ("global"), __global_variables_orig); + if (! isempty (__leaked_vars)) + warning ("test: file %s leaked global variables:%s\n", + __file, sprintf (" %s", __leaked_vars{:})); endif if (nargout == 0)