matlab.unittest.constraints.IssuesNoWarnings - Test if function issues no warnings - MATLAB (original) (raw)
Main Content
Namespace: matlab.unittest.constraints
Superclasses: matlab.unittest.constraints.Constraint
Test if function issues no warnings
Description
The matlab.unittest.constraints.IssuesNoWarnings
class provides a constraint to test if a function handle issues no warnings.
The matlab.unittest.constraints.IssuesNoWarnings
class is a handle class.
Creation
Description
c = matlab.unittest.constraints.IssuesNoWarnings
creates a constraint to test if a function handle issues no warnings. The constraint is satisfied if the actual value is a function handle that issues no warnings when the testing framework invokes it.
c = matlab.unittest.constraints.IssuesNoWarnings("WhenNargoutIs",[numOutputs](#mw%5F77611bff-16f1-4e9d-8313-bcc9c37e2c7e))
also specifies the number of outputs to request from the function handle. When you use this syntax, the constraint is satisfied if the function handle produces the specified number of outputs without issuing any warnings.
Input Arguments
Number of outputs that the constraint requests when invoking the function handle, specified as a nonnegative integer scalar.
This argument sets the [Nargout](matlab.unittest.constraints.issuesnowarnings-class.html#mw%5Fc88c17ec-8124-4422-a6d2-bebe71684332)
property.
Data Types: double
| single
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Properties
Outputs produced by the function handle when the testing framework invokes it, returned as a cell array. The number of cell array elements is the same as numOutputs.
Attributes:
GetAccess | public |
---|---|
SetAccess | private |
Number of outputs that the constraint requests when invoking the function handle, returned as a nonnegative integer scalar.
This property is set by the numOutputs input argument.
Attributes:
GetAccess | public |
---|---|
SetAccess | private |
Examples
Test if the actual value is a function handle that issues no warnings.
First, import the classes used in this example.
import matlab.unittest.TestCase import matlab.unittest.constraints.IssuesNoWarnings
Create a test case for interactive testing.
testCase = TestCase.forInteractiveUse;
Verify that a call to the true
function does not result in any warnings.
testCase.verifyThat(@true,IssuesNoWarnings)
Verify that requesting two outputs from the size
function when it is passed an empty array does not result in any warnings.
constraint = IssuesNoWarnings("WhenNargoutIs",2); testCase.verifyThat(@() size([]),constraint)
Inspect the outputs produced by the function handle in the previous test.
[out1,out2] = constraint.FunctionOutputs{:}
Verify that the IssuesNoWarnings
constraint is not satisfied if the actual value is not a function handle.
testCase.verifyThat(5,IssuesNoWarnings)
Verification failed. --------------------- Framework Diagnostic: --------------------- IssuesNoWarnings failed. --> The value must be an instance of the expected type.
Actual Class:
double
Expected Type:
function_handle
Actual Value:
5
Test if the constraint is satisfied if the actual value issues a warning. The test fails.
testCase.verifyThat(@() warning("SOME⚠️id","Warning!"), ... IssuesNoWarnings)
Warning: Warning!
In @()warning("SOME⚠️id","Warning!") In matlab.unittest.internal.constraints/FunctionHandleConstraint/invoke (line 35) In matlab.unittest.internal.constraints/WarningQualificationConstraint/invoke (line 43) In matlab.unittest.constraints/IssuesNoWarnings/issuesNoWarnings (line 141) In matlab.unittest.constraints/IssuesNoWarnings/satisfiedBy (line 84) Verification failed. --------------------- Framework Diagnostic: --------------------- IssuesNoWarnings failed. --> The function issued warnings.
Warnings Issued:
--> Identifier: "SOME⚠️id"
Message: Warning!
Evaluated Function:
function_handle with value:
@()warning("SOME⚠️id","Warning!")
Version History
Introduced in R2013a