Skip to content

Commit 5efb20e

Browse files
committed
stronger R2020b checking args
1 parent d5e265b commit 5efb20e

File tree

16 files changed

+36
-122
lines changed

16 files changed

+36
-122
lines changed

+stdlib/+fileio/TestFileio.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ function test_makedir(tc)
7979
function test_which(tc)
8080
import stdlib.fileio.which
8181

82-
tc.verifyEmpty(which(string.empty))
83-
8482
n = "matlab";
8583
% assumes Matlab in environment variable PATH
8684
tc.assumeNotEmpty(which(n))

+stdlib/+fileio/copyfile.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ function copyfile(in, out)
22
%% copyfile(path) overloads copyfile with tilde expansion
33
% "out" may be a directory or directory/name.ext
44
arguments
5-
in (1,1) string
6-
out (1,1) string
5+
in (1,1) string {mustBeNonzeroLengthText}
6+
out (1,1) string {mustBeNonzeroLengthText}
77
end
88

99
import stdlib.fileio.expanduser

+stdlib/+fileio/makedir.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ function makedir(direc)
22
%% malformed paths can be "created" but are not accessible.
33
% This function works around that bug in Matlab mkdir().
44
arguments
5-
direc (1,1) string
5+
direc (1,1) string {mustBeNonzeroLengthText}
66
end
77

88
direc = stdlib.fileio.expanduser(direc);

+stdlib/+fileio/md5sum.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function hash = md5sum(file)
22
% compute MD5 hash of file
33
arguments
4-
file (1,1) string
4+
file (1,1) string {mustBeNonzeroLengthText}
55
end
66

77
import stdlib.fileio.expanduser

+stdlib/+fileio/sha256sum.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function hash = sha256sum(file)
22
% compute sha256 hash of file
33
arguments
4-
file (1,1) string
4+
file (1,1) string {mustBeNonzeroLengthText}
55
end
66

77
import stdlib.fileio.expanduser

+stdlib/+fileio/which.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
% like Python shutil.which, may return relative or absolute path
44

55
arguments
6-
name string
6+
name (1,1) string {mustBeNonzeroLengthText}
77
fpath string = getenv('PATH')
8-
subdir (1,:) string = ""
8+
subdir (1,:) string {mustBeNonempty} = ""
99
end
1010

11-
assert(length(name) < 2, "fileio.which is for one executable at a time")
12-
assert(~isempty(subdir), "put '' or '""' for subdir if not wanted")
13-
1411
exe = string.empty;
1512

1613
if ispc

+stdlib/+hdf5nc/TestHDF5.m

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ function test_get_variables(tc)
6969
import stdlib.hdf5nc.h5variables
7070
basic = tc.TestData.basic;
7171

72-
tc.verifyEmpty(h5variables(string.empty))
73-
tc.verifyEmpty(h5variables(string.empty, string.empty))
74-
[a,b] = h5variables(string.empty, "hi");
75-
tc.verifyEmpty(a)
76-
tc.verifyEmpty(b)
77-
7872
v = h5variables(basic);
7973
tc.verifyEqual(sort(v), ["A0", "A1", "A2", "A3", "A4"])
8074

@@ -108,16 +102,9 @@ function test_exists(tc, vars)
108102
tc.verifyTrue(e)
109103

110104
% vector
111-
e = h5exists(basic, [vars, "oops", ""]);
105+
e = h5exists(basic, [vars, "oops"]);
112106
tc.verifyTrue(isrow(e))
113-
tc.verifyEqual(e, [true, false, false])
114-
115-
% empty
116-
e = h5exists(basic, string.empty);
117-
tc.verifyEmpty(e)
118-
119-
tc.verifyEqual(h5exists(string.empty, ["oops", "hi"]), [false, false])
120-
tc.verifyEmpty(h5exists(string.empty, string.empty))
107+
tc.verifyEqual(e, [true, false])
121108
end
122109

123110

@@ -144,11 +131,6 @@ function test_size(tc)
144131
s = h5size(basic, '/A4');
145132
tc.verifyTrue(isvector(s))
146133
tc.verifyEqual(s, [4,3,2,5])
147-
148-
% empty
149-
tc.verifyEmpty(h5size(basic, string.empty))
150-
tc.verifyEmpty(h5size(string.empty, string.empty))
151-
tc.verifyEmpty(h5size(string.empty, "hi"))
152134
end
153135

154136

@@ -215,9 +197,6 @@ function test_string(tc, str)
215197

216198
function test_file_missing(tc)
217199

218-
tc.verifyError(@() stdlib.hdf5nc.h5exists(tempname,"/bad"), 'hdf5nc:h5variables:fileNotFound')
219-
tc.verifyError(@() stdlib.hdf5nc.h5variables(tempname), 'hdf5nc:h5variables:fileNotFound')
220-
tc.verifyError(@() stdlib.hdf5nc.h5size(tempname,"/bad"), 'hdf5nc:h5size:fileNotFound')
221200
[~,badname] = fileparts(tempname);
222201
tc.verifyError(@() stdlib.hdf5nc.h5save(badname,"/bad",0), 'hdf5nc:h5save:fileNotFound')
223202
end
@@ -227,7 +206,7 @@ function test_real_only(tc)
227206
basic = tc.TestData.basic;
228207

