Skip to content

Commit 082ed32

Browse files
VahilaVahila Kayithimw-hrastega
authored
Add SelectByName parameter (#148)
* Add SeectByName parameter * Remove comment * Update the test * Update the version * Send {} when empty selectByName value * Update scriptgen.ts * Update failing test * Update failing test * Update failing test * test fix * Update test * Update test * Update file * Update file * Update file * Update file * Update failing test * Update failing test * Updated file * Update file * Update file * Update file * Update file * Update file * Update file * Update file * Update file * Update file * Update file * Update file * Document the `selectByName` input --------- Co-authored-by: Vahila Kayithi <[email protected]> Co-authored-by: mw-hrastega <[email protected]>
1 parent d503642 commit 082ed32

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

integ-test-promote-template.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,24 @@ jobs:
266266
testResultsJUnit: test-results/matlab/selectbyfolder.xml
267267
selectByFolder: tests/filteredTest
268268
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABTests.RunMATLABTests@${{ version }}
269-
displayName: Run MATLAB tests filter by folder
269+
displayName: Run MATLAB tests filter by tag
270270
inputs:
271271
testResultsJUnit: test-results/matlab/selectbytag.xml
272272
selectByTag: FILTERED
273+
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABTests.RunMATLABTests@${{ version }}
274+
displayName: Run MATLAB tests filter by name
275+
inputs:
276+
testResultsJUnit: test-results/matlab/selectbyname.xml
277+
selectByName: "filtertest/* mytest/StartupTest"
278+
sourceFolder: src
279+
condition: not(eq(${{ version }}, '0'))
280+
- task: MathWorks.matlab-azure-devops-extension-dev.RunMATLABTests.RunMATLABTests@${{ version }}
281+
displayName: Run MATLAB tests filter by name with multiple spaces
282+
inputs:
283+
testResultsJUnit: test-results/matlab/selectbynamewithmultiplespaces.xml
284+
selectByName: "filtertest/* mytest/StartupTest"
285+
sourceFolder: src
286+
condition: not(eq(${{ version }}, '0'))
273287
- bash: |
274288
set -e
275289
grep -q FirstTest test-results/matlab/results.xml
@@ -301,6 +315,20 @@ jobs:
301315
grep -v FirstTest test-results/matlab/selectbytag.xml
302316
grep -v simpleTest test-results/matlab/selectbytag.xml
303317
displayName: Verify test filtered by tag name
318+
- bash: |
319+
set -e
320+
grep -q StartupTest test-results/matlab/selectbyname.xml
321+
grep -q simpleTest test-results/matlab/selectbyname.xml
322+
! grep -q FirstTest test-results/matlab/selectbyname.xml
323+
displayName: Verify test filtered by name
324+
condition: not(eq(${{ version }}, '0'))
325+
- bash: |
326+
set -e
327+
grep -q StartupTest test-results/matlab/selectbynamewithmultiplespaces.xml
328+
grep -q simpleTest test-results/matlab/selectbynamewithmultiplespaces.xml
329+
! grep -q FirstTest test-results/matlab/selectbynamewithmultiplespaces.xml
330+
displayName: Verify test filtered by name with multiple spaces
331+
condition: not(eq(${{ version }}, '0'))
304332
- bash: |
305333
echo 'diary console.log' >> startup.m
306334
displayName: Set up diary for logging

overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Input | Description
228228
------------------------- | ---------------
229229
`sourceFolder` | <p>(Optional) Location of the folder containing source code, specified as a path relative to the project root folder. The specified folder and its subfolders are added to the top of the MATLAB search path. If you specify `sourceFolder` and then generate a coverage report, the task uses only the source code in the specified folder and its subfolders to generate the report. You can specify multiple folders using a colon-separated or semicolon-separated list.</p><p>**Example:** `sourceFolder: source`<br/>**Example:** `sourceFolder: source/folderA; source/folderB`</p>
230230
`selectByFolder` | <p>(Optional) Location of the folder used to select test suite elements, specified as a path relative to the project root folder. To create a test suite, the task uses only the tests in the specified folder and its subfolders. You can specify multiple folders using a colon-separated or semicolon-separated list.</p><p>**Example:** `selectByFolder: test`<br/>**Example:** `selectByFolder: test/folderA; test/folderB`</p>
231+
`selectBynName` | <p>(Optional) Names of the tests to run, specified as a list of test names separated by spaces. If you specify this input, the task runs only the tests with the specified names. You can use the wildcard character (`*`) to match any number of characters and the question mark character (`?`) to match a single character. For example, specify `selectByName: ExampleTest/*` to select all the tests whose name starts with `ExampleTest/`.</p><p>For a given test file, the name of a test uniquely identifies the smallest runnable portion of the test content. The test name includes the namespace name, filename (excluding the extension), procedure name, and information about parameterization.</p><p>**Example:** `selectByName: ExampleTest/testA`<br/>**Example:** `selectByName: ExampleTest/testA ExampleTest/testB(array=3x3_double)`</p>
231232
`selectByTag` | <p>(Optional) Test tag used to select test suite elements. To create a test suite, the task uses only the test elements with the specified tag.</p><p>**Example:** `selectByTag: Unit`</p>
232233
`strict` | <p>(Optional) Option to apply strict checks when running tests, specified as `false` or `true`. By default, the value is `false`. If you specify a value of `true`, the task generates a qualification failure whenever a test issues a warning.</p><p>**Example:** `strict: true`</p>
233234
`useParallel` | <p>(Optional) Option to run tests in parallel, specified as `false` or `true`. By default, the value is `false` and tests run in serial. If the test runner configuration is suited for parallelization, you can specify a value of `true` to run tests in parallel. This input requires a Parallel Computing Toolbox license.</p><p>**Example:** `useParallel: true`</p>

tasks/run-matlab-tests/v1/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ async function run() {
1515
SourceFolder: taskLib.getInput("sourceFolder"),
1616
SelectByFolder: taskLib.getInput("selectByFolder"),
1717
SelectByTag: taskLib.getInput("selectByTag"),
18+
SelectByName: taskLib.getInput("selectByName"),
1819
CoberturaModelCoverage: taskLib.getInput("modelCoverageCobertura"),
1920
HTMLModelCoverage: taskLib.getInput("modelCoverageHTML"),
2021
SimulinkTestResults: taskLib.getInput("testResultsSimulinkTest"),

tasks/run-matlab-tests/v1/scriptgen.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@ export interface IRunTestsOptions {
1414
HTMLModelCoverage?: string;
1515
SelectByTag?: string;
1616
SelectByFolder?: string;
17+
SelectByName?: string;
1718
Strict?: boolean;
1819
UseParallel?: boolean;
1920
OutputDetail?: string;
2021
LoggingLevel?: string;
2122
}
2223

24+
// Function to convert space separated names to cell array of character vectors
25+
export function getSelectByNameAsCellArray(input?: string): string {
26+
if (!input || !input.trim()) {
27+
return "{}";
28+
}
29+
const items = input.split(/\s+/).filter(Boolean).map((s) => `\'${s}\'`);
30+
return `\{${items.join(", ")}\}`;
31+
}
32+
2333
export function generateCommand(options: IRunTestsOptions): string {
2434
return `addpath('${path.join(__dirname, "scriptgen")}');` +
2535
`testScript = genscript('Test',` +
@@ -34,6 +44,7 @@ export function generateCommand(options: IRunTestsOptions): string {
3444
`'HTMLModelCoverage','${options.HTMLModelCoverage || ""}',` +
3545
`'SelectByTag','${options.SelectByTag || ""}',` +
3646
`'SelectByFolder','${options.SelectByFolder || ""}',` +
47+
`'SelectByName',${getSelectByNameAsCellArray(options.SelectByName)},` +
3748
`'Strict',${options.Strict || false},` +
3849
`'UseParallel',${options.UseParallel || false},` +
3950
`'OutputDetail','${options.OutputDetail || ""}',` +

tasks/run-matlab-tests/v1/task.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@
5757
"required": false,
5858
"helpMarkDown": "Test tag used to select test suite elements. To create a test suite, the task uses only the test elements with the specified tag."
5959
},
60+
{
61+
"name": "selectByName",
62+
"type": "string",
63+
"label": "By name",
64+
"defaultValue": "",
65+
"groupName": "filterTests",
66+
"required": false,
67+
"helpMarkDown": "Test name used to select test suite elements. To create a test suite, the task uses only the test elements that match the specified name."
68+
},
6069
{
6170
"name": "strict",
6271
"type": "boolean",

tasks/run-matlab-tests/v1/test/scriptgen.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export default function suite() {
1818
HTMLModelCoverage: "",
1919
SelectByTag: "",
2020
SelectByFolder: "",
21+
SelectByName: "",
2122
Strict: false,
2223
UseParallel: false,
2324
OutputDetail: "",
@@ -38,14 +39,15 @@ export default function suite() {
3839
assert(actual.includes("'HTMLModelCoverage',''"));
3940
assert(actual.includes("'SelectByTag',''"));
4041
assert(actual.includes("'SelectByFolder',''"));
42+
assert(actual.includes("'SelectByName',{}"));
4143
assert(actual.includes("'Strict',false"));
4244
assert(actual.includes("'UseParallel',false"));
4345
assert(actual.includes("'OutputDetail',''"));
4446
assert(actual.includes("'LoggingLevel',''"));
4547

4648
const expected = `genscript('Test', 'JUnitTestResults','', 'CoberturaCodeCoverage','','HTMLCodeCoverage','',
4749
'SourceFolder','', 'PDFTestReport','', 'HTMLTestReport','', 'SimulinkTestResults','',
48-
'CoberturaModelCoverage','', 'HTMLModelCoverage','', 'SelectByTag','', 'SelectByFolder','',
50+
'CoberturaModelCoverage','', 'HTMLModelCoverage','', 'SelectByTag','', 'SelectByFolder','', 'SelectByName',{},
4951
'Strict',false, 'UseParallel',false, 'OutputDetail','', 'LoggingLevel','')`
5052
.replace(/\s+/g, "");
5153
assert(actual.replace(/\s+/g, "").includes(expected));
@@ -64,6 +66,7 @@ export default function suite() {
6466
HTMLModelCoverage: "test-results/modelcoverageHTML",
6567
SelectByTag: "FeatureA",
6668
SelectByFolder: "test/tools;test/toolbox",
69+
SelectByName: "tTestA/* tTestB/*",
6770
Strict: true,
6871
UseParallel: true,
6972
OutputDetail: "Detailed",
@@ -84,6 +87,7 @@ export default function suite() {
8487
assert(actual.includes("'HTMLModelCoverage','test-results/modelcoverageHTML'"));
8588
assert(actual.includes("'SelectByTag','FeatureA'"));
8689
assert(actual.includes("'SelectByFolder','test/tools;test/toolbox'"));
90+
assert(actual.includes("'SelectByName',{'tTestA/*', 'tTestB/*'}"));
8791
assert(actual.includes("'Strict',true"));
8892
assert(actual.includes("'UseParallel',true"));
8993
assert(actual.includes("'OutputDetail','Detailed'"));
@@ -93,7 +97,7 @@ export default function suite() {
9397
'CoberturaCodeCoverage','code-coverage/coverage.xml','HTMLCodeCoverage','code-coverage/coverageHTML', 'SourceFolder','source',
9498
'PDFTestReport','test-results/pdf-results.pdf', 'HTMLTestReport','test-results/html-resultsHTML', 'SimulinkTestResults','test-results/simulinkTest.mldatx',
9599
'CoberturaModelCoverage','test-results/modelcoverage.xml', 'HTMLModelCoverage','test-results/modelcoverageHTML', 'SelectByTag','FeatureA',
96-
'SelectByFolder','test/tools;test/toolbox', 'Strict',true, 'UseParallel',true, 'OutputDetail','Detailed',
100+
'SelectByFolder','test/tools;test/toolbox', 'SelectByName',{'tTestA/*', 'tTestB/*'}, 'Strict',true, 'UseParallel',true, 'OutputDetail','Detailed',
97101
'LoggingLevel','Detailed' )`
98102
.replace(/\s+/g, "");
99103
assert(actual.replace(/\s+/g, "").includes(expected));

0 commit comments

Comments
 (0)