# HG changeset patch # User Rik # Date 1375459315 25200 # Node ID fa14aa77b5145380671c07b4b2c049dcb67058c9 # Parent 35a1bd41aa023d0400043085511550f85165b95e 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. diff --git a/scripts/testfun/rundemos.m b/scripts/testfun/rundemos.m --- 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")) diff --git a/scripts/testfun/runtests.m b/scripts/testfun/runtests.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 runtests ("#_TOTALLY_/_INVALID_/_PATHNAME_#") +