Skip to content

Commit d88bc0f

Browse files
author
Sam Eagen
committed
Add unit tests for parallelizable build summary plugin
1 parent 1a3d7e7 commit d88bc0f

3 files changed

Lines changed: 132 additions & 3 deletions

File tree

.github/workflows/bat.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@ permissions:
44
contents: read
55

66
jobs:
7+
plugin-tests:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
include:
13+
- os: ubuntu-latest
14+
- os: windows-latest
15+
- os: macos-latest
16+
steps:
17+
- uses: actions/checkout@v5
18+
- uses: matlab-actions/setup-matlab@v2
19+
- uses: matlab-actions/run-tests@v2
20+
721
bat:
822
name: Build and Test
923
runs-on: ubuntu-22.04

plugins/+buildframework/ParallelizableBuildSummaryPlugin.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@
77
end
88

99
methods
10-
function plugin = ParallelizableBuildSummaryPlugin()
11-
tempRoot = getenv("RUNNER_TEMP");
10+
function plugin = ParallelizableBuildSummaryPlugin(options)
11+
arguments
12+
options.TempFolder (1,:) string = string.empty()
13+
end
14+
15+
if ~isempty(options.TempFolder)
16+
tempRoot = options.TempFolder;
17+
else
18+
tempRoot = getenv("RUNNER_TEMP");
19+
end
20+
1221
plugin.TempFolder = fullfile(tempRoot, "taskDetails");
1322
end
1423
end
@@ -31,7 +40,8 @@ function runBuild(plugin, pluginData)
3140
end
3241

3342
% Write to file
34-
[fID, msg] = fopen(fullfile(getenv("RUNNER_TEMP"), "buildSummary" + getenv("GITHUB_RUN_ID") + ".json"), "w");
43+
folder = fileparts(plugin.TempFolder);
44+
[fID, msg] = fopen(fullfile(folder, "buildSummary" + getenv("GITHUB_RUN_ID") + ".json"), "w");
3545
if fID == -1
3646
warning("buildframework:BuildSummaryPlugin:UnableToOpenFile","Unable to open a file required to create the MATLAB build summary table: %s", msg);
3747
else
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
classdef tParallelizableBuildSummaryPlugin < matlab.unittest.TestCase
2+
3+
% Copyright 2026 The MathWorks, Inc.
4+
5+
properties
6+
TempFolder
7+
Plugin
8+
Runner
9+
end
10+
11+
methods (TestClassSetup)
12+
function setupPath(testCase)
13+
import matlab.unittest.fixtures.PathFixture;
14+
15+
testCase.applyFixture(PathFixture(fileparts(fileparts(mfilename("fullpath")))));
16+
end
17+
end
18+
19+
methods (TestMethodSetup)
20+
function createPlugin(testCase)
21+
import matlab.unittest.fixtures.WorkingFolderFixture;
22+
23+
testCase.applyFixture(WorkingFolderFixture);
24+
testCase.TempFolder = pwd();
25+
26+
testCase.Plugin = ParallelizableBuildSummaryPlugin(TempFolder=testCase.TempFolder);
27+
testCase.Runner = matlab.buildtool.BuildRunner.withNoPlugins();
28+
testCase.Runner.addPlugin(testCase.Plugin);
29+
end
30+
end
31+
32+
methods (Test)
33+
function runningBuildCreatesSummaryArtifact(testCase)
34+
plan = buildplan();
35+
plan("t1") = Task();
36+
plan("t2") = Task();
37+
38+
testCase.Runner.run(plan, ["t1", "t2"]);
39+
40+
testCase.verifyTrue(isfile(fullfile(testCase.TempFolder, "buildSummary.json")));
41+
end
42+
43+
function runningBuildCreatesSummaryArtifactWithExpectedTasks(testCase)
44+
plan = buildplan();
45+
plan("t1") = Task();
46+
plan("t2") = Task();
47+
48+
testCase.Runner.run(plan, ["t1", "t2"]);
49+
50+
f = fullfile(testCase.TempFolder, "buildSummary.json");
51+
testCase.assertTrue(isfile(f));
52+
53+
s = readstruct(f);
54+
55+
testCase.verifySize(s, [1 2]);
56+
testCase.verifyEqual(s(1).name, "t1");
57+
testCase.verifyEqual(s(2).name, "t2");
58+
end
59+
60+
function summaryArtifactStatusesAreCorrect(testCase)
61+
plan = buildplan();
62+
plan("t1") = Task();
63+
plan("t2") = Task(Actions=@()error("bam"));
64+
65+
testCase.Runner.run(plan, ["t1", "t2"]);
66+
67+
f = fullfile(testCase.TempFolder, "buildSummary.json");
68+
testCase.assertTrue(isfile(f));
69+
70+
s = readstruct(f);
71+
72+
testCase.verifySize(s, [1 2]);
73+
74+
testCase.verifyFalse(s(1).failed);
75+
testCase.verifyFalse(s(1).skipped);
76+
77+
testCase.verifyTrue(s(2).failed);
78+
testCase.verifyFalse(s(2).skipped);
79+
end
80+
81+
function runningBuildCreatesSummaryForTaskGroups(testCase)
82+
plan = buildplan();
83+
plan("g:t") = Task();
84+
85+
testCase.Runner.run(plan, "g:t");
86+
87+
f = fullfile(testCase.TempFolder, "buildSummary.json");
88+
testCase.assertTrue(isfile(f));
89+
90+
s = readstruct(f);
91+
92+
testCase.verifySize(s, [1 1]);
93+
testCase.verifyEqual(s(1).name, "g:t");
94+
end
95+
end
96+
97+
end
98+
99+
function plugin = ParallelizableBuildSummaryPlugin(varargin)
100+
plugin = buildframework.ParallelizableBuildSummaryPlugin(varargin{:});
101+
end
102+
103+
function task = Task(varargin)
104+
task = matlab.buildtool.Task(varargin{:});
105+
end

0 commit comments

Comments
 (0)