|
4 | 4 | plan("test").Dependencies = "check"; |
5 | 5 | end |
6 | 6 |
|
7 | | - |
8 | 7 | function checkTask(~) |
9 | 8 | % Identify code issues (recursively all Matlab .m files) |
10 | 9 | issues = codeIssues; |
11 | 10 | assert(isempty(issues.Issues), formattedDisplayText(issues.Issues)) |
12 | 11 | end |
13 | 12 |
|
14 | | - |
15 | 13 | function testTask(~) |
16 | | -r = runtests('test/', strict=true, UseParallel=false); |
17 | | -% UseParallel can be a lot slower, especially on Mac |
18 | | -assert(~isempty(r), "No tests were run") |
19 | | -assertSuccess(r) |
20 | | -end |
| 14 | + r = runtests(IncludeSubfolders=true, strict=true, UseParallel=true); |
21 | 15 |
|
| 16 | + assert(~isempty(r), "No tests were run") |
| 17 | + assertSuccess(r) |
| 18 | +end |
22 | 19 |
|
23 | 20 | function coverageTask(~) |
24 | | -import matlab.unittest.TestRunner |
25 | | -import matlab.unittest.Verbosity |
26 | | -import matlab.unittest.plugins.CodeCoveragePlugin |
27 | | -% import matlab.unittest.plugins.XMLPlugin |
28 | | -% import matlab.unittest.plugins.codecoverage.CoberturaFormat |
29 | | - |
30 | | - |
31 | | -pkg = "stdlib"; |
32 | | - |
33 | | -suite = testsuite("test/"); |
34 | | - |
35 | | -% not import to allow use of rest of buildfile with R2022b |
36 | | -format = matlab.unittest.plugins.codecoverage.CoverageResult; |
37 | | - |
38 | | - |
39 | | -runner = TestRunner.withTextOutput(); |
40 | | -runner.addPlugin(... |
41 | | - CodeCoveragePlugin.forPackage(pkg, ... |
42 | | - IncludingSubpackages=true, Producing=format)) |
43 | | - |
44 | | -% runner.addPlugin(XMLPlugin.producingJUnitFormat('test-results.xml')) |
45 | | -% runner.addPlugin(CodeCoveragePlugin.forPackage(pkg, 'Producing', ... |
46 | | -% CoberturaFormat('test-coverage.xml'))) |
47 | | - |
48 | | -run_results = runner.run(suite); |
49 | | -assert(~isempty(run_results), "no tests found") |
| 21 | + cwd = fileparts(mfilename('fullpath')); |
50 | 22 |
|
51 | | -assertSuccess(run_results) |
52 | | - |
53 | | -generateHTMLReport(format.Result) |
| 23 | + coverage_run("stdlib", fullfile(cwd, "test")) |
54 | 24 | end |
55 | 25 |
|
56 | | - |
57 | 26 | function publishTask(~) |
58 | | -% publish (generate) docs from Matlab project |
59 | | -% https://www.mathworks.com/help/matlab/ref/publish.html |
60 | | -% https://www.mathworks.com/help/matlab/matlab_prog/marking-up-matlab-comments-for-publishing.html |
61 | | -% |
62 | | -% for package code -- assumes no classes and depth == 1 |
63 | | -pkg_name = "stdlib"; |
64 | | - |
65 | | -pkg = what(pkg_name); |
66 | | - |
67 | | -%% generate docs |
68 | | -cwd = fileparts(mfilename('fullpath')); |
69 | | -docs = fullfile(cwd, "docs"); |
70 | | -readme = fullfile(docs, "index.html"); |
71 | | - |
72 | | -if ~isfolder(docs) |
73 | | - mkdir(docs); |
74 | | -end |
75 | | - |
76 | | -txt = ["<!DOCTYPE html> <head> <title>Standard library for Matlab API</title> <body>", ... |
77 | | - "<h1>stdlib for Matlab API</h1>", ... |
78 | | - "A standard library of functions for Matlab.", ... |
79 | | - "<h2>API Reference</h2>"]; |
80 | | -fid = fopen(readme, 'w'); |
81 | | -fprintf(fid, join(txt, "\n")); |
82 | | - |
83 | | -for sub = pkg.m.' |
84 | | - s = sub{1}; |
85 | | - [~, name] = fileparts(s); |
86 | | - doc_fn = publish(pkg_name + "." + name, evalCode=false, outputDir=docs); |
87 | | - disp(doc_fn) |
88 | | - % inject summary into Readme.md |
89 | | - summary = split(string(help(pkg_name + "." + name)), newline); |
90 | | - words = split(strip(summary(1)), " "); |
91 | | - % purposefully this will error if no docstring |
92 | | - fname = words(1); |
93 | | - if(lower(fname) ~= lower(name)) |
94 | | - error("fname %s does not match name %s", fname, name) |
95 | | - end |
96 | | - line = "<a href=" + name + ".html>" + fname + "</a> "; |
97 | | - if(length(words) > 1) |
98 | | - line = line + join(words(2:end)); |
99 | | - end |
100 | | - fprintf(fid, line + "<br>\n"); |
101 | | -end |
102 | | - |
103 | | -fprintf(fid, "</body> </html>"); |
104 | | - |
105 | | -fclose(fid); |
| 27 | + cwd = fileparts(mfilename('fullpath')); |
| 28 | + outdir = fullfile(cwd, "docs"); |
106 | 29 |
|
| 30 | + publish_gen_index_html("stdlib", ... |
| 31 | + "A standard library of functions for Matlab.", ... |
| 32 | + outdir) |
107 | 33 | end |
0 commit comments