-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.ps1
More file actions
249 lines (205 loc) · 7.27 KB
/
test.ps1
File metadata and controls
249 lines (205 loc) · 7.27 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using namespace System.IO
using namespace System.Reflection
param (
[Parameter(Mandatory)]
[string]
$Name
)
$ErrorActionPreference = 'Stop'
. $PSScriptRoot/common.ps1
#########
# SETUP #
#########
# Comes with Newtonsoft.Json 12
$pwsh_7_1 = Get-PowerShell -Version 7.1.7
# Comes with Newtonsoft.Json 13
$pwsh_7_4 = Get-PowerShell -Version 7.4.0
Get-NugetAssembly -Name YamlDotNet -Version 12.3.1 | Out-Null
Get-NugetAssembly -Name YamlDotNet -Version 13.7.1 | Out-Null
$newtonsoft_12 = Get-NugetAssembly -Name Newtonsoft.Json -Version 12.0.3
$newtonsoft_13 = Get-NugetAssembly -Name Newtonsoft.Json -Version 13.0.3
# Build our module
& $pwsh_7_4 -File ([Path]::Combine($PSScriptRoot, $Name, "build.ps1"))
#########
# TESTS #
#########
Push-Location -LiteralPath $PSScriptRoot/$Name
try {
Write-Host "Test: PS - Loading with assembly not loaded"
& $pwsh_7_4 {
Import-Module (Get-Item -Path ./output/ALC*).FullName
# Newtonsoft.Json is always loaded in pwsh so we are just testing YamlDotNet
ConvertTo-YamlDotNet foo
@(
foreach ($asm in [System.AppDomain]::CurrentDomain.GetAssemblies()) {
if (-not (
$asm.GetName().Name -like "*newtonsoft*" -or
$asm.GetName().Name -like "*yaml*"
)
) {
continue
}
$alc = [Runtime.Loader.AssemblyLoadContext]::GetLoadContext($asm)
[PSCustomObject]@{
Name = $asm.FullName
Location = $asm.Location
ALC = $alc
}
}
) | Format-List
} | Out-Host
Write-Host "Test: PS - Loading with older assembly already loaded"
& $pwsh_7_1 {
Import-Module (Get-Item -Path ./output/ALC*).FullName
Add-Type -Path "../bin/YamlDotNet.12.3.1/netstandard2.0/YamlDotNet.dll"
ConvertTo-NewtonsoftJson foo
ConvertTo-YamlDotNet foo
@(
foreach ($asm in [System.AppDomain]::CurrentDomain.GetAssemblies()) {
if (-not (
$asm.GetName().Name -like "*newtonsoft*" -or
$asm.GetName().Name -like "*yaml*"
)
) {
continue
}
$alc = [Runtime.Loader.AssemblyLoadContext]::GetLoadContext($asm)
[PSCustomObject]@{
Name = $asm.FullName
Location = $asm.Location
ALC = $alc
}
}
) | Format-List
} | Out-Host
Write-Host "Test: PS - Loading with same assembly version already loaded"
& $pwsh_7_4 {
Import-Module (Get-Item -Path ./output/ALC*).FullName
Add-Type -Path "../bin/YamlDotNet.13.7.1/netstandard2.0/YamlDotNet.dll"
ConvertTo-NewtonsoftJson foo
ConvertTo-YamlDotNet foo
@(
foreach ($asm in [System.AppDomain]::CurrentDomain.GetAssemblies()) {
if (-not (
$asm.GetName().Name -like "*newtonsoft*" -or
$asm.GetName().Name -like "*yaml*"
)
) {
continue
}
$alc = [Runtime.Loader.AssemblyLoadContext]::GetLoadContext($asm)
[PSCustomObject]@{
Name = $asm.FullName
Location = $asm.Location
ALC = $alc
}
}
) | Format-List
} | Out-Host
if ($IsCoreCLR -and -not $IsWindows) {
return
}
Write-Host "Test: WinPS - Assembly not already loaded"
powershell.exe {
Import-Module (Get-Item -Path ./output/ALC*).FullName
ConvertTo-NewtonsoftJson foo
ConvertTo-YamlDotNet foo
@(
foreach ($asm in [System.AppDomain]::CurrentDomain.GetAssemblies()) {
if (-not (
$asm.GetName().Name -like "*newtonsoft*" -or
$asm.GetName().Name -like "*yaml*"
)
) {
continue
}
[PSCustomObject]@{
Name = $asm.FullName
Location = $asm.Location
}
}
) | Format-List
} | Out-Host
Write-Host "Test: WinPS - Older assembly already loaded"
powershell.exe {
Add-Type -Path "../bin/Newtonsoft.Json.12.0.3/net45/Newtonsoft.Json.dll"
Add-Type -Path "../bin/YamlDotNet.12.3.1/net45/YamlDotNet.dll"
Import-Module (Get-Item -Path ./output/ALC*).FullName
ConvertTo-NewtonsoftJson foo
ConvertTo-YamlDotNet foo
@(
foreach ($asm in [System.AppDomain]::CurrentDomain.GetAssemblies()) {
if (-not (
$asm.GetName().Name -like "*newtonsoft*" -or
$asm.GetName().Name -like "*yaml*"
)
) {
continue
}
[PSCustomObject]@{
Name = $asm.FullName
Location = $asm.Location
}
}
) | Format-List
} | Out-Host
Write-Host "Test: WinPS - Same assembly already loaded"
powershell.exe {
Add-Type -Path "../bin/Newtonsoft.Json.13.0.3/net45/Newtonsoft.Json.dll"
Add-Type -Path "../bin/YamlDotNet.13.7.1/net45/YamlDotNet.dll"
Import-Module (Get-Item -Path ./output/ALC*).FullName
ConvertTo-NewtonsoftJson foo
ConvertTo-YamlDotNet foo
@(
foreach ($asm in [System.AppDomain]::CurrentDomain.GetAssemblies()) {
if (-not (
$asm.GetName().Name -like "*newtonsoft*" -or
$asm.GetName().Name -like "*yaml*"
)
) {
continue
}
[PSCustomObject]@{
Name = $asm.FullName
Location = $asm.Location
}
}
) | Format-List
} | Out-Host
# We need to be running as admin to add/remove from the GAC
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
if (-not
(([System.Security.Principal.WindowsPrincipal]$currentUser).IsInRole(
[System.Security.Principal.WindowsBuiltinRole]::Administrator
))
) {
return
}
$newton12Assembly = "$newtonsoft_12\net45\Newtonsoft.Json.dll"
$newton13Assembly = "$newtonsoft_13\net45\Newtonsoft.Json.dll"
Add-GacAssembly -Path $newton12Assembly
try {
Write-Host "Test: WinPS GAC - Older assembly version"
powershell.exe {
Import-Module (Get-Item -Path ./output/ALC*).FullName
ConvertTo-NewtonsoftJson foo
} | Out-Host
}
finally {
Remove-GacAssembly -Path $newton12Assembly
}
Add-GacAssembly -Path $newton13Assembly
try {
Write-Host "Test: WinPS GAC - Same assembly version"
powershell.exe {
Import-Module (Get-Item -Path ./output/ALC*).FullName
ConvertTo-NewtonsoftJson foo
} | Out-Host
}
finally {
Remove-GacAssembly -Path $newton13Assembly
}
}
finally {
Pop-Location
}