# MatchResult

The result of `Match.test()`.

Used as argument in: MatchResult.compose
Returned by: MatchResult.compose, MatchResult.finished, MatchResult.push, MatchResult.recordFailure, Matcher.test

- Source: [`matching/lib/matcher.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/matching/lib/matcher.ts#L77)
- Type last changed: v2.58.0 · 29 Dec 2022

## Example

TypeScript:

```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:

```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:

```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);
```

C# / .NET:

```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);
```

Golang:

```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

TypeScript:

```ts
new MatchResult(target: any)
```

Python:

```python
MatchResult(target: Any)
```

Java:

```java
new MatchResult(Object target)
```

C# / .NET:

```csharp
new MatchResult(object target)
```

Golang:

```go
NewMatchResult(Target interface{})
```

## Properties

- `failCost`: number — The cost of the failures so far.

- `failCount`: number — The number of failures.

- `isSuccess`: boolean — Whether the match is a success.

- `target`: any — The target for which this result was generated.

## Methods

- `compose(id: string, inner: MatchResult): MatchResult // chainable` — Compose the results of a previous match as a subtree.

  **Parameters**

  - `id` — the id of the parent tree.

- `finished(): MatchResult // chainable` — Prepare the result to be analyzed.

  This API *must* be called prior to analyzing these results.

- `hasFailed(): boolean` — Does the result contain any failures.

  If not, the result is a success

- `push(matcher: Matcher, path: string[], message: string): MatchResult // chainable` — use recordFailure()

- `recordCapture(options: MatchCapture): void` — Record a capture against in this match result.

- `recordFailure(failure: MatchFailure): MatchResult // chainable` — Record a new failure into this result at a specific path.

- `renderMismatch(): string` — Do a deep render of the match result, showing the structure mismatches in context.

- `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.
