Skip to content

Commit 351a658

Browse files
committed
Add infrastructure for unittests.
1 parent 38fb9b3 commit 351a658

4 files changed

Lines changed: 52 additions & 15 deletions

File tree

.github/workflows/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,29 @@ jobs:
5050
# Optional category for the results
5151
# Used to differentiate multiple results for one commit
5252
category: matlab
53+
54+
- name: Upload Test Results
55+
if: success() || failure()
56+
uses: actions/upload-artifact@v7
57+
with:
58+
if-no-files-found: error
59+
path: testResults.xml
60+
61+
publish-test-results:
62+
needs: check-and-test
63+
runs-on: ubuntu-latest
64+
permissions:
65+
checks: write
66+
# only needed unless run with comment_mode: off
67+
pull-requests: write
68+
if: !cancelled()
69+
steps:
70+
- name: Download Test Results
71+
uses: actions/download-artifact@v8
72+
with:
73+
path: artifacts
74+
75+
- name: Publish Test Results
76+
uses: EnricoMi/publish-unit-test-result-action@v2
77+
with:
78+
files: "artifacts/**/*.xml"

buildfile.m

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,37 @@
11
function plan = buildfile
22
import matlab.buildtool.Task
3-
import matlab.buildtool.tasks.CodeIssuesTask
4-
import matlab.buildtool.tasks.TestTask
5-
import matlab.unittest.Verbosity
3+
import matlab.buildtool.tasks.*
64

75
% Create a plan with no tasks
86
plan = buildplan;
97

108
% Add a task to identify and export the code issues
11-
plan("check") = CodeIssuesTask(["toolbox", "tests"],...
12-
WarningThreshold=0,...
9+
plan("check") = CodeIssuesTask(["toolbox", "tests"], ...
10+
WarningThreshold=0, ...
1311
Results="code-issues/results.sarif");
1412

15-
plan("test") = Task(...
16-
"Description","Build toolbox dependencies with vcpkg",...
17-
"Inputs",["toolbox", "tests/vcpkg.json"],...
18-
"Outputs",[fullfile("work",vcpkg.getHostTriplet), fullfile("work",vcpkg.getTargetTriplet)],...
19-
Actions = {@(~) vcpkg.buildVcpkgDeps('tests','--x-install-root=../work')});
13+
plan("unit") = TestTask( "tests", ...
14+
Description="Run MATLAB unit tests", ...
15+
SourceFiles="toolbox", ...
16+
TestResults="testResults.xml");
17+
18+
plan("integration") = Task( ...
19+
Description="Build sample toolbox dependencies with vcpkg", ...
20+
Inputs=["toolbox", "tests/vcpkg.json"], ...
21+
Outputs=[fullfile("work", vcpkg.getHostTriplet), fullfile("work", vcpkg.getTargetTriplet)], ...
22+
Actions={@(~) vcpkg.buildVcpkgDeps('tests', '--x-install-root=../work')});
23+
24+
plan("test") = Task( ...
25+
Description="Run all tests", ...
26+
Dependencies=["unit" "integration"]);
2027

2128
% Package toolbox
22-
plan("package") = Task(...
23-
Description = "Package toolbox", ...
24-
Dependencies = ["check" "test"], ...
25-
Actions = {@(~,toolboxVersion) packageToolbox(erase(toolboxVersion,"v"))});
29+
plan("package") = Task( ...
30+
Description="Package toolbox", ...
31+
Dependencies=["check" "test"], ...
32+
Actions={@(~, toolboxVersion) packageToolbox(erase(toolboxVersion, "v"))});
2633

27-
% Make the "test" task the default task in the plan
34+
% Make check and test the default tasks in the plan
2835
plan.DefaultTasks = ["check" "test"];
2936

3037
end
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info Ref="tests" Type="Relative"/>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Info location="0c2237cf-1193-46a8-a375-3db856a5559f" type="Reference"/>

0 commit comments

Comments
 (0)