Mercurial > hg > octave-lyh
changeset 17156:fa14aa77b514
Allow relative directory name for rundemos/runtests.
* scripts/testfun/rundemos.m: Use canonicalize_file_name if directory
is relative. Use readdir() rather than dir() for performance.
*scripts/testfun/runtests.m: Use canonicalize_file_name if directory
is relative. Use readdir() rather than dir() for performance. Add
%!error blocks.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 02 Aug 2013 09:01:55 -0700 |
parents | 35a1bd41aa02 |
children | 73a3c1580974 |
files | scripts/testfun/rundemos.m scripts/testfun/runtests.m |
diffstat | 2 files changed, 22 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/testfun/rundemos.m +++ b/scripts/testfun/rundemos.m @@ -34,8 +34,12 @@ elseif (nargin == 1) if (is_absolute_filename (directory)) dirs = {directory}; + elseif (is_rooted_relative_filename (directory)) + dirs = {canonicalize_file_name(directory)}; else - directory = regexprep (directory, ['\',filesep(),'$'], ""); + if (directory(end) == filesep ()) + directory = directory(1:end-1); + endif fullname = find_dir_in_path (directory); if (! isempty (fullname)) dirs = {fullname}; @@ -55,8 +59,7 @@ endfunction function run_all_demos (directory) - dirinfo = dir (directory); - flist = {dirinfo.name}; + flist = readdir (directory); for i = 1:numel (flist) f = flist{i}; if (length (f) > 2 && strcmp (f((end-1):end), ".m"))
--- a/scripts/testfun/runtests.m +++ b/scripts/testfun/runtests.m @@ -20,6 +20,7 @@ ## @deftypefn {Function File} {} runtests () ## @deftypefnx {Function File} {} runtests (@var{directory}) ## Execute built-in tests for all function files in the specified directory. +## ## If no directory is specified, operate on all directories in Octave's ## search path for functions. ## @seealso{rundemos, path} @@ -34,8 +35,12 @@ elseif (nargin == 1) if (is_absolute_filename (directory)) dirs = {directory}; + elseif (is_rooted_relative_filename (directory)) + dirs = {canonicalize_file_name(directory)}; else - directory = regexprep (directory, ['\',filesep(),'$'], ""); + if (directory(end) == filesep ()) + directory = directory(1:end-1); + endif fullname = find_dir_in_path (directory); if (! isempty (fullname)) dirs = {fullname}; @@ -55,14 +60,13 @@ endfunction function run_all_tests (directory) - dirinfo = dir (directory); - flist = {dirinfo.name}; + flist = readdir (directory); no_tests = {}; printf ("Processing files in %s:\n\n", directory); fflush (stdout); 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")) ff = fullfile (directory, f); if (has_tests (ff)) print_test_file_name (f); @@ -83,9 +87,10 @@ function retval = has_tests (f) fid = fopen (f); if (fid >= 0) - str = fread (fid, "*char")'; + str = fread (fid, "*char").'; fclose (fid); - retval = ! isempty (regexp (str, '^%!(test|assert|error|warning)', "lineanchors")); + retval = ! isempty (regexp (str, '^%!(?:test|assert|error|warning)', + "lineanchors", "once")); else error ("runtests: fopen failed: %s", f); endif @@ -106,3 +111,8 @@ filler = repmat (".", 1, 55-length (nm)); printf (" %s %s", nm, filler); endfunction + + +%!error runtests ("foo", 1) +%!error <DIRECTORY argument> runtests ("#_TOTALLY_/_INVALID_/_PATHNAME_#") +