changeset 27119:8a04f5454350

Deprecate 'runtests' function (bug #56325). * NEWS: Announce deprecation, and replacement function 'oruntests'. * scripts/testfun/oruntests.m: Renamed from runtests.m. * scripts/testfun/module.mk: Add oruntests.m to build system. * scripts/deprecated/runtests.m: New function configured to emit a deprecation warning and then call oruntests. * scripts/deprecated/module.mk: Add runtests.m to build system. * rundemos.m: Change seealso link to oruntests. * testfun.txi: Document 'oruntests' function in manual. * output_max_field_width.m: Change deprecation warning to end with newline so that backtrace is suppressed.
author Rik <rik@octave.org>
date Sat, 25 May 2019 18:36:59 -0700
parents ecd36fa98a31
children 014e137947d7
files NEWS doc/interpreter/testfun.txi scripts/deprecated/module.mk scripts/deprecated/output_max_field_width.m scripts/deprecated/runtests.m scripts/testfun/module.mk scripts/testfun/oruntests.m scripts/testfun/rundemos.m scripts/testfun/runtests.m
diffstat 9 files changed, 233 insertions(+), 183 deletions(-) [+]
line wrap: on
line diff
--- a/NEWS	Sat May 25 18:05:12 2019 -0700
+++ b/NEWS	Sat May 25 18:36:59 2019 -0700
@@ -65,7 +65,7 @@
 
   Function               | Replacement
   -----------------------|------------------
-                         |
+  `runtests`             | `oruntests`
 
 - Properties
 
--- a/doc/interpreter/testfun.txi	Sat May 25 18:05:12 2019 -0700
+++ b/doc/interpreter/testfun.txi	Sat May 25 18:36:59 2019 -0700
@@ -470,8 +470,8 @@
 
 @DOCSTRING(example)
 
+@DOCSTRING(oruntests)
+
 @DOCSTRING(rundemos)
 
-@DOCSTRING(runtests)
-
 @DOCSTRING(speed)
--- a/scripts/deprecated/module.mk	Sat May 25 18:05:12 2019 -0700
+++ b/scripts/deprecated/module.mk	Sat May 25 18:36:59 2019 -0700
@@ -1,7 +1,8 @@
 FCN_FILE_DIRS += scripts/deprecated
 
 %canon_reldir%_FCN_FILES = \
-  %reldir%/output_max_field_width.m
+  %reldir%/output_max_field_width.m \
+  %reldir%/runtests.m
 
 %canon_reldir%dir = $(fcnfiledir)/deprecated
 
--- a/scripts/deprecated/output_max_field_width.m	Sat May 25 18:05:12 2019 -0700
+++ b/scripts/deprecated/output_max_field_width.m	Sat May 25 18:36:59 2019 -0700
@@ -41,7 +41,7 @@
   if (! warned)
     warned = true;
     warning ("Octave:deprecated-function",
-             "output_max_field_width is obsolete and will be removed from a future version of Octave, please use output_precision instead");
+             "output_max_field_width is obsolete and will be removed from a future version of Octave, please use output_precision instead\n");
   endif
 
   retval = 20;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/deprecated/runtests.m	Sat May 25 18:36:59 2019 -0700
@@ -0,0 +1,49 @@
+## Copyright (C) 2010-2019 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn  {} {} runtests ()
+## @deftypefnx {} {} runtests (@var{directory})
+##
+##
+## @code{runtests} is deprecated and will be removed in Octave version 8.
+## Use @code{oruntests} instead.
+##
+## Execute built-in tests for all m-files in the specified @var{directory}.
+##
+## Test blocks in any C++ source files (@file{*.cc}) will also be executed
+## for use with dynamically linked oct-file functions.
+##
+## If no directory is specified, operate on all directories in Octave's search
+## path for functions.
+## @seealso{oruntests, rundemos, test, path}
+## @end deftypefn
+
+## FIXME: DEPRECATED: Remove in version 8.
+
+function runtests (varargin)
+
+  persistent warned = false;
+  if (! warned)
+    warned = true;
+    warning ("Octave:deprecated-function",
+             "runtests is obsolete and will be removed from a future version of Octave, please use oruntests instead\n");
+  endif
+
+  oruntests (varargin{:}); 
+endfunction
--- a/scripts/testfun/module.mk	Sat May 25 18:05:12 2019 -0700
+++ b/scripts/testfun/module.mk	Sat May 25 18:36:59 2019 -0700
@@ -16,7 +16,7 @@
   %reldir%/example.m \
   %reldir%/fail.m \
   %reldir%/rundemos.m \
