Skip to content
v2.275.0

MatchResult Class ​

The result of Match.test().

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { assertions } from 'aws-cdk-lib';

declare const target: any;
const matchResult = new assertions.MatchResult(target);
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import assertions

# target: Any

match_result = assertions.MatchResult(target)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.assertions.*;

Object target;

MatchResult matchResult = new MatchResult(target);
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.Assertions;

var target;

var matchResult = new MatchResult(target);
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"

var target interface{}

matchResult := awscdk.Assertions.NewMatchResult(target)

Initializer ​

ts
new MatchResult(target: any)
python
MatchResult(target: Any)
java
new MatchResult(Object target)
csharp
new MatchResult(object target)
go
NewMatchResult(Target interface{})

Properties ​

failCostnumberfail_costint | floatfailCostNumberFailCostdoubleFailCost*float64#
The cost of the failures so far.
failCountnumberfail_countint | floatfailCountNumberFailCountdoubleFailCount*float64#
The number of failures.
isSuccessbooleanis_successboolisSuccessBooleanIsSuccessboolIsSuccess*bool#
Whether the match is a success.
targetanytargetAnytargetObjectTargetobjectTargetinterface{}#
The target for which this result was generated.

Methods ​

compose(id: string, inner: MatchResult): MatchResult // chainabledef compose(self, id: str, inner: MatchResult) -> MatchResultpublic MatchResult compose(String id, MatchResult inner)public MatchResult Compose(string id, MatchResult inner)func Compose(Id *string, Inner MatchResult) MatchResult#
Compose the results of a previous match as a subtree.
1 parameter

Parameters

  • ididididId — the id of the parent tree.
finished(): MatchResult // chainabledef finished(self, ) -> MatchResultpublic MatchResult finished()public MatchResult Finished()func Finished() MatchResult#
Prepare the result to be analyzed.

This API must be called prior to analyzing these results.

hasFailed(): booleandef has_failed(self, ) -> boolpublic Boolean hasFailed()public bool HasFailed()func HasFailed() *bool#
Does the result contain any failures.

If not, the result is a success

push(matcher: Matcher, path: string[], message: string): MatchResult // chainabledef push(self, matcher: Matcher, path: typing.List[str], message: str) -> MatchResultpublic MatchResult push(Matcher matcher, List<String> path, String message)public MatchResult Push(Matcher matcher, string[] path, string message)func Push(Matcher Matcher, Path *[]*string, Message *string) MatchResultdeprecated#
use recordFailure()
recordCapture(options: MatchCapture): voiddef record_capture(self, options: MatchCapture) -> Nonepublic void recordCapture(MatchCapture options)public void RecordCapture(MatchCapture options)func RecordCapture(Options MatchCapture)#
Record a capture against in this match result.
recordFailure(failure: MatchFailure): MatchResult // chainabledef record_failure(self, failure: MatchFailure) -> MatchResultpublic MatchResult recordFailure(MatchFailure failure)public MatchResult RecordFailure(MatchFailure failure)func RecordFailure(Failure MatchFailure) MatchResult#
Record a new failure into this result at a specific path.
renderMismatch(): stringdef render_mismatch(self, ) -> strpublic String renderMismatch()public string RenderMismatch()func RenderMismatch() *string#
Do a deep render of the match result, showing the structure mismatches in context.
toHumanStrings(): string[]def to_human_strings(self, ) -> typing.List[str]public List<String> toHumanStrings()public string[] ToHumanStrings()func ToHumanStrings() *[]*string#
Render the failed match in a presentable way.

Prefer using renderMismatch over this method. It is left for backwards compatibility for test suites that expect it, but renderMismatch() will produce better output.