changeset 25525:48a9bd2d0a20

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.
author John W. Eaton <jwe@octave.org>
date Fri, 29 Jun 2018 16:31:40 -0400
parents 366d4b8f6668
children d7aafcb1dc1a
files scripts/testfun/test.m
diffstat 1 files changed, 19 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- 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)