-  %reldir%/runtests.m \
+  %reldir%/oruntests.m \
   %reldir%/speed.m \
   %reldir%/test.m
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/testfun/oruntests.m	Sat May 25 18:36:59 2019 -0700
@@ -0,0 +1,176 @@
+## Copyright (C) 2010-2019 John W. Eaton
+##
+## This file is part of Octave.
+##
+## Octave is free software: you can redistribute it and/or modify it
+## under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## Octave is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Octave; see the file COPYING.  If not, see
+## <https://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn  {} {} oruntests ()
+## @deftypefnx {} {} oruntests (@var{directory})
+## Execute built-in tests for all m-files in the specified @var{directory}.
+##
+## Test blocks in any C++ source files (@file{*.cc}) will also be executed
+## for use with dynamically linked oct-file functions.
+##
+## If no directory is specified, operate on all directories in Octave's search
+## path for functions.
+## @seealso{rundemos, test, path}
+## @end deftypefn
+
+## Author: jwe
+
+function oruntests (directory)
+
+  if (nargin == 0)
+    dirs = ostrsplit (path (), pathsep ());
+    do_class_dirs = true;
+  elseif (nargin == 1)
+    dirs = {canonicalize_file_name(directory)};
+    if (isempty (dirs{1}) || ! isfolder (dirs{1}))
+      ## Search for directory name in path
+      if (directory(end) == '/' || directory(end) == '\')
+        directory(end) = [];
+      endif
+      fullname = dir_in_loadpath (directory);
+      if (isempty (fullname))
+        error ("oruntests: DIRECTORY argument must be a valid pathname");
+      endif
+      dirs = {fullname};
+    endif
+    do_class_dirs = false;
+  else
+    print_usage ();
+  endif
+
+  for i = 1:numel (dirs)
+    d = dirs{i};
+    run_all_tests (d, do_class_dirs);
+  endfor
+
+endfunction
+
+function run_all_tests (directory, do_class_dirs)
+
+  flist = readdir (directory);
+  dirs = {};
+  no_tests = {};
+  printf ("Processing files in %s:\n\n", directory);
+  fflush (stdout);
+  for i = 1:numel (flist)
+    f = flist{i};
+    if ((length (f) > 2 && strcmpi (f((end-1):end), ".m"))
+        || (length (f) > 3 && strcmpi (f((end-2):end), ".cc")))
+      ff = fullfile (directory, f);
+      if (has_tests (ff))
+        print_test_file_name (f);
+        [p, n, xf, xb, sk, rtsk, rgrs] = test (ff, "quiet");
+        print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs);
+        fflush (stdout);
+      elseif (has_functions (ff))
+        no_tests(end+1) = f;
+      endif
+    elseif (f(1) == "@")
+      f = fullfile (directory, f);
+      if (isfolder (f))
+        dirs(end+1) = f;
+      endif
+    endif
+  endfor
+  if (! isempty (no_tests))
+    printf ("\nThe following files in %s have no tests:\n\n", directory);
+    printf ("%s", list_in_columns (no_tests));
+  endif
+
+  ## Recurse into class directories since they are implied in the path
+  if (do_class_dirs)
+    for i = 1:numel (dirs)
+      d = dirs{i};
+      run_all_tests (d, false);
+    endfor
+  endif
+
+endfunction
+
+function retval = has_functions (f)
+
+  n = length (f);
+  if (n > 3 && strcmpi (f((end-2):end), ".cc"))
+    fid = fopen (f);
+    if (fid < 0)
+      error ("oruntests: fopen failed: %s", f);
+    endif
+    str = fread (fid, "*char")';
+    fclose (fid);
+    retval = ! isempty (regexp (str,'^(?:DEFUN|DEFUN_DLD|DEFUNX)\>',
+                                    'lineanchors', 'once'));
+  elseif (n > 2 && strcmpi (f((end-1):end), ".m"))
+    retval = true;
+  else
+    retval = false;
+  endif
+
+endfunction
+
+function retval = has_tests (f)
+
+  fid = fopen (f);
+  if (fid < 0)
+    error ("oruntests: fopen failed: %s", f);
+  endif
+
+  str = fread (fid, "*char").';
+  fclose (fid);
+  retval = ! isempty (regexp (str,
+                              '^%!(assert|error|fail|test|xtest|warning)',
+                              'lineanchors', 'once'));
+
+endfunction
+
+function print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs)
+
+  if ((n + sk + rtsk + rgrs) > 0)
+    printf (" PASS   %4d/%-4d", p, n);
+    nfail = n - p - xf - xb - rgrs;
+    if (nfail > 0)
+      printf ("\n%71s %3d", "FAIL ", nfail);
+    endif
+    if (rgrs > 0)
+      printf ("\n%71s %3d", "REGRESSION", rgrs);
+    endif
+    if (xb > 0)
+      printf ("\n%71s %3d", "(reported bug) XFAIL", xb);
+    endif
+    if (xf > 0)
+      printf ("\n%71s %3d", "(expected failure) XFAIL", xf);
+    endif
+    if (sk > 0)
+      printf ("\n%71s %3d", "(missing feature) SKIP", sk);
+    endif
+    if (rtsk > 0)
+      printf ("\n%71s %3d", "(run-time condition) SKIP", rtsk);
+    endif
+  endif
+  puts ("\n");
+
+endfunction
+
+function print_test_file_name (nm)
+  filler = repmat (".", 1, 60-length (nm));
+  printf ("  %s %s", nm, filler);
+endfunction
+
+
+%!error oruntests ("foo", 1)
+%!error <DIRECTORY argument> oruntests ("#_TOTALLY_/_INVALID_/_PATHNAME_#")
--- a/scripts/testfun/rundemos.m	Sat May 25 18:05:12 2019 -0700
+++ b/scripts/testfun/rundemos.m	Sat May 25 18:36:59 2019 -0700
@@ -26,7 +26,7 @@
 ##
 ## If no directory is specified, operate on all directories in Octave's search
 ## path for functions.
