Skip to content

Out Diff

viscalyxbot edited this page Aug 13, 2024 · 2 revisions

Out-Diff

SYNOPSIS

Compares two sets of strings and highlights the differences in hexadecimal output.

SYNTAX

Out-Diff [-Difference] <String[]> [-Reference] <String[]> [[-DifferenceAnsi] <String>] [[-AnsiReset] <String>]
 [[-DiffIndicator] <String>] [[-EqualIndicator] <String>] [-AsVerbose] [-NoHeader] [[-ReferenceLabel] <String>]
 [[-DifferenceLabel] <String>] [[-ReferenceLabelAnsi] <String>] [[-DifferenceLabelAnsi] <String>] [-PassThru]
 [<CommonParameters>]

DESCRIPTION

The Out-Diff command compares two sets of strings, $Difference and $Reference. Outputs the result using hexadecimal output and highlights the differences between the two sets of strings in a side-by-side format, making it easier to spot discrepancies at a byte level.

Its main intended use is in unit tests when comparing large text masses that can have small, normally invisible differences, such as an extra or missing line feed or new line character.

The command supports ANSI escape sequences for coloring the differences between the actual and expected strings. The default color for differences is red. The command defaults to outputting the result as informational messages, but it also supports displaying the differences using the Write-Verbose cmdlet or returning the result as output.

EXAMPLES

EXAMPLE 1

$actual = "Hello", "World"
$expected = "Hello", "Universe"
Out-Diff -Difference $actual -Reference $expected

This example compares the actual strings "Hello" and "World" with the expected strings "Hello" and "Universe". The function displays the differences between the two sets of strings.

PARAMETERS

-AnsiReset

Specifies the ANSI escape sequence to reset the formatting. The default value is '0m'.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 4
Default value: 0m
Accept pipeline input: False
Accept wildcard characters: False

-AsVerbose

Switch parameter. If specified, the differences are displayed using the Write-Verbose cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Difference

Specifies the set of strings to compare against the reference strings. This parameter is mandatory.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DifferenceAnsi

Specifies the ANSI escape sequence for controlling how the difference is highlighted. The default value is '30;31m' (red).

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: 30;31m
Accept pipeline input: False
Accept wildcard characters: False

-DifferenceLabel

Specifies the label for the difference strings. The default value is 'But was:'. The label should be no longer than 65 characters.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 8
Default value: But was:
Accept pipeline input: False
Accept wildcard characters: False

-DifferenceLabelAnsi

Specifies the ANSI escape sequence for controlling the look of the difference label. The default value is '4m' (underline).

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 10
Default value: 4m
Accept pipeline input: False
Accept wildcard characters: False

-DiffIndicator

Specifies the indicator to display when there is a differences between the strings. The default value is '!='.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: !=
Accept pipeline input: False
Accept wildcard characters: False

-EqualIndicator

Specifies the indicator to display when there is equality between the strings. The default value is '!='.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 6
Default value: ==
Accept pipeline input: False
Accept wildcard characters: False

-NoHeader

Switch parameter. If specified, the header message is not displayed.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-PassThru

Switch parameter. If specified, the output is returned as an array of strings.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-Reference

Specifies the set of reference strings to compare against the difference strings. This parameter is mandatory.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: True
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-ReferenceLabel

Specifies the label for the reference strings. The default value is 'Expected:'. The label should be no longer than 65 characters.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 7
Default value: Expected:
Accept pipeline input: False
Accept wildcard characters: False

-ReferenceLabelAnsi

Specifies the ANSI escape sequence for controlling the look of the reference label. The default value is '4m' (underline).

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 9
Default value: 4m
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

If the PassThru parameter is specified, the function returns an array of

strings representing the differences between the actual and expected strings.

NOTES

RELATED LINKS

Clone this wiki locally