Mercurial > octave
changeset 28064:fbed279b7074
pkg: add "test" command to test all functions in a package (bug #41215)
* pkg.m: Add "test" command to test all functions in a package.
Thanks to Oliver Heimlich and Philip Nienhuis for their original revisions
of this patch.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Sun, 16 Feb 2020 11:31:48 -0800 |
parents | 60e4a9909fac |
children | 7a22be5833c7 |
files | scripts/pkg/pkg.m |
diffstat | 1 files changed, 36 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/pkg/pkg.m Fri Feb 14 18:26:59 2020 +0100 +++ b/scripts/pkg/pkg.m Sun Feb 16 11:31:48 2020 -0800 @@ -315,6 +315,14 @@ ## Rebuild the package database from the installed directories. This can ## be used in cases where the package database has been corrupted. ## +## @item test +## Perform the built-in self tests contained in all functions provided by +## the named packages. For example, +## +## @example +## pkg test image +## @end example +## ## @end table ## @seealso{ver, news} ## @end deftypefn @@ -346,7 +354,7 @@ # valid actions in alphabetical order available_actions = {"build", "describe", "global_list", "install", ... "list", "load", "local_list", "prefix", "rebuild", ... - "uninstall", "unload", "update"}; + "test", "uninstall", "unload", "update"}; ## Parse input arguments if (isempty (varargin) || ! iscellstr (varargin)) @@ -665,6 +673,33 @@ endif endfor + case "test" + if (isempty (files)) + error ("pkg: test action requires at least one package name"); + endif + ## Make sure the requested packages are loaded + orig_path = path (); + load_packages (files, deps, local_list, global_list); + ## Test packages one by one + installed_pkgs_lst = installed_packages (local_list, global_list, files); + unwind_protect + for i = 1:numel (installed_pkgs_lst) + printf ("Testing functions in package '%s':\n", files{i}); + installed_pkgs_dirs = {installed_pkgs_lst{i}.dir, ... + installed_pkgs_lst{i}.archprefix}; + ## For local installs installed_pkgs_dirs contains the same subdirs + installed_pkgs_dirs = unique (installed_pkgs_dirs); + if (! isempty (installed_pkgs_dirs)) + ## FIXME invoke another test routine once that is available. + ## Until then __run_test_suite__.m will do the job fine enough + __run_test_suite__ ({installed_pkgs_dirs{:}}, {}); + endif + endfor + unwind_protect_cleanup + ## Restore load path back to its original value before loading packages + path (orig_path); + end_unwind_protect + otherwise error ("pkg: invalid action. See 'help pkg' for available actions"); endswitch