-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuildfile.m
More file actions
97 lines (80 loc) · 2.69 KB
/
Copy pathbuildfile.m
File metadata and controls
97 lines (80 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function plan = buildfile
% BUILDFILE Build configuration for uniform-spherical-sampling project.
%
% Tasks:
% clean - Delete generated reports and badges
% check - Run static code analysis on src and tests
% test - Run unit tests with coverage
%
% Usage:
% >> buildtool % Runs default tasks: check, test
% >> buildtool clean
% >> buildtool check
% >> buildtool test
% Set up paths (project file isn't opened in CI for older matlab versions)
root = fileparts(mfilename("fullpath"));
addpath(genpath(fullfile(root, "src")));
addpath(genpath(fullfile(root, "lib")));
addpath(fullfile(root, "buildUtilities"));
% Auto-discover task functions
plan = buildplan(localfunctions);
% Configure dependencies and defaults
plan("test").Dependencies = "check";
plan.DefaultTasks = ["check", "test"];
end
%% Tasks
function cleanTask(~)
% Delete reports and badges
if exist("reports/badge", "dir")
delete("reports/badge/*.json");
end
if exist("reports", "dir")
delete("reports/*.xml");
end
end
function checkTask(~)
% Run static analysis on src and tests
results = codeIssues(["src", "tests"]);
issues = results.Issues;
% Display issues if any
if ~isempty(issues)
disp(issues);
end
% Generate badge (JSON format for shields.io)
generateCodeIssuesBadge(issues);
end
function testTask(~)
% Run unit tests with coverage
import matlab.unittest.TestRunner
import matlab.unittest.plugins.CodeCoveragePlugin
import matlab.unittest.plugins.XMLPlugin
import matlab.unittest.plugins.codecoverage.CoberturaFormat
suite = testsuite("tests", "IncludeSubfolders", true);
runner = TestRunner.withTextOutput;
% Create output directories
if ~exist("reports", "dir")
mkdir("reports");
end
if ~exist("reports/badge", "dir")
mkdir("reports/badge");
end
% Add JUnit XML plugin for CI
runner.addPlugin(XMLPlugin.producingJUnitFormat("reports/test-results.xml"));
% Get all .m files in src for coverage
srcFiles = dir(fullfile("src", "**", "*.m"));
srcFiles = arrayfun(@(f) fullfile(f.folder, f.name), srcFiles, UniformOutput=false);
srcFiles = string(srcFiles);
coverageFile = "reports/coverage.xml";
if ~isempty(srcFiles)
runner.addPlugin(CodeCoveragePlugin.forFile(srcFiles, ...
"Producing", CoberturaFormat(coverageFile)));
end
% Run tests
result = runner.run(suite);
% Generate coverage badge (JSON format for shields.io)
if exist(coverageFile, "file")
generateCoverageBadge(coverageFile);
end
% Fail the build if tests failed
assertSuccess(result);
end