changeset 11024:fa56fd98c0c5

Remove requirement for PCRE in Octave. (Bug #31025)
author Rik <octave@nomad.inbox5.com>
date Sun, 26 Sep 2010 12:55:38 -0700
parents cb62c7401ea2
children df2152514429
files scripts/ChangeLog scripts/testfun/runtests.m test/ChangeLog test/fntests.m
diffstat 4 files changed, 35 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog
+++ b/scripts/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-26  Rik <octave@nomad.inbox5.com>
+
+	* testfun/runtests.m (has_tests): Recode to remove requirement for PCRE.
+	Bug #31025.
+
 2010-09-25  Ben Abbott <bpabbott@mac.com>
 
 	* plot/__print_parse_opts__.m: Recongize gs devices {eps/pdf/ps}write.
--- a/scripts/testfun/runtests.m
+++ b/scripts/testfun/runtests.m
@@ -17,7 +17,8 @@
 ## <http://www.gnu.org/licenses/>.
 
 ## -*- texinfo -*-
-## @deftypefn {Function File} {} rundtests (@var{directory})
+## @deftypefn {Function File} {} runtests (@var{directory})
+## Execute built-in tests for all function files in the specified directory.
 ## @end deftypefn
 
 ## Author: jwe
@@ -69,23 +70,19 @@
     endif
   endfor
   if (! isempty (no_tests))
-    printf ("\nThe following files in have no tests:\n\n", directory);
+    printf ("\nThe following files in %s have no tests:\n\n", directory);
     printf ("%s", list_in_columns (no_tests));
   endif
 endfunction
 
 function retval = has_tests (f)
-  retval = false;
   fid = fopen (f);
   if (fid >= 0)
-    while (! feof (fid))
-      ln = fgetl (fid);
-      if (! isempty (regexp (ln, "%!(assert|error|test)", "lineanchors")))
-        retval = true;
-        break;
-      endif
-    endwhile
+    str = fread (fid, "*char")';
     fclose (fid);
+    ## Avoid PCRE 'lineanchors' by searching for newline followed by PTN.
+    ## Equivalent to regexp ('^PTN','lineanchors')
+    retval = ! isempty (regexp (str, '[\r\n]\s*%!(test|assert|error|warning)', "once"));
   else
     error ("runtests: fopen failed: %s", f);
   endif
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-26  Rik <octave@nomad.inbox5.com>
+
+	* fntests.m (has_tests, has_functions): Recode to remove requirement 
+	for PCRE.
+
 2010-09-24  Rik <octave@nomad.inbox5.com>
 
 	* fntests.m: Rephrase output for clarity.
--- a/test/fntests.m
+++ b/test/fntests.m
@@ -68,34 +68,34 @@
   puts ("\n");
 endfunction
 
-function y = hasfunctions (f)
+function retval = has_functions (f)
   n = length (f);
   if (n > 3 && strcmp (f((end-2):end), ".cc"))
     fid = fopen (f);
-    if (fid < 0)
-      error ("fopen failed: %s", f);
-    else
+    if (fid >= 0)
       str = fread (fid, "*char")';
       fclose (fid);
-      y = ! isempty (regexp (str,'^(DEFUN|DEFUN_DLD)\b', "lineanchors"));
+      retval = ! isempty (regexp (str,'[\r\n](DEFUN|DEFUN_DLD)\b', "once"));
+    else
+      error ("fopen failed: %s", f);
     endif
   elseif (n > 2 && strcmp (f((end-1):end), ".m"))
-    y = true;
+    retval = true;
   else
-    y = false;
+    retval = false;
   endif
 endfunction
 
-## FIXME -- should we only try match the keyword at the start of a line?
-function y = hastests (f)
+function retval = has_tests (f)
   fid = fopen (f);
-  if (fid < 0)
-    error ("fopen failed: %s", f);
-  else
+  if (fid >= 0)
     str = fread (fid, "*char")';
     fclose (fid);
-    y = ! isempty (regexp (str, "^[ \t]*%!(test|assert|error|warning)",
-                           "lineanchors"));
+    ## Avoid PCRE 'lineanchors' by searching for newline followed by PTN.
+    ## Equivalent to regexp ('^PTN','lineanchors')
+    retval = ! isempty (regexp (str, '[\r\n]\s*%!(test|assert|error|warning)', "once"));
+  else
+    error ("fopen failed: %s", f);
   endif
 endfunction
 
@@ -110,7 +110,7 @@
 	&& strcmp (nm((end-1):end), ".m"))
       p = n = xf = sk = 0;
       ffnm = fullfile (d, nm);
-      if (hastests (ffnm))
+      if (has_tests (ffnm))
 	print_test_file_name (nm);
 	[p, n, xf, sk] = test (nm(1:(end-2)), "quiet", fid);
 	print_pass_fail (n, p);
@@ -155,7 +155,7 @@
         (length (nm) > 3 && strcmp (nm((end-2):end), ".cc")))
       p = n = xf = 0;
       ## Only run if it contains %!test, %!assert %!error or %!warning
-      if (hastests (f))
+      if (has_tests (f))
 	tmp = strrep (f, [topsrcdir, "/"], "");
 	tmp = strrep (tmp, [topbuilddir, "/"], "../");
 	print_test_file_name (tmp);
@@ -166,7 +166,7 @@
 	dxf += xf;
 	dsk += sk;
 	files_with_tests(end+1) = f;
-      elseif (hasfunctions (f))
+      elseif (has_functions (f))
 	## To reduce the list length, only mark .cc files that contain
 	## DEFUN definitions.
 	files_with_no_tests(end+1) = f;
@@ -196,7 +196,7 @@
 function n = num_elts_matching_pattern (lst, pat)
   n = 0;
   for i = 1:length (lst)
-    if (! isempty (regexp (lst{i}, pat)))
+    if (! isempty (regexp (lst{i}, pat, "once")))
       n++;
     endif
   endfor