1######################################################################## 2## 3## Copyright (C) 2018-2021 The Octave Project Developers 4## 5## See the file COPYRIGHT.md in the top-level directory of this 6## distribution or <https://octave.org/copyright/>. 7## 8## This file is part of Octave. 9## 10## Octave is free software: you can redistribute it and/or modify it 11## under the terms of the GNU General Public License as published by 12## the Free Software Foundation, either version 3 of the License, or 13## (at your option) any later version. 14## 15## Octave is distributed in the hope that it will be useful, but 16## WITHOUT ANY WARRANTY; without even the implied warranty of 17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18## GNU General Public License for more details. 19## 20## You should have received a copy of the GNU General Public License 21## along with Octave; see the file COPYING. If not, see 22## <https://www.gnu.org/licenses/>. 23## 24######################################################################## 25 26############################################################ 27## Test suite for pkg.m 28## Tests are organized first by action, and then by options. 29## All actions should be tested, and ideally all options are tested. 30############################################################ 31 32%!shared old_prefix, old_archprefix, old_local_list, old_global_list, prefix, restorecfg, restorecache, restoreglobalcache, rmtmpdir, mfile_pkg_name, mfile_pkg_tgz 33 34%!testif HAVE_Z 35%! ## Do all tests in a temporary directory 36%! [old_prefix, old_archprefix] = pkg ("prefix"); 37%! restorecfg = onCleanup (@() pkg ("prefix", old_prefix, old_archprefix)); 38%! old_local_list = pkg ("local_list"); 39%! restorecache = onCleanup (@() pkg ("local_list", old_local_list)); 40%! old_global_list = pkg ("global_list"); 41%! restoreglobalcache = onCleanup (@() pkg ("global_list", old_global_list)); 42%! prefix = tempname (); 43%! [status] = mkdir (prefix); 44%! if (! status) 45%! error ("pkg.tst: Could not create temporary directory for pkg testing"); 46%! return; # abort further testing 47%! endif 48%! pkg ("prefix", prefix, prefix); 49%! pkg ("local_list", fullfile (prefix, "octave_packages")); 50%! pkg ("global_list", fullfile (prefix, "octave_packages")); 51%! rmtmpdir = @onCleanup (@() confirm_recursive_rmdir (0, "local") && rmdir (prefix, "s")); 52%! 53%! ## Create tar.gz file packages of testing directories in prefix directory 54%! mfile_pkg_name = {"mfile_basic_test", "mfile_minimal_test"}; 55%! mfile_pkg_tar = fullfile (prefix, strcat (mfile_pkg_name, ".tar")); 56%! mfile_pkg_tgz = strcat (mfile_pkg_tar, ".gz"); 57%! for i = 1:numel (mfile_pkg_name) 58%! tar (mfile_pkg_tar{i}, mfile_pkg_name{i}); 59%! gzip (mfile_pkg_tar{i}); 60%! endfor 61 62## Avoids printing to stdout when installing 63%!function silent_pkg_install (varargin) 64%! evalc (["pkg install", sprintf(" %s", varargin{:})]); 65%!endfunction 66 67## Action install/uninstall 68%!testif HAVE_Z 69%! for i = 1:numel (mfile_pkg_name) 70%! silent_pkg_install (mfile_pkg_tgz{i}); 71%! system (["chmod -Rf u+w '" prefix "'"]); ## FIXME: Work around bug #53578 72%! pkg ("uninstall", mfile_pkg_name{i}); 73%! endfor 74%! 75%!error pkg ("install", "nonexistent.zip") 76 77# -local 78%!testif HAVE_Z 79%! for i = 1:numel (mfile_pkg_name) 80%! silent_pkg_install ("-local", mfile_pkg_tgz{i}); 81%! system (["chmod -Rf u+w '" prefix "'"]); ## FIXME: Work around bug #53578 82%! pkg ("uninstall", mfile_pkg_name{i}); 83%! endfor 84 85# -forge (need check for options?) 86## FIXME: Need test 87# We do not test this yet ... fails if no internet connection 88# use dataframe which is an mfile only package 89#%!test 90#%! silent_pkg_install ("-forge", "dataframe"); 91#%! pkg ("uninstall", "dataframe"); 92 93# -nodeps 94## FIXME: Need test 95 96# -verbose 97## FIXME: Need test 98 99## Action load/unload (within install/uninstall) 100%!testif HAVE_Z 101%! save_default_options ("-binary", "local"); 102%! for i = 1:numel (mfile_pkg_name) 103%! name = mfile_pkg_name{i}; 104%! silent_pkg_install ("-local", mfile_pkg_tgz{i}); 105%! unwind_protect 106%! pkg ("load", name); 107%! pkg ("unload", name); 108%! unwind_protect_cleanup 109%! system (["chmod -Rf u+w '" prefix "'"]); ## FIXME: Work around bug #53578 110%! pkg ("uninstall", name); 111%! end_unwind_protect 112%! endfor 113%! 114%!error <package foobar is not installed> pkg ("load", "foobar"); 115 116# -nodeps 117## FIXME: Need test 118 119# -verbose 120## FIXME: Need test 121 122## Action list 123%!test 124%! [user_packages, system_packages] = pkg ("list"); 125 126# -forge 127#%!test 128#%! oct_forge_pkgs = pkg ("list", "-forge"); 129 130## Action describe 131%!testif HAVE_Z 132%! silent_pkg_install ("-local", mfile_pkg_tgz{1}); 133%! [desc, flag] = pkg ("describe", mfile_pkg_name{1}); 134%! ## FIXME: this only tests that the describe command runs, 135%! ## not that the output is in anyway correct. 136%! system (["chmod -Rf u+w '" prefix "'"]); ## FIXME: Work around bug #53578 137%! pkg ("uninstall", mfile_pkg_name{1}); 138 139# -verbose 140## FIXME: Need test 141 142## Action prefix 143%!test 144%! pfx_old = pkg ("prefix"); 145%! unwind_protect 146%! pfx_new = pkg ("prefix", pwd ()); 147%! assert (pfx_new, pwd ()); 148%! unwind_protect_cleanup 149%! pfx = pkg ("prefix", pfx_old); 150%! end_unwind_protect 151 152## Action build 153## FIXME: Need test 154# pkg build -verbose /tmp image-* 155 156## Action rebuild 157## FIXME: Need test 158# pkg rebuild signal 159 160## Future commands 161%!error pkg ("whereis", "myfunc.m") 162%!error pkg ("whereis", "-forge", "myfunc.m") 163 164############################################################ 165## End of Tests 166############################################################ 167