annotate scripts/prefs/getpref.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 7854d5752dd2
children 597f3ee61a48
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2012-2022 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 27898
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/>.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 ## This file is part of Octave.
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.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: 23220
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: 22323
diff changeset
13 ## (at your option) any later version.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.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: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 ##
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
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: 23220
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 ########################################################################
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.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: 20834
diff changeset
27 ## @deftypefn {} {@var{val} =} getpref ("@var{group}", "@var{pref}")
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20834
diff changeset
28 ## @deftypefnx {} {@var{val} =} getpref ("@var{group}", "@var{pref}", @var{default})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20834
diff changeset
29 ## @deftypefnx {} {@{@var{val1}, @var{val2}, @dots{}@} =} getpref ("@var{group}", @{"@var{pref1}", "@var{pref2"}, @dots{}@})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20834
diff changeset
30 ## @deftypefnx {} {@var{prefstruct} =} getpref ("@var{group}")
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20834
diff changeset
31 ## @deftypefnx {} {@var{prefstruct} =} getpref ()
20160
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
32 ## Return the preference value corresponding to the named preference @var{pref}
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
33 ## in the preference group @var{group}.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 ##
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
35 ## The named preference group must be a string.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 ##
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
37 ## If @var{pref} does not exist in @var{group} and @var{default} is specified,
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
38 ## create the preference with value @var{default} and return @var{default}.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 ##
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
40 ## The preference @var{pref} may be a string or cell array of strings. If it
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
41 ## is a cell array of strings then a cell array of preferences is returned.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 ##
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
43 ## The corresponding default value @var{default} may be any Octave value,
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
44 ## .e.g., double, struct, cell array, object, etc. Or, if @var{pref} is a cell
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
45 ## array of strings then @var{default} must be a cell array of values with the
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
46 ## same size as @var{pref}.
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 ##
20160
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
48 ## If neither @var{pref} nor @var{default} are specified, return a structure
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
49 ## of preferences for the preference group @var{group}.
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
50 ##
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
51 ## If no arguments are specified, return a structure containing all groups of
03b9d17a2d95 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
52 ## preferences and their values.
13943
5820f8ce683e doc: Add undocumented functions to manual for 3.6.0 release
Rik <octave@nomad.inbox5.com>
parents: 13929
diff changeset
53 ## @seealso{addpref, setpref, ispref, rmpref}
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 ## @end deftypefn
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 function retval = getpref (group, pref, default)
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 if (nargin == 0)
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 retval = loadprefs ();
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 elseif (nargin == 1)
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
61 if (! ischar (group))
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
62 error ("getpref: GROUP must be a string");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
63 endif
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
64 prefs = loadprefs ();
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
65 if (isfield (prefs, group))
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
66 retval = prefs.(group);
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 else
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
68 ## FIXME: Is this the right behavior, or should it produce an error?
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
69 retval = [];
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 endif
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
71 else
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
72 if (! (ischar (pref) || iscellstr (pref)))
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
73 error ("getpref: PREF must be a string or cellstr");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
74 endif
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
75
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 grp = getpref (group);
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
77
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 if (ischar (pref))
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 if (isfield (grp, pref))
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 retval = grp.(pref);
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 elseif (nargin == 3)
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
82 addpref (group, pref, default);
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 retval = default;
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 else
22760
c4d80b9d2898 maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents: 22755
diff changeset
85 error ("getpref: preference %s does not exist in GROUP %s",
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
86 pref, group);
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 endif
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
88 else
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
89 if (nargin != 2 && ! size_equal (pref, default))
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20160
diff changeset
90 error ("getpref: size mismatch for PREF and DEFAULT");
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 endif
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
92
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
93 for i = 1:numel (pref)
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
94 if (isfield (grp, pref{i}))
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
95 retval{i} = grp.(pref{i});
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
96 elseif (nargin == 3)
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
97 addpref (group, pref{i}, default{i});
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
98 retval{i} = default{i};
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
99 else
22760
c4d80b9d2898 maint: Capitalize variable names appearing in error() messages of m-files.
Rik <rik@octave.org>
parents: 22755
diff changeset
100 error ("getpref: preference %s does not exist in GROUP %s",
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
101 pref{i}, group);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
102 endif
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
103 endfor
13261
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 endif
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 endif
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 endfunction
9134ca9d4ec8 new functions for Matlab compatibility
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 14868
diff changeset
109
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
110 %!test
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
111 %! HOME = getenv ("HOME");
24835
c644c53c8d37 use unique directory names in getpref and setpref tests
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
112 %! tmp_home = tempname ();
26698
63b5a17ba30f Use save_default_options() to make BIST test suite robust against user configurations.
Rik <rik@octave.org>
parents: 26376
diff changeset
113 %! save_default_options ("-binary", "local");
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
114 %! unwind_protect
24835
c644c53c8d37 use unique directory names in getpref and setpref tests
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
115 %! mkdir (tmp_home);
c644c53c8d37 use unique directory names in getpref and setpref tests
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
116 %! setenv ("HOME", tmp_home);
c644c53c8d37 use unique directory names in getpref and setpref tests
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
117 %!
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
118 %! addpref ("group1", "pref1", [1 2 3]);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
119 %! addpref ("group2", {"prefA", "prefB"}, {"StringA", {"StringB"}});
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
120 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
121 %! exp.group1.pref1 = [1 2 3];
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
122 %! exp.group2.prefA = "StringA";
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
123 %! exp.group2.prefB = {"StringB"};
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
124 %! obs = getpref ();
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
125 %! assert (obs, exp);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
126 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
127 %! assert (getpref ("group1"), exp.group1);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
128 %! assert (getpref ("group2"), exp.group2);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
129 %! assert (getpref ("group3"), []);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
130 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
131 %! assert (getpref ("group1", "pref1"), [1 2 3]);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
132 %! assert (getpref ("group2", "prefA"), "StringA");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
133 %! assert (getpref ("group2", "prefB"), {"StringB"});
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
134 %! assert (getpref ("group1", "pref2", "New_Value"), "New_Value");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
135 %! assert (getpref ("group1", "pref2"), "New_Value");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
136 %! fail ('getpref ("group1", "no_such_pref")', ...
22765
01aae08a0105 maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents: 22760
diff changeset
137 %! "preference no_such_pref does not exist in GROUP group1");
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
138 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
139 %! assert (getpref ("group2", {"prefA", "prefB"}), {"StringA", {"StringB"}});
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
140 %! assert (getpref ("group2", {"prefA", "prefC"}, {1, "StringC"}),
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
141 %! {"StringA", "StringC"});
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
142 %! assert (getpref ("group2", "prefC"), "StringC");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
143 %! fail ('getpref ("group1", {"p1", "p2"}, 1)', ...
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
144 %! "size mismatch for PREF and DEFAULT");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
145 %! fail ('getpref ("group2", {"prefA", "prefD"})',
22765
01aae08a0105 maint: Rename variables to match documentation in m-files.
Rik <rik@octave.org>
parents: 22760
diff changeset
146 %! "preference prefD does not exist in GROUP group2");
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
147 %!
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
148 %! unwind_protect_cleanup
24835
c644c53c8d37 use unique directory names in getpref and setpref tests
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
149 %! unlink (fullfile (tmp_home, ".octave_prefs"));
28087
9cb04a9e81ec rmdir: throw an error if operation fails and nargout == 0 (bug #57830).
Rik <rik@octave.org>
parents: 27923
diff changeset
150 %! sts = rmdir (tmp_home);
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
151 %! if (isempty (HOME))
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
152 %! unsetenv ("HOME");
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
153 %! else
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
154 %! setenv ("HOME", HOME);
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
155 %! endif
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
156 %! end_unwind_protect
17338
1c89599167a6 maint: End m-files with 1 blank line.
Rik <rik@octave.org>
parents: 14868
diff changeset
157
20834
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
158 %!error <GROUP must be a string> getpref (1)
27b333c88c8e Overhaul m-files in prefs directory.
Rik <rik@octave.org>
parents: 20711
diff changeset
159 %!error <PREF must be a string> getpref ("group1", 1, 2)