229208
tc.verifyError(@() h5save(basic, "/bad_imag", 1j), 'MATLAB:validators:mustBeReal')
230-
tc.verifyError(@() h5save(basic, "", 0), 'MATLAB:expectedNonempty')
209+
tc.verifyError(@() h5save(basic, "", 0), 'MATLAB:validators:mustBeNonzeroLengthText')
231210
end
232211

233212
end

+stdlib/+hdf5nc/TestNetCDF.m

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ function test_get_variables(tc)
5656
import stdlib.hdf5nc.ncvariables
5757
basic = tc.TestData.basic;
5858

59-
tc.verifyEmpty(ncvariables(string.empty))
60-
61-
6259
tc.verifyEqual(sort(ncvariables(basic)), ["A0", "A1", "A2", "A3", "A4"])
6360
end
6461

@@ -73,16 +70,10 @@ function test_exists(tc, vars)
7370
tc.verifyTrue(e)
7471

7572
% vector
76-
e = ncexists(basic, [vars, "oops", ""]);
73+
e = ncexists(basic, [vars, "oops"]);
7774
tc.verifyTrue(isrow(e))
78-
tc.verifyEqual(e, [true, false, false])
79-
80-
% empty
81-
e = ncexists(basic, string.empty);
82-
tc.verifyEmpty(e)
75+
tc.verifyEqual(e, [true, false])
8376

84-
tc.verifyEqual(ncexists(string.empty, ["oops", "hi"]), [false, false])
85-
tc.verifyEmpty(ncexists(string.empty, string.empty))
8677
end
8778

8879

@@ -111,10 +102,6 @@ function test_size(tc)
111102
tc.verifyTrue(isvector(s))
112103
tc.verifyEqual(s, [4,3,2,5])
113104

114-
% empty
115-
tc.verifyEmpty(ncsize(basic, string.empty))
116-
tc.verifyEmpty(ncsize(string.empty, string.empty))
117-
tc.verifyEmpty(ncsize(string.empty, "hi"))
118105
end
119106

120107

@@ -178,19 +165,16 @@ function test_no_char_string(tc)
178165

179166
function test_file_missing(tc)
180167

181-
tc.verifyError(@() stdlib.hdf5nc.ncexists(tempname,""), 'hdf5nc:ncvariables:fileNotFound')
182-
tc.verifyError(@() stdlib.hdf5nc.ncvariables(tempname), 'hdf5nc:ncvariables:fileNotFound')
183-
tc.verifyError(@() stdlib.hdf5nc.ncsize(tempname,""), 'hdf5nc:ncsize:fileNotFound')
184168
[~,badname] = fileparts(tempname);
185-
tc.verifyError(@() stdlib.hdf5nc.ncsave(badname,"",0), 'hdf5nc:ncsave:fileNotFound')
169+
tc.verifyError(@() stdlib.hdf5nc.ncsave(badname,"bad",0), 'hdf5nc:ncsave:fileNotFound')
186170
end
187171

188172
function test_real_only(tc)
189173
import stdlib.hdf5nc.ncsave
190174
basic = tc.TestData.basic;
191175

192176
tc.verifyError(@() ncsave(basic, "bad_imag", 1j), 'MATLAB:validators:mustBeReal')
193-
tc.verifyError(@() ncsave(basic, "", 0), 'MATLAB:imagesci:netcdf:badLocationString')
177+
tc.verifyError(@() ncsave(basic, "", 0), 'MATLAB:validators:mustBeNonzeroLengthText')
194178
end
195179

196180
end

+stdlib/+hdf5nc/h5exists.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
% exists: boolean (scalar or vector)
1212

1313
arguments
14-
file string
15-
varnames (1,:) string
14+
file (1,1) string {mustBeNonzeroLengthText}
15+
varnames (1,:) string {mustBeNonempty,mustBeNonzeroLengthText}
1616
end
1717

1818
import stdlib.hdf5nc.h5variables

+stdlib/+hdf5nc/h5save.m

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@ function h5save(filename, varname, A, opts)
44
% parent folder (file directory) must already exist
55

66
arguments
7-
filename (1,1) string
8-
varname (1,1) string
7+
filename (1,1) string {mustBeNonzeroLengthText}
8+
varname (1,1) string {mustBeNonzeroLengthText}
99
A {mustBeNonempty}
1010
opts.size (1,:) double {mustBeInteger,mustBeNonnegative} = []
11-
opts.type string = string.empty
11+
opts.type string {mustBeScalarOrEmpty} = string.empty
1212
end
1313

1414
import stdlib.fileio.expanduser
1515
import stdlib.hdf5nc.h5exists
1616

17-
if strlength(varname) < 2
18-
error("MATLAB:expectedNonempty", "variable name must start with / and be non-empty")
19-
end
20-
2117
if isnumeric(A)
2218
mustBeReal(A)
2319
end

0 commit comments

Comments
 (0)