annotate scripts/help/which.m @ 28896:90fea9cc9caa

test: Add expected error message <Invalid call> to BIST tests for nargin. * acosd.m, acot.m, acotd.m, acoth.m, acsc.m, acscd.m, acsch.m, asec.m, asecd.m, asech.m, asind.m, atand.m, cosd.m, cot.m, cotd.m, coth.m, csc.m, cscd.m, csch.m, sec.m, secd.m, sech.m, sind.m, tand.m, cart2pol.m, cart2sph.m, celldisp.m, common_size.m, deal.m, del2.m, fliplr.m, integral2.m, interp1.m, isequal.m, isequaln.m, nextpow2.m, pol2cart.m, quad2d.m, quadl.m, quadv.m, randi.m, rat.m, repelem.m, rescale.m, shiftdim.m, sortrows.m, sph2cart.m, xor.m, convhull.m, delaunay.m, delaunayn.m, griddata.m, griddatan.m, inpolygon.m, voronoi.m, voronoin.m, listdlg.m, msgbox.m, questdlg.m, rmappdata.m, setappdata.m, __gripe_missing_component__.m, get_first_help_sentence.m, type.m, which.m, cmpermute.m, cmunique.m, gray2ind.m, imfinfo.m, imshow.m, imwrite.m, ind2rgb.m, movie.m, rgb2ind.m, importdata.m, bandwidth.m, condeig.m, gls.m, housh.m, linsolve.m, logm.m, lscov.m, normest.m, normest1.m, ols.m, ordeig.m, planerot.m, qzhess.m, rref.m, copyfile.m, delete.m, dos.m, fileparts.m, getfield.m, menu.m, mkdir.m, movefile.m, orderfields.m, publish.m, setfield.m, substruct.m, unix.m, unpack.m, decic.m, ode23.m, ode23s.m, ode45.m, fminsearch.m, lsqnonneg.m, pqpnonneg.m, sqp.m, annotation.m, lighting.m, shading.m, area.m, compass.m, contourc.m, feather.m, fplot.m, hist.m, isocaps.m, isocolors.m, isonormals.m, isosurface.m, ostreamtube.m, pie.m, pie3.m, reducepatch.m, reducevolume.m, rose.m, smooth3.m, stairs.m, stem.m, stem3.m, stream2.m, stream3.m, streamline.m, streamribbon.m, streamtube.m, surfnorm.m, trimesh.m, trisurf.m, colstyle.m, hgload.m, linkprop.m, meshgrid.m, ndgrid.m, padecoef.m, polyfit.m, polyval.m, unmkpp.m, profexport.m, ismember.m, unique.m, movfun.m, movslice.m, periodogram.m, sinc.m, spdiags.m, sprandsym.m, betaincinv.m, ellipke.m, factor.m, gammainc.m, gammaincinv.m, isprime.m, lcm.m, gallery.m, hadamard.m, bounds.m, corrcoef.m, discrete_rnd.m, empirical_rnd.m, histc.m, mode.m, movmad.m, movmax.m, movmean.m, movmedian.m, movmin.m, movprod.m, movstd.m, movsum.m, movvar.m, ranks.m, runlength.m, zscore.m, str2num.m, strchr.m, strsplit.m, strtok.m, untabify.m, assert.m, demo.m, example.m, speed.m, test.m, datenum.m, datevec.m, webread.m, webwrite.m: Add expected error message <Invalid call> to BIST tests for nargin. Remove redundant tests for nargin greater than the number of declared inputs which are now handled by interpreter.
author Rik <rik@octave.org>
date Sun, 11 Oct 2020 21:59:35 -0700
parents c28b8ba841fb
children 7854d5752dd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 ## Copyright (C) 2009-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27018
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
7 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10549
diff changeset
8 ## This file is part of Octave.
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10549
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23295
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23295
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22430
diff changeset
13 ## (at your option) any later version.
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
14 ##
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10549
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22430
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22430
diff changeset
18 ## GNU General Public License for more details.
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
19 ##
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
11104
2c356a35d7f5 fix copyright notices
John W. Eaton <jwe@octave.org>
parents: 10549
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23295
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
25
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20158
diff changeset
27 ## @deftypefn {} {} which name @dots{}
20158
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
28 ## Display the type of each @var{name}.
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
29 ##
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
30 ## If @var{name} is defined from a function file, the full name of the file is
7503499a252b doc: Update docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ## also displayed.
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
32 ## @seealso{help, lookfor}
11547
e1851653d59c Eliminate @deffn macros.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
33 ## @end deftypefn
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
34
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
35 function varargout = which (varargin)
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
36
20922
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
37 if (nargin == 0 || ! iscellstr (varargin))
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
38 print_usage ();
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
39 endif
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
40
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
41 m = __which__ (varargin{:});
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
42
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
43 ## Check whether each name is a variable, variables take precedence over
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
44 ## functions in name resolution.
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
45 for i = 1:nargin
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
46 m(i).is_variable = evalin ("caller",
27018
a20ead51515d move core of evalin function to evaluator
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
47 ['exist ("' undo_string_escapes(m(i).name) '", "var")'], "");
20922
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
48 if (m(i).is_variable)
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
49 m(i).file = "variable";
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
50 endif
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
51 endfor
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
52
20922
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
53 if (nargout == 0)
18451
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
54 for i = 1:nargin
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
55 if (m(i).is_variable)
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
56 printf ("'%s' is a variable\n", m(i).name);
20922
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
57 elseif (isempty (m(i).file))
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
58 if (! isempty (m(i).type))
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
59 printf ("'%s' is a %s\n",
20922
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
60 m(i).name, m(i).type);
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
61 endif
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
62 else
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
63 if (isempty (m(i).type))
25781
e04c56bbbace isdir.m: Make m-file a legacy function (bug #54489)
Rik <rik@octave.org>
parents: 25054
diff changeset
64 if (isfolder (m(i).file))
23046
168a18a57fc2 which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents: 22755
diff changeset
65 printf ("'%s' is the directory %s\n",
168a18a57fc2 which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents: 22755
diff changeset
66 m(i).name, m(i).file);
168a18a57fc2 which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents: 22755
diff changeset
67 else
168a18a57fc2 which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents: 22755
diff changeset
68 printf ("'%s' is the file %s\n",
168a18a57fc2 which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents: 22755
diff changeset
69 m(i).name, m(i).file);
168a18a57fc2 which.m: change output to distinguish between files and directories.
Rik <rik@octave.org>
parents: 22755
diff changeset
70 endif
20922
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
71 else
21634
96518f623c91 Backed out changeset dcf8922b724b
Mike Miller <mtmiller@octave.org>
parents: 21633
diff changeset
72 printf ("'%s' is a %s from the file %s\n",
20922
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
73 m(i).name, m(i).type, m(i).file);
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
74 endif
18451
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
75 endif
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
76 endfor
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
77 else
20922
49081851fddc Eliminate duplicate input arg checking in which.m and __which__.
Rik <rik@octave.org>
parents: 20852
diff changeset
78 varargout = {m.file};
23295
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
79 ## Return type, instead of "", for built-in classes (bug #50541).
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
80 ## FIXME: remove code if __which__ is updated to return path for classes
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
81 idx = find (cellfun ("isempty", varargout));
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
82 if (idx)
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
83 varargout(idx) = m(idx).type;
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
84 endif
8575
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
85 endif
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
86
f134925a1cfa m-file implementation of help system
Soren Hauberg <soren@hauberg.org>
parents:
diff changeset
87 endfunction
12843
3035c2e130de codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents: 11547
diff changeset
88
3035c2e130de codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents: 11547
diff changeset
89
3035c2e130de codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents: 11547
diff changeset
90 %!test
3035c2e130de codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents: 11547
diff changeset
91 %! str = which ("ls");
23295
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
92 %! assert (str(end-17:end), fullfile ("miscellaneous", "ls.m"));
12843
3035c2e130de codesprint: Tests for which.m
Rik <octave@nomad.inbox5.com>
parents: 11547
diff changeset
93 %!test
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
94 %! str = which ("fftw");
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
95 %! assert (str(end-7:end), "fftw.oct");
23295
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
96 %!test
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
97 %! str = which ("inputParser");
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
98 %! assert (str, "built-in function");
18451
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
99 %!test
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
100 %! x = 3;
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
101 %! str = which ("x");
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
102 %! assert (str, "variable");
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
103
23295
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
104 %!assert (which ("__NO_SUCH_NAME__"), "")
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
105
18451
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
106 %!test
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
107 %! str = which ("fftw");
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
108 %! assert (str(end-7:end), "fftw.oct");
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
109 %! fftw = 12;
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
110 %! str = which ("fftw");
18451
2bd78ab75b23 which: Properly identify workspace variables (bug #37320)
Mike Miller <mtmiller@ieee.org>
parents: 17744
diff changeset
111 %! assert (str, "variable");
28024
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
112 %! clear fftw;
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
113 %! str = which ("fftw");
c28b8ba841fb move sparse functions from dldfcn to corefcn directory (bug #57459)
John W. Eaton <jwe@octave.org>
parents: 27923
diff changeset
114 %! assert (str(end-7:end), "fftw.oct");
23295
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
115
28896
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28024
diff changeset
116 %!error <Invalid call> which ()
90fea9cc9caa test: Add expected error message <Invalid call> to BIST tests for nargin.
Rik <rik@octave.org>
parents: 28024
diff changeset
117 %!error <Invalid call> which (1)
23295
c1362a71fb0e which.m: Return a non-empty string for built-in classes and command line fcns (bug #50541);
Rik <rik@octave.org>
parents: 23220
diff changeset
118