Skip to content

Commit

Permalink
Enable automation of MATLAB tests (#59)
Browse files Browse the repository at this point in the history
* Add usage of `matlab-actions/run-tests` to test automation

* Set up MATLAB prior to running tests in test action

* Move MATLAB testing to separate job

* Specify MATLAB version

* Checkout before MATLAB tests

* Resolve test failures

* Update assertion

* Temporarily update test action to run against all supported MATLAB versions

* Leverage `testCase.assumeTrue` to skip tests in certain environments

* Update tFormatCode `assumeTrue` condition

* Update tFormatCode isApplicable check to check Java Swing again

* Return isApplicable check to checking for the testing environment

* Fix message text
  • Loading branch information
dklilley authored Mar 11, 2025
1 parent 073aaa1 commit 4765aa2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ on:
workflow_dispatch:

jobs:
build-and-test:
typescript-build-and-test:
name: ${{ matrix.os }}-${{ matrix.node-version }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
node-version: [18.x, 20.x, 22.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
Expand All @@ -37,5 +38,25 @@ jobs:
run: npm ci
- name: Build
run: npm run compile
- name: Run Unit Tests
- name: Run TypeScript Unit Tests
run: npm test

matlab-test:
env:
MATLAB_TEST_ENVIRONMENT: 1
name: ${{ matrix.matlab-version }}-${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
matlab-version: [R2021b, R2022a, R2022b, R2023a, R2023b, R2024a, latest]
os: [windows-latest, ubuntu-latest, macos-13]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up MATLAB
uses: matlab-actions/[email protected]
with:
release: ${{ matrix.matlab-version }}
- name: Run MATLAB Unit Tests
uses: matlab-actions/[email protected]
Binary file modified matlab/+matlabls/+internal/computeCodeData.p
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/matlab/matlabls/handlers/folding/tGetFoldingRanges.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
% Copyright 2025 The MathWorks, Inc.
classdef tGetFoldingRanges < matlab.unittest.TestCase
methods (TestClassSetup)
function isApplicable (testCase)
% Determine if the test should be skipped in the current environment
testCase.assumeTrue(...
~isMATLABReleaseOlderThan('R2024b'),...
"Code folding only supported in R2024b and later.");
end

function setup (~)
% Add function under test to path
addpath("../../../../../matlab");
Expand Down
10 changes: 10 additions & 0 deletions tests/matlab/matlabls/handlers/formatting/tFormatCode.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
end

methods (TestClassSetup)
function isApplicable (testCase)
% Determine if the test should be skipped in the current environment
isTestingEnvironment = ~isempty(getenv('MATLAB_TEST_ENVIRONMENT'));
shouldRun = ~(isMATLABReleaseOlderThan('R2024b') && isTestingEnvironment);

testCase.assumeTrue(...
shouldRun,...
"Document formatting test cannot run prior to 24b in GitHub test environment.");
end

function setup (~)
% Add function under test to path
addpath("../../../../../matlab");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function testParsingScriptFile (testCase)
testCase.assertEqual(result.references, expectedReferences);

expectedSections = {
struct(title = "Create Data", range = toRange(3, 1, 6, 2)),...
struct(title = "Create Data", range = toRange(3, 1, 6, 1)),...
struct(title = "Plot", range = toRange(7, 1, 8, 11))
};

Expand Down
7 changes: 7 additions & 0 deletions tests/matlab/matlabls/handlers/linting/tGetSuppressionEdits.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
% Copyright 2025 The MathWorks, Inc.
classdef tGetSuppressionEdits < matlab.unittest.TestCase
methods (TestClassSetup)
function isApplicable (testCase)
% Determine if the test should be skipped in the current environment
testCase.assumeTrue(...
~isMATLABReleaseOlderThan('R2022a'),...
"Diagnostic suppression tests require R2022a and later.");
end

function setup (~)
% Add function under test to path
addpath("../../../../../matlab");
Expand Down

0 comments on commit 4765aa2

Please sign in to comment.