-## @seealso{demo, runtests, path}
+## @seealso{demo, oruntests, path}
 ## @end deftypefn
 
 ## Author: jwe
--- a/scripts/testfun/runtests.m	Sat May 25 18:05:12 2019 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,176 +0,0 @@
-## Copyright (C) 2010-2019 John W. Eaton
-##
-## This file is part of Octave.
-##
-## Octave is free software: you can redistribute it and/or modify it
-## under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## (at your option) any later version.
-##
-## Octave is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with Octave; see the file COPYING.  If not, see
-## <https://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn  {} {} runtests ()
-## @deftypefnx {} {} runtests (@var{directory})
-## Execute built-in tests for all m-files in the specified @var{directory}.
-##
-## Test blocks in any C++ source files (@file{*.cc}) will also be executed
-## for use with dynamically linked oct-file functions.
-##
-## If no directory is specified, operate on all directories in Octave's search
-## path for functions.
-## @seealso{rundemos, test, path}
-## @end deftypefn
-
-## Author: jwe
-
-function runtests (directory)
-
-  if (nargin == 0)
-    dirs = ostrsplit (path (), pathsep ());
-    do_class_dirs = true;
-  elseif (nargin == 1)
-    dirs = {canonicalize_file_name(directory)};
-    if (isempty (dirs{1}) || ! isfolder (dirs{1}))
-      ## Search for directory name in path
-      if (directory(end) == '/' || directory(end) == '\')
-        directory(end) = [];
-      endif
-      fullname = dir_in_loadpath (directory);
-      if (isempty (fullname))
-        error ("runtests: DIRECTORY argument must be a valid pathname");
-      endif
-      dirs = {fullname};
-    endif
-    do_class_dirs = false;
-  else
-    print_usage ();
-  endif
-
-  for i = 1:numel (dirs)
-    d = dirs{i};
-    run_all_tests (d, do_class_dirs);
-  endfor
-
-endfunction
-
-function run_all_tests (directory, do_class_dirs)
-
-  flist = readdir (directory);
-  dirs = {};
-  no_tests = {};
-  printf ("Processing files in %s:\n\n", directory);
-  fflush (stdout);
-  for i = 1:numel (flist)
-    f = flist{i};
-    if ((length (f) > 2 && strcmpi (f((end-1):end), ".m"))
-        || (length (f) > 3 && strcmpi (f((end-2):end), ".cc")))
-      ff = fullfile (directory, f);
-      if (has_tests (ff))
-        print_test_file_name (f);
-        [p, n, xf, xb, sk, rtsk, rgrs] = test (ff, "quiet");
-        print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs);
-        fflush (stdout);
-      elseif (has_functions (ff))
-        no_tests(end+1) = f;
-      endif
-    elseif (f(1) == "@")
-      f = fullfile (directory, f);
-      if (isfolder (f))
-        dirs(end+1) = f;
-      endif
-    endif
-  endfor
-  if (! isempty (no_tests))
-    printf ("\nThe following files in %s have no tests:\n\n", directory);
-    printf ("%s", list_in_columns (no_tests));
-  endif
-
-  ## Recurse into class directories since they are implied in the path
-  if (do_class_dirs)
-    for i = 1:numel (dirs)
-      d = dirs{i};
-      run_all_tests (d, false);
-    endfor
-  endif
-
-endfunction
-
-function retval = has_functions (f)
-
-  n = length (f);
-  if (n > 3 && strcmpi (f((end-2):end), ".cc"))
-    fid = fopen (f);
-    if (fid < 0)
-      error ("runtests: fopen failed: %s", f);
-    endif
-    str = fread (fid, "*char")';
-    fclose (fid);
-    retval = ! isempty (regexp (str,'^(?:DEFUN|DEFUN_DLD|DEFUNX)\>',
-                                    'lineanchors', 'once'));
-  elseif (n > 2 && strcmpi (f((end-1):end), ".m"))
-    retval = true;
-  else
-    retval = false;
-  endif
-
-endfunction
-
-function retval = has_tests (f)
-
-  fid = fopen (f);
-  if (fid < 0)
-    error ("runtests: fopen failed: %s", f);
-  endif
-
-  str = fread (fid, "*char").';
-  fclose (fid);
-  retval = ! isempty (regexp (str,
-                              '^%!(assert|error|fail|test|xtest|warning)',
-                              'lineanchors', 'once'));
-
-endfunction
-
-function print_pass_fail (p, n, xf, xb, sk, rtsk, rgrs)
-
-  if ((n + sk + rtsk + rgrs) > 0)
-    printf (" PASS   %4d/%-4d", p, n);
-    nfail = n - p - xf - xb - rgrs;
-    if (nfail > 0)
-      printf ("\n%71s %3d", "FAIL ", nfail);
-    endif
-    if (rgrs > 0)
-      printf ("\n%71s %3d", "REGRESSION", rgrs);
-    endif
-    if (xb > 0)
-      printf ("\n%71s %3d", "(reported bug) XFAIL", xb);
-    endif
-    if (xf > 0)
-      printf ("\n%71s %3d", "(expected failure) XFAIL", xf);
-    endif
-    if (sk > 0)
-      printf ("\n%71s %3d", "(missing feature) SKIP", sk);
-    endif
-    if (rtsk > 0)
-      printf ("\n%71s %3d", "(run-time condition) SKIP", rtsk);
-    endif
-  endif
-  puts ("\n");
-
-endfunction
-
-function print_test_file_name (nm)
-  filler = repmat (".", 1, 60-length (nm));
-  printf ("  %s %s", nm, filler);
-endfunction
-
-
-%!error runtests ("foo", 1)
-%!error <DIRECTORY argument> runtests ("#_TOTALLY_/_INVALID_/_PATHNAME_#")