Mercurial > hg > octave-lyh
changeset 17464:2c2a6801cb57
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.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Sat, 21 Sep 2013 07:33:49 -0400 |
parents | b76b14e386b3 |
children | a4f86f459744 |
files | scripts/testfun/rundemos.m scripts/testfun/runtests.m |
diffstat | 2 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/testfun/rundemos.m +++ b/scripts/testfun/rundemos.m @@ -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
--- a/scripts/testfun/runtests.m +++ b/scripts/testfun/runtests.m @@ -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)