Mercurial > octave
comparison scripts/pkg/pkg.m @ 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 | 915b3630eed0 |
children | baf16e6f498b |
comparison
equal
deleted
inserted
replaced
28063:60e4a9909fac | 28064:fbed279b7074 |
---|---|
313 ## | 313 ## |
314 ## @item rebuild | 314 ## @item rebuild |
315 ## Rebuild the package database from the installed directories. This can | 315 ## Rebuild the package database from the installed directories. This can |
316 ## be used in cases where the package database has been corrupted. | 316 ## be used in cases where the package database has been corrupted. |
317 ## | 317 ## |
318 ## @item test | |
319 ## Perform the built-in self tests contained in all functions provided by | |
320 ## the named packages. For example, | |
321 ## | |
322 ## @example | |
323 ## pkg test image | |
324 ## @end example | |
325 ## | |
318 ## @end table | 326 ## @end table |
319 ## @seealso{ver, news} | 327 ## @seealso{ver, news} |
320 ## @end deftypefn | 328 ## @end deftypefn |
321 | 329 |
322 function [local_packages, global_packages] = pkg (varargin) | 330 function [local_packages, global_packages] = pkg (varargin) |
344 confirm_recursive_rmdir (false, "local"); | 352 confirm_recursive_rmdir (false, "local"); |
345 | 353 |
346 # valid actions in alphabetical order | 354 # valid actions in alphabetical order |
347 available_actions = {"build", "describe", "global_list", "install", ... | 355 available_actions = {"build", "describe", "global_list", "install", ... |
348 "list", "load", "local_list", "prefix", "rebuild", ... | 356 "list", "load", "local_list", "prefix", "rebuild", ... |
349 "uninstall", "unload", "update"}; | 357 "test", "uninstall", "unload", "update"}; |
350 | 358 |
351 ## Parse input arguments | 359 ## Parse input arguments |
352 if (isempty (varargin) || ! iscellstr (varargin)) | 360 if (isempty (varargin) || ! iscellstr (varargin)) |
353 print_usage (); | 361 print_usage (); |
354 endif | 362 endif |
663 if (compare_versions (forge_pkg_version, installed_pkg_version, ">")) | 671 if (compare_versions (forge_pkg_version, installed_pkg_version, ">")) |
664 feval (@pkg, "install", "-forge", installed_pkg_name); | 672 feval (@pkg, "install", "-forge", installed_pkg_name); |
665 endif | 673 endif |
666 endfor | 674 endfor |
667 | 675 |
676 case "test" | |
677 if (isempty (files)) | |
678 error ("pkg: test action requires at least one package name"); | |
679 endif | |
680 ## Make sure the requested packages are loaded | |
681 orig_path = path (); | |
682 load_packages (files, deps, local_list, global_list); | |
683 ## Test packages one by one | |
684 installed_pkgs_lst = installed_packages (local_list, global_list, files); | |
685 unwind_protect | |
686 for i = 1:numel (installed_pkgs_lst) | |
687 printf ("Testing functions in package '%s':\n", files{i}); | |
688 installed_pkgs_dirs = {installed_pkgs_lst{i}.dir, ... | |
689 installed_pkgs_lst{i}.archprefix}; | |
690 ## For local installs installed_pkgs_dirs contains the same subdirs | |
691 installed_pkgs_dirs = unique (installed_pkgs_dirs); | |
692 if (! isempty (installed_pkgs_dirs)) | |
693 ## FIXME invoke another test routine once that is available. | |
694 ## Until then __run_test_suite__.m will do the job fine enough | |
695 __run_test_suite__ ({installed_pkgs_dirs{:}}, {}); | |
696 endif | |
697 endfor | |
698 unwind_protect_cleanup | |
699 ## Restore load path back to its original value before loading packages | |
700 path (orig_path); | |
701 end_unwind_protect | |
702 | |
668 otherwise | 703 otherwise |
669 error ("pkg: invalid action. See 'help pkg' for available actions"); | 704 error ("pkg: invalid action. See 'help pkg' for available actions"); |
670 endswitch | 705 endswitch |
671 | 706 |
672 endfunction | 707 endfunction |