Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions PSDepend/PSDepend.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
}

#Get nuget dependecy file if we don't have it
#Read PSDepend.Config path variables
Get-Content $ModuleRoot\PSDepend.Config |
Where-Object {$_ -and $_ -notmatch "^\s*#"} |
Foreach-Object {
Expand All @@ -27,8 +27,5 @@
$Value = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Value)
Set-Variable -Name $Name -Value $Value
}
if(Test-PlatformSupport -Support 'windows','core') {
BootStrap-Nuget -NugetPath $NuGetPath
}

Export-ModuleMember -Function $Public.Basename
10 changes: 9 additions & 1 deletion PSDepend/PSDependScripts/Nuget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,15 @@ param(

if(-not (Get-Command Nuget -ErrorAction SilentlyContinue))
{
Write-Error "Nuget requires Nuget.exe. Ensure this is in your path, or explicitly specified in $ModuleRoot\PSDepend.Config's NugetPath. Skipping [$DependencyName]"
if(Test-PlatformSupport -Type 'Nuget' -Support 'windows','core')
{
BootStrap-Nuget -NugetPath $NuGetPath
}
if(-not (Get-Command Nuget -ErrorAction SilentlyContinue))
{
Write-Error "Nuget requires Nuget.exe. Ensure this is in your path, or explicitly specified in $ModuleRoot\PSDepend.Config's NugetPath. Skipping [$DependencyName]"
return
}
}

Write-Verbose -Message "Getting dependency [$DependencyName] from Nuget source [$Source]"
Expand Down
10 changes: 9 additions & 1 deletion PSDepend/PSDependScripts/PSGalleryNuget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ param(

if(-not (Get-Command Nuget -ErrorAction SilentlyContinue))
{
Write-Error "PSGalleryNuget requires Nuget.exe. Ensure this is in your path, or explicitly specified in $ModuleRoot\PSDepend.Config's NugetPath. Skipping [$DependencyName]"
if(Test-PlatformSupport -Type 'PSGalleryNuget' -Support 'windows','core')
{
BootStrap-Nuget -NugetPath $NuGetPath
}
if(-not (Get-Command Nuget -ErrorAction SilentlyContinue))
{
Write-Error "PSGalleryNuget requires Nuget.exe. Ensure this is in your path, or explicitly specified in $ModuleRoot\PSDepend.Config's NugetPath. Skipping [$DependencyName]"
return
}
}

Write-Verbose -Message "Getting dependency [$name] from Nuget source [$Source]"
Expand Down
40 changes: 40 additions & 0 deletions Tests/Nuget.Type.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,44 @@ Describe 'Nuget script' {
$Arguments -contains '-version' -and $Arguments -contains '12.0.2'
}
}

Context 'NuGet bootstrap' {
BeforeAll {
InModuleScope PSDepend {
Mock Get-Command { $null } -ParameterFilter { $Name -eq 'Nuget' }
Mock BootStrap-Nuget { }
Mock Test-PlatformSupport { $true }
}
}

It 'Calls BootStrap-Nuget when nuget.exe is missing on a supported platform' {
$targetDir = (New-Item 'TestDrive:/nuget-bootstrap' -ItemType Directory -Force).FullName
$dep = New-PSDependFixture -DependencyName 'Newtonsoft.Json' -DependencyType 'Nuget' -Target $targetDir
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -ErrorAction SilentlyContinue
}
Should -Invoke -CommandName BootStrap-Nuget -ModuleName PSDepend -Times 1
}

It 'Does not invoke nuget install when nuget.exe is still missing after bootstrap' {
$targetDir = (New-Item 'TestDrive:/nuget-bootstrap-fail' -ItemType Directory -Force).FullName
$dep = New-PSDependFixture -DependencyName 'Newtonsoft.Json' -DependencyType 'Nuget' -Target $targetDir
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -ErrorAction SilentlyContinue
}
Should -Invoke -CommandName Invoke-ExternalCommand -ModuleName PSDepend -Times 0
}

It 'Does not call BootStrap-Nuget on an unsupported platform' {
InModuleScope PSDepend {
Mock Test-PlatformSupport { $false }
}
$targetDir = (New-Item 'TestDrive:/nuget-bootstrap-noplatform' -ItemType Directory -Force).FullName
$dep = New-PSDependFixture -DependencyName 'Newtonsoft.Json' -DependencyType 'Nuget' -Target $targetDir
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -ErrorAction SilentlyContinue
}
Should -Invoke -CommandName BootStrap-Nuget -ModuleName PSDepend -Times 0
}
}
}
40 changes: 40 additions & 0 deletions Tests/PSGalleryNuget.Type.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,44 @@ Describe 'PSGalleryNuget script' {
}
Should -Invoke -CommandName Import-PSDependModule -ModuleName PSDepend -Times 1
}

Context 'NuGet bootstrap' {
BeforeAll {
InModuleScope PSDepend {
Mock Get-Command { $null } -ParameterFilter { $Name -eq 'Nuget' }
Mock BootStrap-Nuget { }
Mock Test-PlatformSupport { $true }
}
}

It 'Calls BootStrap-Nuget when nuget.exe is missing on a supported platform' {
$targetDir = (New-Item 'TestDrive:/psgnuget-bootstrap' -ItemType Directory -Force).FullName
$dep = New-PSDependFixture -DependencyName 'PSDeploy' -DependencyType 'PSGalleryNuget' -Target $targetDir
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -ErrorAction SilentlyContinue
}
Should -Invoke -CommandName BootStrap-Nuget -ModuleName PSDepend -Times 1
}

It 'Does not invoke nuget install when nuget.exe is still missing after bootstrap' {
$targetDir = (New-Item 'TestDrive:/psgnuget-bootstrap-fail' -ItemType Directory -Force).FullName
$dep = New-PSDependFixture -DependencyName 'PSDeploy' -DependencyType 'PSGalleryNuget' -Target $targetDir
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -ErrorAction SilentlyContinue
}
Should -Invoke -CommandName Invoke-ExternalCommand -ModuleName PSDepend -Times 0
}

It 'Does not call BootStrap-Nuget on an unsupported platform' {
InModuleScope PSDepend {
Mock Test-PlatformSupport { $false }
}
$targetDir = (New-Item 'TestDrive:/psgnuget-bootstrap-noplatform' -ItemType Directory -Force).FullName
$dep = New-PSDependFixture -DependencyName 'PSDeploy' -DependencyType 'PSGalleryNuget' -Target $targetDir
InModuleScope PSDepend -Parameters @{ Dep = $dep; ScriptPath = $script:ScriptPath } {
& $ScriptPath -Dependency $Dep -ErrorAction SilentlyContinue
}
Should -Invoke -CommandName BootStrap-Nuget -ModuleName PSDepend -Times 0
}
}
}
Loading