# HG changeset patch # User Mike Miller # Date 1379763229 14400 # Node ID 2c2a6801cb575009c3dc891a9a00cacf7fd9effb # Parent b76b14e386b3f4e76200c54184ae192cfe4f8383 rundemos.m, runtests.m: Operate on .cc files (bug #40052) * rundemos.m, runtests.m: Copy logic from a previous version of fntests to operate on C++ source files for development use. Update docstrings. diff -r b76b14e386b3 -r 2c2a6801cb57 scripts/testfun/rundemos.m --- a/scripts/testfun/rundemos.m Fri Sep 20 18:43:43 2013 -0400 +++ b/scripts/testfun/rundemos.m Sat Sep 21 07:33:49 2013 -0400 @@ -20,6 +20,9 @@ ## @deftypefn {Function File} {} rundemos () ## @deftypefnx {Function File} {} rundemos (@var{directory}) ## Execute built-in demos for all function files in the specified directory. +## Also executes demos in any C++ source files found in the directory, for +## use with dynamically linked functions. +## ## If no directory is specified, operate on all directories in Octave's ## search path for functions. ## @seealso{runtests, path} @@ -62,7 +65,8 @@ flist = readdir (directory); for i = 1:numel (flist) f = flist{i}; - if (length (f) > 2 && strcmp (f((end-1):end), ".m")) + if ((length (f) > 2 && strcmpi (f((end-1):end), ".m")) || + (length (f) > 3 && strcmpi (f((end-2):end), ".cc"))) f = fullfile (directory, f); if (has_demos (f)) try diff -r b76b14e386b3 -r 2c2a6801cb57 scripts/testfun/runtests.m --- a/scripts/testfun/runtests.m Fri Sep 20 18:43:43 2013 -0400 +++ b/scripts/testfun/runtests.m Sat Sep 21 07:33:49 2013 -0400 @@ -20,6 +20,8 @@ ## @deftypefn {Function File} {} runtests () ## @deftypefnx {Function File} {} runtests (@var{directory}) ## Execute built-in tests for all function files in the specified directory. +## Also executes tests in any C++ source files found in the directory, for +## use with dynamically linked functions. ## ## If no directory is specified, operate on all directories in Octave's ## search path for functions. @@ -66,14 +68,15 @@ fflush (stdout); for i = 1:numel (flist) f = flist{i}; - if (length (f) > 2 && strcmpi (f((end-1):end), ".m")) + 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, sk] = test (ff, "quiet"); print_pass_fail (n, p); fflush (stdout); - else + elseif (has_functions (ff)) no_tests{end+1} = f; endif endif @@ -84,6 +87,25 @@ 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) + str = fread (fid, "*char")'; + fclose (fid); + retval = ! isempty (regexp (str,'^(DEFUN|DEFUN_DLD)\>', + 'lineanchors', 'once')); + else + error ("fopen failed: %s", f); + endif + 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)