Main Content

matlab.unittest.constraints.IssuesNoWarnings Class

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.

example

c = matlab.unittest.constraints.IssuesNoWarnings("WhenNargoutIs",numOutputs) 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.

example

Input Arguments

expand all

Number of outputs that the constraint requests when invoking the function handle, specified as a nonnegative integer scalar.

This argument sets the Nargout property.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Properties

expand all

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

collapse all

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)
Verification passed.

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)
Verification passed.

Inspect the outputs produced by the function handle in the previous test.

[out1,out2] = constraint.FunctionOutputs{:}
out1 =

     0


out2 =

     0

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:warning:id","Warning!"), ...
    IssuesNoWarnings)
Warning: Warning! 
> In @()warning("SOME:warning: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:warning:id"
                   Message: Warning!
    
    Evaluated Function:
      function_handle with value:
    
        @()warning("SOME:warning:id","Warning!")

Version History

Introduced in R2013a