Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input to run tests in parallel #23

Merged
merged 3 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Input | Description
`test-results-simulink-test` | (Optional) Path to export Simulink Test Manager results in MLDATX format. This input requires a Simulink Test license, and is supported in MATLAB R2019a and later.<br/>**Example:** `test-results/results.mldatx`
`code-coverage-cobertura` | (Optional) Path to write code coverage report in Cobertura XML format.<br/>**Example:** `code-coverage/coverage.xml`
`model-coverage-cobertura` | (Optional) Path to write model coverage report in Cobertura XML format. This input requires a Simulink Coverage™ license, and is supported in MATLAB R2018b and later.<br/>**Example:** `model-coverage/coverage.xml`
`use-parallel` | (Optional) Indicator to run tests in parallel, specified as false or true. This input requires a Parallel Computing Toolbox license, and might not be compatible with other options. If incompatible, testing occurs in serial regardless of the value for `use-parallel`.

## Notes
* In MATLAB R2019a and later, the **Run MATLAB Tests** action uses the `-batch` option to start MATLAB noninteractively. Preferences do not persist across different MATLAB sessions launched with the `-batch` option. To run code that requires the same preferences, use a single action.
Expand Down
7 changes: 6 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 The MathWorks, Inc.
# Copyright 2020-2022 The MathWorks, Inc.

name: Run MATLAB Tests
description: >-
Expand Down Expand Up @@ -44,6 +44,11 @@ inputs:
Path to write model coverage report in Cobertura XML format
required: false
default: ""
use-parallel:
description: >-
Indicator to run tests in parallel
required: false
default: false
runs:
using: node12
main: dist/index.js
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The MathWorks, Inc.
// Copyright 2020-2022 The MathWorks, Inc.

import * as core from "@actions/core";
import * as exec from "@actions/exec";
Expand All @@ -21,6 +21,7 @@ async function run() {
CoberturaModelCoverage: core.getInput("model-coverage-cobertura"),
SelectByTag: core.getInput("select-by-tag"),
SelectByFolder: core.getInput("select-by-folder"),
UseParallel: core.getBooleanInput("use-parallel"),
};

const command = scriptgen.generateCommand(options);
Expand Down
6 changes: 4 additions & 2 deletions src/scriptgen.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The MathWorks, Inc.
// Copyright 2020-2022 The MathWorks, Inc.

import * as path from "path";

Expand All @@ -15,6 +15,7 @@ export interface RunTestsOptions {
CoberturaModelCoverage?: string;
SelectByTag?: string;
SelectByFolder?: string;
UseParallel?: boolean;
}

/**
Expand All @@ -33,7 +34,8 @@ export function generateCommand(options: RunTestsOptions): string {
'SimulinkTestResults','${options.SimulinkTestResults || ""}',
'CoberturaModelCoverage','${options.CoberturaModelCoverage || ""}',
'SelectByTag','${options.SelectByTag || ""}',
'SelectByFolder','${options.SelectByFolder || ""}'
'SelectByFolder','${options.SelectByFolder || ""}',
'UseParallel',${options.UseParallel || false}
);
disp('Running MATLAB script with contents:');
disp(testScript.Contents);
Expand Down
11 changes: 8 additions & 3 deletions src/scriptgen.unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020 The MathWorks, Inc.
// Copyright 2020-2022 The MathWorks, Inc.

import * as scriptgen from "./scriptgen";

Expand All @@ -13,6 +13,7 @@ describe("command generation", () => {
CoberturaModelCoverage: "",
SelectByTag: "",
SelectByFolder: "",
UseParallel: false,
};

const actual = scriptgen.generateCommand(options);
Expand All @@ -26,10 +27,12 @@ describe("command generation", () => {
expect(actual.includes("'CoberturaModelCoverage',''")).toBeTruthy();
expect(actual.includes("'SelectByTag',''")).toBeTruthy();
expect(actual.includes("'SelectByFolder',''")).toBeTruthy();
expect(actual.includes("'UseParallel',false")).toBeTruthy();

const expected = `genscript('Test', 'JUnitTestResults','', 'CoberturaCodeCoverage','',
'SourceFolder','', 'PDFTestReport','', 'SimulinkTestResults','',
'CoberturaModelCoverage','', 'SelectByTag','', 'SelectByFolder','' )`.replace(/\s+/g, "");
'CoberturaModelCoverage','', 'SelectByTag','', 'SelectByFolder','',
'UseParallel',false )`.replace(/\s+/g, "");
expect(actual.replace(/\s+/g, "").includes(expected)).toBeTruthy();
});

Expand All @@ -43,6 +46,7 @@ describe("command generation", () => {
CoberturaModelCoverage: "test-results/modelcoverage.xml",
SelectByTag: "FeatureA",
SelectByFolder: "test/tools;test/toolbox",
UseParallel: true,
};

const actual = scriptgen.generateCommand(options);
Expand All @@ -62,12 +66,13 @@ describe("command generation", () => {
).toBeTruthy();
expect(actual.includes("'SelectByTag','FeatureA'")).toBeTruthy();
expect(actual.includes("'SelectByFolder','test/tools;test/toolbox'")).toBeTruthy();
expect(actual.includes("'UseParallel',true")).toBeTruthy();

const expected = `genscript('Test', 'JUnitTestResults','test-results/results.xml',
'CoberturaCodeCoverage','code-coverage/coverage.xml', 'SourceFolder','source',
'PDFTestReport','test-results/pdf-results.pdf', 'SimulinkTestResults','test-results/simulinkTest.mldatx',
'CoberturaModelCoverage','test-results/modelcoverage.xml', 'SelectByTag','FeatureA',
'SelectByFolder','test/tools;test/toolbox' )`.replace(/\s+/g, "");
'SelectByFolder','test/tools;test/toolbox', 'UseParallel',true )`.replace(/\s+/g, "");
expect(actual.replace(/\s+/g, "").includes(expected)).toBeTruthy();
});
});