Main Content

matlab.buildtool.TaskAction Class

Namespace: matlab.buildtool

Action performed when task runs

Since R2022b

Description

The matlab.buildtool.TaskAction class defines the code that executes when a task runs.

When you specify a task action using a function handle, MATLAB® automatically converts the function handle to a TaskAction object. You cannot create an object of the TaskAction class directly.

Class Attributes

Abstract
true

For information on class attributes, see Class Attributes.

Properties

expand all

Name of the action, returned as a string scalar. The build tool sets the property to the string representation of the action.

Attributes:

GetAccess
public
SetAccess
private

Examples

collapse all

Specify the actions to perform when a task runs.

In a file named runMyTests.m in your current folder, create a function that runs the tests in the current folder and its subfolders, generates an HTML test report from the test results, and asserts that the tests run without failure.

function runMyTests(~)
results = runtests(IncludeSubfolders=true,OutputDetail="terse");
generateHTMLReport(results,"artifacts")
assertSuccess(results);
end

Import the Task class.

import matlab.buildtool.Task

Create a plan with no tasks.

plan = buildplan;

Add a task to the plan that executes the runMyTests function.

plan("test") = Task(Actions=@runMyTests);

Add another action to the task to open the generated test report.

plan("test").Actions(end+1) = @(~)open(fullfile("artifacts","index.html"));

Display the names of the task actions. The build tool displays the string representation of the function handles.

disp({plan("test").Actions.Name}')
    {["runMyTests"                                  ]}
    {["@(~)open(fullfile("artifacts","index.html"))"]}

Now, run the task. The build runner performs the actions of the task in the order specified. In this example, all the tests pass and the report opens.

result = run(plan,"test");
** Starting test
...
Generating test report. Please wait.
    Preparing content for the test report.
    Adding content to the test report.
    Writing test report to file.
Test report has been saved to:
 C:\work\artifacts\index.html
** Finished test

Version History

Introduced in R2022b

expand all