Skip to content

Commit 91f043e

Browse files
committed
Leverage testCase.assumeTrue to skip tests in certain environments
1 parent be462a3 commit 91f043e

File tree

4 files changed

+26
-59
lines changed

4 files changed

+26
-59
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ jobs:
4242
run: npm test
4343

4444
matlab-test:
45+
env:
46+
MATLAB_TEST_ENVIRONMENT: 1
4547
name: ${{ matrix.matlab-version }}-${{ matrix.os }}
4648
runs-on: ${{ matrix.os }}
4749
strategy:

tests/matlab/matlabls/handlers/folding/tGetFoldingRanges.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
% Copyright 2025 The MathWorks, Inc.
22
classdef tGetFoldingRanges < matlab.unittest.TestCase
33
methods (TestClassSetup)
4+
function isApplicable (testCase)
5+
% Determine if the test should be skipped in the current environment
6+
testCase.assumeTrue(...
7+
~isMATLABReleaseOlderThan('R2024b'),...
8+
"Code folding only supported in R2024b and later.");
9+
end
10+
411
function setup (~)
512
% Add function under test to path
613
addpath("../../../../../matlab");

tests/matlab/matlabls/handlers/formatting/tFormatCode.m

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
end
66

77
methods (TestClassSetup)
8+
function isApplicable (testCase)
9+
% Determine if the test should be skipped in the current environment
10+
isTestingEnvironment = ~isempty(getenv('MATLAB_TEST_ENVIRONMENT'));
11+
shouldRun = ~(isMATLABReleaseOlderThan('R2025a') && isTestingEnvironment);
12+
13+
testCase.assumeTrue(...
14+
shouldRun,...
15+
"Document formatting test cannot run prior to 25a in GitHub test environment.");
16+
end
17+
818
function setup (~)
919
% Add function under test to path
1020
addpath("../../../../../matlab");
@@ -15,12 +25,6 @@ function setup (~)
1525
% Test correct formatting with spaces when the tab size is 4.
1626
% Each indent should be represented by 4 spaces.
1727
function testFormatting4WithSpaces (testCase)
18-
if shouldSkipTest()
19-
disp('Skipping test due to environment limitations.');
20-
testCase.verifyTrue(true);
21-
return;
22-
end
23-
2428
options.insertSpaces = true;
2529
options.tabSize = 4;
2630

@@ -33,12 +37,6 @@ function testFormatting4WithSpaces (testCase)
3337
% Test correct formatting with tabs when the tab size is 4.
3438
% Each indent should be represented by 1 tab character.
3539
function testFormatting4WithTabs (testCase)
36-
if shouldSkipTest()
37-
disp('Skipping test due to environment limitations.');
38-
testCase.verifyTrue(true);
39-
return;
40-
end
41-
4240
options.insertSpaces = false;
4341
options.tabSize = 4;
4442

@@ -51,12 +49,6 @@ function testFormatting4WithTabs (testCase)
5149
% Test correct formatting with spaces when the tab size is 6.
5250
% Each indent should be represented by 6 spaces.
5351
function testFormatting6WithSpaces (testCase)
54-
if shouldSkipTest()
55-
disp('Skipping test due to environment limitations.');
56-
testCase.verifyTrue(true);
57-
return;
58-
end
59-
6052
options.insertSpaces = true;
6153
options.tabSize = 6;
6254

@@ -69,12 +61,6 @@ function testFormatting6WithSpaces (testCase)
6961
% Test correct formatting with tabs when the tab size is 6.
7062
% Each indent should be represented by 1 tab character.
7163
function testFormatting6WithTabs (testCase)
72-
if shouldSkipTest()
73-
disp('Skipping test due to environment limitations.');
74-
testCase.verifyTrue(true);
75-
return;
76-
end
77-
7864
options.insertSpaces = false;
7965
options.tabSize = 4;
8066

@@ -85,9 +71,3 @@ function testFormatting6WithTabs (testCase)
8571
end
8672
end
8773
end
88-
89-
function shouldSkip = shouldSkipTest ()
90-
% Before 25a, code formatting depends on Java logic, which may not be available
91-
% in the testing environment.
92-
shouldSkip = isMATLABReleaseOlderThan('R2025a') && ~isempty(javachk('swing'));
93-
end
Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
% Copyright 2025 The MathWorks, Inc.
22
classdef tGetSuppressionEdits < matlab.unittest.TestCase
33
methods (TestClassSetup)
4+
function isApplicable (testCase)
5+
% Determine if the test should be skipped in the current environment
6+
testCase.assumeTrue(...
7+
~isMATLABReleaseOlderThan('R2022a'),...
8+
"Diagnostic suppression tests require R2022a and later.");
9+
end
10+
411
function setup (~)
512
% Add function under test to path
613
addpath("../../../../../matlab");
@@ -10,12 +17,6 @@ function setup (~)
1017
methods (Test)
1118
% Test a basic case where a suppression should be placed on the same line
1219
function testBasicSuppression (testCase)
13-
if shouldSkipTest()
14-
disp('Skipping test on MATLAB version prior to R2022a.');
15-
testCase.verifyTrue(true);
16-
return;
17-
end
18-
1920
code = sprintf('if true\n x = 3;\nend');
2021
diagnosticId = 'testId';
2122
diagnosticLine = 2;
@@ -30,12 +31,6 @@ function testBasicSuppression (testCase)
3031

3132
% Test a basic case where a file-wide suppression should be placed on the same line
3233
function testBasicSuppressionInFile (testCase)
33-
if shouldSkipTest()
34-
disp('Skipping test on MATLAB version prior to R2022a.');
35-
testCase.verifyTrue(true);
36-
return;
37-
end
38-
3934
code = sprintf('if true\n x = 3;\nend');
4035
diagnosticId = 'testId';
4136
diagnosticLine = 2;
@@ -50,12 +45,6 @@ function testBasicSuppressionInFile (testCase)
5045

5146
% Test that suppression does not have preceding whitespace when there is trailing whitespace on line
5247
function testSuppressionWithTrailingSpace (testCase)
53-
if shouldSkipTest()
54-
disp('Skipping test on MATLAB version prior to R2022a.');
55-
testCase.verifyTrue(true);
56-
return;
57-
end
58-
5948
code = sprintf('if true\n x = 3; \nend');
6049
diagnosticId = 'testId';
6150
diagnosticLine = 2;
@@ -70,12 +59,6 @@ function testSuppressionWithTrailingSpace (testCase)
7059

7160
% Test a case where a suppression should be placed at the end of a multi-line statement
7261
function testSuppressionAfterMultilineStatement (testCase)
73-
if shouldSkipTest()
74-
disp('Skipping test on MATLAB version prior to R2022a.');
75-
testCase.verifyTrue(true);
76-
return;
77-
end
78-
7962
code = sprintf('if true\n x = 1 + ...\n 2 + ...\n 3;\nend');
8063
diagnosticId = 'testId';
8164
diagnosticLine = 2;
@@ -89,8 +72,3 @@ function testSuppressionAfterMultilineStatement (testCase)
8972
end
9073
end
9174
end
92-
93-
function shouldSkip = shouldSkipTest ()
94-
% Required APIs are not available prior to R2022a
95-
shouldSkip = isMATLABReleaseOlderThan('R2022a');
96-
end

0 commit comments

Comments
 (0)