2323)
2424
2525
26- # Step 0 -- remove the strongname from the binaries
27- # region
26+ # region Step 0 -- remove the strongname from the binaries
2827try
2928{
3029 reg ADD " HKLM\Software\Microsoft\StrongName\Verification\Microsoft.PackageManagement.ArchiverProviders,31bf3856ad364e35" / f
5352catch {}
5453# endregion
5554
56- # Step 1 - test setup
55+ # region Step 1 - test setup
5756$TestHome = $PSScriptRoot
5857$TestBin = " $ ( $TestHome ) \..\src\out\PackageManagement\"
5958$PowerShellGetPath = " $ ( $TestHome ) \..\src\Modules\PowerShellGet\"
60- $PowerShellGetVersion = " 1.1.0"
61- $PackageManagementVersion = " 1.1.0"
62-
63- $ProgramProviderInstalledPath = " $Env: ProgramFiles \PackageManagement\ProviderAssemblies"
64- $LocalAppData = $env: LocalAppdata
65- $UserProviderInstalledPath = " $ ( $LocalAppData ) \PackageManagement\ProviderAssemblies"
66- $ProgramModulePath = " $Env: ProgramFiles \WindowsPowerShell\Modules"
67-
59+ $PowerShellGetVersion = " 1.1.0.0"
60+ $PackageManagementVersion = " 1.1.0.0"
6861
6962$testframeworkVariable = $null
7063# For appveyor runs
@@ -79,7 +72,27 @@ if ($testframeworkVariable)
7972 $testframework = $testframeworkVariable
8073}
8174
82- Write-host " testframework = $testframework "
75+ # Get the current OS
76+ try {
77+ $Runtime = [System.Runtime.InteropServices.RuntimeInformation ]
78+ $OSPlatform = [System.Runtime.InteropServices.OSPlatform ]
79+
80+ $IsCoreCLR = $true
81+ $IsLinux = $Runtime ::IsOSPlatform($OSPlatform ::Linux)
82+ $IsOSX = $Runtime ::IsOSPlatform($OSPlatform ::OSX)
83+ $IsWindows = $Runtime ::IsOSPlatform($OSPlatform ::Windows)
84+ } catch {
85+ # If these are already set, then they're read-only and we're done
86+ try {
87+ $IsCoreCLR = $false
88+ $IsLinux = $false
89+ $IsOSX = $false
90+ $IsWindows = $true
91+ }
92+ catch { }
93+ }
94+
95+ Write-host (" testframework={0}, IsCoreCLR={1}, IsLinux={2}, IsOSX={3}, IsWindows={4}" -f $testframework , $IsCoreCLR , $IsLinux , $IsOSX , $IsWindows )
8396
8497
8598if ($testframework -eq " fullclr" )
@@ -91,84 +104,151 @@ else
91104 $mydocument = Microsoft.PowerShell.Management\Join-Path - Path $HOME - ChildPath " .local/share/powershell"
92105}
93106
94- $UserModulePath = " $ ( $mydocument ) \WindowsPowerShell\Modules"
95- $packagemanagementfolder = " $ProgramModulePath \PackageManagement\$PackageManagementVersion "
96- $powershellGetfolder = " $ProgramModulePath \PowerShellGet\$PowerShellGetVersion "
97107
98108# Setting up Packagemanagement and PowerShellGet folders
99109if ($testframework -eq " fullclr" )
100110{
111+ $ProgramProviderInstalledPath = " $Env: ProgramFiles \PackageManagement\ProviderAssemblies"
112+ $LocalAppData = $env: LocalAppdata
113+ $UserProviderInstalledPath = " $ ( $LocalAppData ) \PackageManagement\ProviderAssemblies"
114+ $ProgramModulePath = " $Env: ProgramFiles \WindowsPowerShell\Modules"
115+
116+ $UserModulePath = " $ ( $mydocument ) \WindowsPowerShell\Modules"
117+ $packagemanagementfolder = " $ProgramModulePath \PackageManagement\$PackageManagementVersion "
118+ $powershellGetfolder = " $ProgramModulePath \PowerShellGet\$PowerShellGetVersion "
119+
101120 if (-not (Test-Path $packagemanagementfolder )){
102121 New-Item - Path $packagemanagementfolder - ItemType Directory - Force
103122 Write-Host " Created $packagemanagementfolder "
104123 } else {
105124 Get-ChildItem - Path $packagemanagementfolder | % {ren " $packagemanagementfolder \$_ " " $packagemanagementfolder \$_ .deleteMe" }
106125 Get-ChildItem - Path $packagemanagementfolder - Recurse | Remove-Item - force - Recurse
107126 }
108- }
109127
110- if (-not (Test-Path $powershellGetfolder )){
111- New-Item - Path $powershellGetfolder - ItemType Directory - Force
112- Write-Host " Created $powershellGetfolder "
113- } else {
114- Get-ChildItem - Path $powershellGetfolder | % {ren " $powershellGetfolder \$_ " " $powershellGetfolder \$_ .deleteMe" }
115- Get-ChildItem - Path $powershellGetfolder - Recurse | Remove-Item - force - Recurse
116- }
117128
129+ if (-not (Test-Path $powershellGetfolder )){
130+ New-Item - Path $powershellGetfolder - ItemType Directory - Force
131+ Write-Host " Created $powershellGetfolder "
132+ } else {
133+ Get-ChildItem - Path $powershellGetfolder | % {ren " $powershellGetfolder \$_ " " $powershellGetfolder \$_ .deleteMe" }
134+ Get-ChildItem - Path $powershellGetfolder - Recurse | Remove-Item - force - Recurse
135+ }
118136
119- # Copying files to Packagemanagement and PowerShellGet folders
120- if ($testframework -eq " fullclr" )
121- {
137+
138+ # Copying files to Packagemanagement and PowerShellGet folders
122139 Copy-Item " $PowerShellGetPath \*" $powershellGetfolder - force - verbose
123140 Copy-Item " $TestBin \net451\*.dll" $packagemanagementfolder - force - Verbose
124141 Copy-Item " $TestBin \*.psd1" $packagemanagementfolder - force - Verbose
125142 Copy-Item " $TestBin \*.psm1" $packagemanagementfolder - force - Verbose
126143 Copy-Item " $TestBin \*.ps1" $packagemanagementfolder - force - Verbose
127144 Copy-Item " $TestBin \*.ps1xml" $packagemanagementfolder - force - Verbose
128- }
129145
130- # Setting up provider path
131- if (-not (Test-Path $ProgramProviderInstalledPath )){
132- New-Item - Path $ProgramProviderInstalledPath - ItemType Directory - Force
133- Write-Host " Created $ProgramProviderInstalledPath "
134- } else {
135- Get-ChildItem - Path $ProgramProviderInstalledPath - Recurse | Remove-Item - force - Recurse - ea silentlycontinue
136- }
137146
138- if (-not (Test-Path $UserProviderInstalledPath )) {
139- New-Item - Path $UserProviderInstalledPath - ItemType Directory - Force
140- Write-Host " Created $UserProviderInstalledPath "
147+ # Setting up provider path
148+ if (-not (Test-Path $ProgramProviderInstalledPath )){
149+ New-Item - Path $ProgramProviderInstalledPath - ItemType Directory - Force
150+ Write-Host " Created $ProgramProviderInstalledPath "
151+ } else {
152+ Get-ChildItem - Path $ProgramProviderInstalledPath - Recurse | Remove-Item - force - Recurse - ea silentlycontinue
153+ }
154+
155+ if (-not (Test-Path $UserProviderInstalledPath )) {
156+ New-Item - Path $UserProviderInstalledPath - ItemType Directory - Force
157+ Write-Host " Created $UserProviderInstalledPath "
141158
142- } else {
143- Get-ChildItem - Path $UserProviderInstalledPath - Recurse | Remove-Item - force - Recurse - ea silentlycontinue
144- }
159+ } else {
160+ Get-ChildItem - Path $UserProviderInstalledPath - Recurse | Remove-Item - force - Recurse - ea silentlycontinue
161+ }
145162
146- if (-not (Test-Path $UserModulePath )) {
147- New-Item - Path $UserModulePath - ItemType Directory - Force
148- Write-Host " Created $UserModulePath "
163+ if (-not (Test-Path $UserModulePath )) {
164+ New-Item - Path $UserModulePath - ItemType Directory - Force
165+ Write-Host " Created $UserModulePath "
149166
150- } else {
151- Get-ChildItem - Path $UserModulePath - Recurse | Remove-Item - force - Recurse - ea silentlycontinue
152- }
167+ } else {
168+ Get-ChildItem - Path $UserModulePath - Recurse | Remove-Item - force - Recurse - ea silentlycontinue
169+ }
170+
171+
172+ # Clean up
173+ if (Test-Path " $env: temp \PackageManagementDependencies" ) {
174+ Remove-Item - Recurse - Force " $env: temp \PackageManagementDependencies"
175+ }
153176
177+ Copy-Item " $ ( $TestHome ) \Unit\Providers\Dependencies" " $env: tmp \PackageManagementDependencies" - Recurse - Force
178+
179+
180+ if (test-path $Env: AppData / NuGet/ nuget.config) {
181+ copy - force $Env: AppData / NuGet/ nuget.config $Env: AppData / NuGet/ nuget.config.original - ea silentlycontinue
182+ rm - force $Env: AppData / NuGet/ nuget.config - ea silentlycontinue
183+ }
184+
185+ # Copy test dependencies
186+
187+ # Copy-Item "$($Testbin)\Microsoft.PackageManagement.OneGetTestProvider.dll" "$($ProgramProviderInstalledPath)\" -force
188+ # Copy-Item "$($Testbin)\Microsoft.PackageManagement.OneGetTestProvider.dll" "$($UserProviderInstalledPath)\" -force
189+
190+ Copy-Item " $ ( $TestHome ) \Unit\Providers\PSChained1Provider.psm1" " $ ( $ProgramModulePath ) \" - force - verbose
191+ Copy-Item " $ ( $TestHome ) \Unit\Providers\PSChained1Provider.psm1" " $ ( $UserModulePath ) \" - force - verbose
192+ Copy-Item " $ ( $TestHome ) \Unit\Providers\PSOneGetTestProvider" " $ ( $ProgramModulePath ) \" - Recurse - force - verbose
193+ }
154194
155195if ($testframework -eq " coreclr" )
156196{
157197 # install powershell core if test framework is coreclr
158- Install-PackageProvider PSL - Force;
159- $powershellCore = (Get-Package - provider PSL - name PowerShell)
160- if (-not $powershellCore )
161- {
162- $powershellCore = Install-Package PowerShell - Provider PSL - Force
198+
199+ If ($IsWindows )
200+ {
201+ Install-PackageProvider PSL - Force - verbose
202+ $powershellCore = (Get-Package - provider PSL - name PowerShell - ErrorAction SilentlyContinue)
203+ if ($powershellCore )
204+ {
205+ Write-Warning (" PowerShell already installed" -f $powershellCore.Name )
206+ }
207+ else
208+ {
209+ $powershellCore = Install-Package PowerShell - Provider PSL - Force - verbose
210+ }
211+
212+ $powershellVersion = $powershellCore.Version
213+ Write-host (" PowerShell Version '{0}'" -f $powershellVersion )
214+
215+ $powershellFolder = " $Env: ProgramFiles \PowerShell\$powershellVersion "
216+ Write-host (" PowerShell Folder '{0}'" -f $powershellFolder )
217+
163218 }
219+ else
220+ {
221+ # TODO: On Linux, need to grab PowerShellCore
164222
165- $powershellVersion = $powershellCore.Version
166- Write-host (" PowerShell Version '{0}'" -f $powershellVersion )
223+ }
167224
168- $powershellFolder = " $Env: ProgramFiles \PowerShell\$powershellVersion \"
169- Write-host (" PowerShell Folder '{0}'" -f $powershellFolder )
225+ # Workaround: delete installed PackageManagement files
226+ $assemblyNames = @ (
227+ " Microsoft.PackageManagement" ,
228+ " Microsoft.PackageManagement.ArchiverProviders" ,
229+ " Microsoft.PackageManagement.CoreProviders" ,
230+ " Microsoft.PackageManagement.MetaProvider.PowerShell" ,
231+ " Microsoft.PowerShell.PackageManagement" ,
232+ " Microsoft.PackageManagement.NuGetProvider"
233+ )
234+
235+ foreach ($assemblyName in $assemblyNames )
236+ {
237+ $dll = " $powershellFolder \$assemblyName .dll"
238+ if (Test-Path ($dll ))
239+ {
240+ Remove-Item - Path $dll - Verbose - force
241+ }
242+
243+ $ni = " $powershellFolder \$assemblyName .ni.dll"
244+ if (Test-Path ($ni ))
245+ {
246+ Remove-Item - Path $ni - Verbose - force
247+ }
248+ }
170249
171- $OneGetPath = " $powershellFolder \Modules\PackageManagement"
250+
251+ $OneGetPath = " $powershellFolder \Modules\PackageManagement\$PackageManagementVersion \"
172252 Write-host (" OneGet Folder '{0}'" -f $OneGetPath )
173253
174254 if (-not (Test-Path - Path $OneGetPath ))
@@ -182,62 +262,22 @@ if ($testframework -eq "coreclr")
182262 Copy-Item " $TestBin \*.ps1xml" $OneGetPath - force - Verbose
183263
184264 # copy the OneGet bits into powershell core
185- Copy-Item " $TestBin \netstandard1.6\*.dll" $OneGetPath - Force - Verbose
265+ $OneGetBinaryPath = " $OneGetPath \coreclr"
266+ if (-not (Test-Path - Path $OneGetBinaryPath ))
267+ {
268+ New-Item - Path $OneGetBinaryPath - ItemType Directory - Force - Verbose
269+ }
270+ Copy-Item " $TestBin \netstandard1.6\*.dll" $OneGetBinaryPath - Force - Verbose
186271
187272 # copy test modules
188273 Copy-Item " $ ( $TestHome ) \Unit\Providers\PSChained1Provider.psm1" " $ ( $powershellFolder ) \Modules" - force - verbose
189274 Copy-Item " $ ( $TestHome ) \Unit\Providers\PSOneGetTestProvider" " $ ( $powershellFolder ) \Modules" - Recurse - force - verbose
190275}
191276
192-
193-
194- if (Test-Path " $env: temp \PackageManagementDependencies" ) {
195- Remove-Item - Recurse - Force " $env: temp \PackageManagementDependencies"
196- }
197-
198- Copy-Item " $ ( $TestHome ) \Unit\Providers\Dependencies" " $env: tmp \PackageManagementDependencies" - Recurse - Force
199-
200-
201- # remove existing nuget provider.
202- if (test-path $Env: ProgramFiles / PackageManagement/ ProviderAssemblies/ nuget-anycpu.exe ) {
203- ren $Env: ProgramFiles / PackageManagement/ ProviderAssemblies/ nuget-anycpu.exe " nuget-anycpu.$ ( Get-Random ) .deleteme"
204- rm - force $Env: ProgramFiles / PackageManagement/ ProviderAssemblies/* .deleteme - ea silentlycontinue
205- }
206-
207- if (test-path $Env: LocalAppData / PackageManagement/ ProviderAssemblies/ nuget-anycpu.exe ) {
208- ren $Env: LocalAppData / PackageManagement/ ProviderAssemblies/ nuget-anycpu.exe " nuget-anycpu.$ ( Get-Random ) .deleteme"
209- rm - force $Env: LocalAppData / PackageManagement/ ProviderAssemblies/* .deleteme - ea silentlycontinue
210- }
211-
212- if (test-path $Env: ProgramFiles / PackageManagement/ ProviderAssemblies/ nuget-anycpu.exe ) {
213- ren $Env: ProgramFiles / PackageManagement/ ProviderAssemblies/ nuget-anycpu.exe " nuget-anycpu.$ ( Get-Random ) .deleteme"
214- rm - force $Env: ProgramFiles / PackageManagement/ ProviderAssemblies/* .deleteme - ea silentlycontinue
215- }
216-
217- if (test-path $Env: LocalAppData / PackageManagement/ ProviderAssemblies/ nuget-anycpu.exe ) {
218- ren $Env: LocalAppData / PackageManagement/ ProviderAssemblies/ nuget-anycpu.exe " nuget-anycpu.$ ( Get-Random ) .deleteme"
219- rm - force $Env: LocalAppData / PackageManagement/ ProviderAssemblies/* .deleteme - ea silentlycontinue
220- }
221-
222- if (test-path $Env: AppData / NuGet/ nuget.config) {
223- copy - force $Env: AppData / NuGet/ nuget.config $Env: AppData / NuGet/ nuget.config.original - ea silentlycontinue
224- rm - force $Env: AppData / NuGet/ nuget.config - ea silentlycontinue
225- }
226-
227-
228-
229- # Copy-Item "$($Testbin)\Microsoft.PackageManagement.OneGetTestProvider.dll" "$($ProgramProviderInstalledPath)\" -force
230- # Copy-Item "$($Testbin)\Microsoft.PackageManagement.OneGetTestProvider.dll" "$($UserProviderInstalledPath)\" -force
231-
232- if ($testframework -eq " fullclr" )
233- {
234- Copy-Item " $ ( $TestHome ) \Unit\Providers\PSChained1Provider.psm1" " $ ( $ProgramModulePath ) \" - force - verbose
235- Copy-Item " $ ( $TestHome ) \Unit\Providers\PSChained1Provider.psm1" " $ ( $UserModulePath ) \" - force - verbose
236- Copy-Item " $ ( $TestHome ) \Unit\Providers\PSOneGetTestProvider" " $ ( $ProgramModulePath ) \" - Recurse - force - verbose
237- }
277+ # endregion
238278
239279# Step 2 - run tests
240- Write-Host - fore White " Running powershell pester tests "
280+ Write-Host " Running powershell pester tests "
241281
242282if ($testframework -eq " fullclr" )
243283{
@@ -263,7 +303,7 @@ if ($testframework -eq "coreclr")
263303
264304 $command += " Invoke-Pester $ ( $TestHome ) \ModuleTests\tests"
265305
266- Write-Host " CoreCLR: Calling $command "
306+ Write-Host " CoreCLR: Calling $powershellFolder \powershell -command $ command"
267307
268308 & " $powershellFolder \powershell" - command $command
269309}
0 commit comments