-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConformance.Tests.ps1
More file actions
178 lines (162 loc) · 7.83 KB
/
Copy pathConformance.Tests.ps1
File metadata and controls
178 lines (162 loc) · 7.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '6.0.0'; MaximumVersion = '6.*' }
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSReviewUnusedParameter', '',
Justification = 'Required for Pester tests'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseDeclaredVarsMoreThanAssignments', '',
Justification = 'Required for Pester tests'
)]
[CmdletBinding()]
param()
BeforeAll {
$archivePath = Join-Path $PSScriptRoot 'fixtures\yaml-test-suite\yaml-test-suite-data-2022-01-17.zip'
$sourcesPath = Join-Path $PSScriptRoot 'fixtures\yaml-test-suite\SOURCES.txt'
$repositoryRoot = Split-Path -Parent $PSScriptRoot
$suitePath = Join-Path $TestDrive 'yaml-test-suite'
. (Join-Path $PSScriptRoot 'TestBootstrap.ps1')
$conformanceYamlModule = $yamlModule
Expand-Archive -LiteralPath $archivePath -DestinationPath $suitePath
$suiteRoots = @(
Get-ChildItem -LiteralPath $suitePath -Directory
)
if ($suiteRoots.Count -ne 1) {
throw "Expected one release archive root, but found $($suiteRoots.Count)."
}
$suiteDataPath = $suiteRoots[0].FullName
$suiteResults = @(
& (Join-Path $PSScriptRoot 'tools\Invoke-YamlTestSuite.ps1') `
-Path $suiteDataPath `
-CompareJson `
-CompareEvents `
-CompareOutYaml `
-CompareEmitRoundTrip
)
}
Describe 'Released yaml-test-suite corpus accounting' {
It 'uses the built module for conformance in GitHub Actions' {
if ($env:GITHUB_ACTIONS -eq 'true') {
$conformanceYamlModule | Should -Not -BeNullOrEmpty
$command = Get-Command -Name ConvertFrom-Yaml
$command.Module | Should -Be $conformanceYamlModule
$conformanceYamlModule.ModuleBase |
Should -Not -Be (Join-Path $repositoryRoot 'src')
$conformanceYamlModule.PowerShellVersion | Should -Be '7.6'
@($conformanceYamlModule.CompatiblePSEditions) | Should -Be @('Core')
}
}
It 'uses the pinned unmodified release archive' {
(Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash |
Should -Be '47C173AFFEB480517B30FB77DC8C76FD48609B9B65DD1C1D3D0D0BAEE48D6AA9'
$suiteResults.Count | Should -Be 402
}
It 'pins the latest official source and data release attribution' {
$sources = Get-Content -LiteralPath $sourcesPath -Raw
$sources | Should -Match 'Latest source release:\s+v2022-01-17'
$sources | Should -Match '45db50aecf9b1520f8258938c88f396e96f30831'
$sources | Should -Match '6e6c296ae9c9d2d5c4134b4b64d01b29ac19ff6f'
}
It 'accounts for syntax recognition and representation-key load policy' {
@($suiteResults | Where-Object SyntaxResult -EQ 'Pass').Count | Should -Be 400
@($suiteResults | Where-Object SyntaxResult -EQ 'PolicyDifference').Count |
Should -Be 2
@($suiteResults | Where-Object SyntaxResult -EQ 'Fail').Count | Should -Be 0
@($suiteResults | Where-Object SyntaxResult -EQ 'NotApplicable').Count |
Should -Be 0
$policyResults = @(
$suiteResults |
Where-Object SyntaxResult -EQ 'PolicyDifference' |
Sort-Object Case
)
@($policyResults.Case) | Should -Be @('2JQS', 'X38W')
@($policyResults.SyntaxReason | Select-Object -Unique) |
Should -Be @('RepresentationMappingKeyUniqueness')
@($policyResults | Where-Object EventResult -NE 'Pass').Count | Should -Be 0
}
It 'accounts for parser representation/event comparisons' {
@($suiteResults | Where-Object EventResult -EQ 'Pass').Count | Should -Be 308
@($suiteResults | Where-Object EventResult -EQ 'PolicyDifference').Count |
Should -Be 0
@($suiteResults | Where-Object EventResult -EQ 'Fail').Count | Should -Be 0
@($suiteResults | Where-Object EventResult -EQ 'NotApplicable').Count |
Should -Be 94
}
It 'accounts for JSON construction comparisons' {
@($suiteResults | Where-Object JsonResult -EQ 'Pass').Count | Should -Be 277
@($suiteResults | Where-Object JsonResult -EQ 'PolicyDifference').Count |
Should -Be 2
@($suiteResults | Where-Object JsonResult -EQ 'Fail').Count | Should -Be 0
@($suiteResults | Where-Object JsonResult -EQ 'NotApplicable').Count |
Should -Be 123
$policyResults = @(
$suiteResults |
Where-Object JsonResult -EQ 'PolicyDifference' |
Sort-Object Case
)
@($policyResults.Case) | Should -Be @('565N', 'J7PZ')
@($policyResults.JsonReason) | Should -Be @(
'BinaryByteArrayProjection',
'LegacyOrderedMapProjection'
)
}
It 'does not mask altered JSON values as projection policy' {
$mutatedSuitePath = Join-Path $TestDrive 'mutated-policy-cases'
$null = New-Item -Path $mutatedSuitePath -ItemType Directory -Force
foreach ($case in @('565N', 'J7PZ')) {
Copy-Item -LiteralPath (Join-Path $suiteDataPath $case) `
-Destination $mutatedSuitePath -Recurse
}
$binaryJsonPath = Join-Path $mutatedSuitePath '565N\in.json'
$binaryJson = Get-Content -LiteralPath $binaryJsonPath -Raw |
ConvertFrom-Json -AsHashtable
$binaryJson['description'] = 'Altered expected value'
$binaryJson | ConvertTo-Json -Depth 10 |
Set-Content -LiteralPath $binaryJsonPath -Encoding utf8NoBOM
$orderedMapJsonPath = Join-Path $mutatedSuitePath 'J7PZ\in.json'
$orderedMapJson = Get-Content -LiteralPath $orderedMapJsonPath -Raw |
ConvertFrom-Json -AsHashtable
$orderedMapJson[0]['Mark McGwire'] = 66
$orderedMapJson | ConvertTo-Json -Depth 10 |
Set-Content -LiteralPath $orderedMapJsonPath -Encoding utf8NoBOM
$mutatedResults = @(
& (Join-Path $PSScriptRoot 'tools\Invoke-YamlTestSuite.ps1') `
-Path $mutatedSuitePath `
-CompareJson
)
@($mutatedResults | Sort-Object Case | Select-Object -ExpandProperty Case) |
Should -Be @('565N', 'J7PZ')
@($mutatedResults | Where-Object JsonResult -EQ 'PolicyDifference').Count |
Should -Be 0
@($mutatedResults | Where-Object JsonResult -EQ 'Fail').Count | Should -Be 2
@($mutatedResults.JsonReason | Select-Object -Unique) |
Should -Be @('ConstructedValueMismatch')
}
It 'accounts for out.yaml representation comparisons' {
@($suiteResults | Where-Object OutYamlResult -EQ 'Pass').Count | Should -Be 241
@($suiteResults | Where-Object OutYamlResult -EQ 'PolicyDifference').Count |
Should -Be 0
@($suiteResults | Where-Object OutYamlResult -EQ 'Fail').Count | Should -Be 0
@($suiteResults | Where-Object OutYamlResult -EQ 'NotApplicable').Count |
Should -Be 161
}
It 'accounts for emitter and round-trip comparisons' {
@($suiteResults | Where-Object EmitResult -EQ 'Pass').Count | Should -Be 306
@($suiteResults | Where-Object EmitResult -EQ 'PolicyDifference').Count |
Should -Be 0
@($suiteResults | Where-Object EmitResult -EQ 'Fail').Count | Should -Be 0
@($suiteResults | Where-Object EmitResult -EQ 'NotApplicable').Count |
Should -Be 96
}
It 'keeps the previously failing multi-document JSON cases green' {
$jsonRegressions = @(
$suiteResults |
Where-Object Case -In @(
'35KP', '6XDY', '6ZKB', '7Z25', '9DXL',
'9KAX', 'JHB9', 'KSS4', 'L383', 'M7A3',
'PUW8', 'RZT7', 'U9NS', 'UT92', 'W4TN'
) |
Where-Object JsonResult -NE 'Pass'
)
$jsonRegressions.Count | Should -Be 0
}
}