Skip to content

Commit af53228

Browse files
committed
add toolbox_used()
1 parent 92042f4 commit af53228

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

+stdlib/toolbox_used.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
%% TOOLBOX_USED list all Matlab toolboxes used by all functions in pkgPath
2+
%
3+
%% Inputs
4+
% * pkgPath: path to user namespace or file. Example: "+stdlib" or "stdlib.cpu_arch"
5+
%% Outputs
6+
% * tbxMathworks: Mathworks toolbox names used
7+
% * funUser: all user function files under pkgPath
8+
9+
function [tbxMathworks, funUser] = toolbox_used(pkgPath)
10+
arguments
11+
pkgPath string
12+
end
13+
14+
[user, mathworks] = matlab.codetools.requiredFilesAndProducts(pkgPath);
15+
16+
tbxMathworks = string({mathworks.Name}).';
17+
18+
funUser = string(user).';
19+
20+
end

test/TestSys.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
properties
44
CI = getenv("CI") == "true" || getenv("GITHUB_ACTIONS") == "true"
5+
cwd
6+
root
57
end
68

79
properties (TestParameter)
@@ -14,14 +16,35 @@
1416

1517
methods(TestClassSetup)
1618
function pkg_path(tc)
17-
p = matlab.unittest.fixtures.PathFixture(fileparts(fileparts(mfilename('fullpath'))));
19+
tc.cwd = fileparts(mfilename('fullpath'));
20+
tc.root = fileparts(tc.cwd);
21+
p = matlab.unittest.fixtures.PathFixture(tc.root);
1822
tc.applyFixture(p)
1923
end
2024
end
2125

2226

2327
methods (Test, TestTags="impure")
2428

29+
function test_toolbox_used(tc)
30+
[mathworksUsed, userFun] = stdlib.toolbox_used(fullfile(tc.root, "+stdlib"));
31+
Nlicense = length(mathworksUsed);
32+
txt = "stdlib for Matlab should only use builtin functions, no toolboxes";
33+
tc.verifyEqual(Nlicense, 1, txt)
34+
tc.verifyEqual(mathworksUsed, "MATLAB")
35+
tc.verifyGreaterThan(length(userFun), 200) % we have over 200 stdlib functions
36+
37+
[mathworksUsed, userFun] = stdlib.toolbox_used(["edge", "geodetic2ecef"]);
38+
tc.verifyEqual(userFun, string.empty)
39+
tc.verifyEqual(length(mathworksUsed), 3)
40+
end
41+
42+
function test_all_toolboxes(tc)
43+
tc.assumeTrue(stdlib.has_java())
44+
tbx = stdlib.allToolboxes();
45+
tc.verifyClass(tbx, "table")
46+
end
47+
2548
function test_platform_tell(tc)
2649
tc.verifyClass(stdlib.platform_tell(), 'char')
2750
end

0 commit comments

Comments
 (0)