Skip to content

Commit

Permalink
Bake test examples into the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mcafaro committed Oct 3, 2024
1 parent a2c2029 commit 30d78ee
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
- checkout
- matlab/install:
release: <<parameters.release>>
products: Optimization_Toolbox Curve_Fitting_Toolbox
- matlab/run-tests:
source-folder: code

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:

- name: Setup MATLAB
uses: matlab-actions/setup-matlab@v2
with:
release: ${{ matrix.release }}
products: Optimization_Toolbox Curve_Fitting_Toolbox

- name: Run tests and generate artifacts
uses: matlab-actions/run-tests@v2
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
- task: InstallMATLAB@1
inputs:
release: ${{ release }}
products: Optimization_Toolbox Curve_Fitting_Toolbox
- task: RunMATLABTests@1
inputs:
sourceFolder: code
Binary file added examples/curve_fitting_toolbox.mlx
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/disk.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function radsqr = disk(x)

radsqr = x(1)^2 + x(2)^2;
Binary file added examples/matlab.mlx
Binary file not shown.
Binary file added examples/optimization_toolbox.mlx
Binary file not shown.
24 changes: 14 additions & 10 deletions tinstall.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
'signal_blocks', 'curve_fitting_toolbox'}
restricted = {'rtw_embedded_coder', 'filter_design_hdl_coder', 'gpu_coder', ...
'simulink_hdl_coder', 'matlab_coder', 'real-time_workshop', 'simulink_plc_coder'}
example = {'matlab/intro', 'optim/SolveAConstrainedNonlinearProblemProblemBasedExample', ...
'curvefit/FitPolynomialExample', 'simulink_general/sldemo_bounceExample'}
example = {'matlab', 'optimization_toolbox', 'curve_fitting_toolbox'}
end

methods (Test)
Expand All @@ -25,15 +24,12 @@ function testFailToCheckoutRestrictedLicense(testCase, restricted)
end

function testRunExample(testCase, example)
meta = findExample(example);
testCase.assumeTrue(isfolder(fullfile(meta.componentDir, 'main')), 'Demo not available');

testCase.applyFixture(PathFixture(meta.componentDir));
testCase.assumeTrue(isInstalled(example), 'Product not installed');

startingFigs = findall(groot, 'Type','figure');
testCase.addTeardown(@() close(setdiff(findall(groot, 'Type','figure'), startingFigs)));

[log, ex] = evalc('runDemo(fullfile(meta.componentDir, ''main'', meta.main));');
[log, ex] = evalc('runExample(fullfile(''examples'',example));');
if ~isempty(ex)
disp(log);
rethrow(ex);
Expand All @@ -43,21 +39,29 @@ function testRunExample(testCase, example)

end

function ex = runDemo(demo) %#ok<DEFNU> evalc
function ex = runExample(example)
try
run(demo)
ex = MException.empty;
run(example)
ex = MException.empty;
catch ex
end
end

function tf = isInstalled(productName)
v = ver();
n = strrep(productName, '_', ' ');
tf = any(strcmpi(n, {v.Name}));
end

% imports
function c = IsTrue(varargin)
c = matlab.unittest.constraints.IsTrue(varargin{:});
end

function c = IsFalse(varargin)
c = matlab.unittest.constraints.IsFalse(varargin{:});
end

function c = PathFixture(varargin)
c = matlab.unittest.fixtures.PathFixture(varargin{:});
end

0 comments on commit 30d78ee

Please sign in to comment.