Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Add public variable containing module and script paths #486

Merged
merged 8 commits into from
May 31, 2019
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
118 changes: 64 additions & 54 deletions Tests/PowerShellGet.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,43 @@ function IsCoreCLR { $PSVersionTable.ContainsKey('PSEdition') -and $PSVersionTab

#region Install locations for modules and scripts

if(IsInbox)
{
if (IsInbox) {
$script:ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath "WindowsPowerShell"
}
elseif(IsCoreCLR){
if(IsWindows) {
elseif (IsCoreCLR) {
if (IsWindows) {
$script:ProgramFilesPSPath = Microsoft.PowerShell.Management\Join-Path -Path $env:ProgramFiles -ChildPath 'PowerShell'
}
else {
$script:ProgramFilesPSPath = Split-Path -Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory('SHARED_MODULES')) -Parent
}
}

try
{
try {
$script:MyDocumentsFolderPath = [Environment]::GetFolderPath("MyDocuments")
}
catch
{
catch {
$script:MyDocumentsFolderPath = $null
}

if(IsInbox)
{
$script:MyDocumentsPSPath = if($script:MyDocumentsFolderPath)
{
Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath "WindowsPowerShell"
}
else
{
Microsoft.PowerShell.Management\Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell"
}
if (IsInbox) {
$script:MyDocumentsPSPath = if ($script:MyDocumentsFolderPath) {
Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath "WindowsPowerShell"
}
else {
Microsoft.PowerShell.Management\Join-Path -Path $env:USERPROFILE -ChildPath "Documents\WindowsPowerShell"
}
}
elseif(IsCoreCLR) {
if(IsWindows)
{
$script:MyDocumentsPSPath = if($script:MyDocumentsFolderPath)
{
elseif (IsCoreCLR) {
if (IsWindows) {
$script:MyDocumentsPSPath = if ($script:MyDocumentsFolderPath) {
Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsFolderPath -ChildPath 'PowerShell'
}
else
{
}
else {
Microsoft.PowerShell.Management\Join-Path -Path $HOME -ChildPath "Documents\PowerShell"
}
}
else
{
else {
$script:MyDocumentsPSPath = Split-Path -Path ([System.Management.Automation.Platform]::SelectProductNameForDirectory('USER_MODULES')) -Parent
}
}
Expand All @@ -80,32 +70,57 @@ $script:MyDocumentsScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path

#region Register a test repository

function Initialize
{
function Initialize {
# Cleaned up commands whose output to console by deleting or piping to Out-Null
Import-Module PackageManagement
Get-PackageProvider -ListAvailable | Out-Null

$repo = Get-PSRepository -ErrorAction SilentlyContinue |
Where-Object {$_.SourceLocation.StartsWith($SourceLocation, [System.StringComparison]::OrdinalIgnoreCase)}
if($repo)
{
Where-Object { $_.SourceLocation.StartsWith($SourceLocation, [System.StringComparison]::OrdinalIgnoreCase) }
if ($repo) {
$script:RepositoryName = $repo.Name
}
else
{
else {
Register-PSRepository -Name $RepositoryName -SourceLocation $SourceLocation -InstallationPolicy Trusted
$script:RegisteredINTRepo = $true
}
}

#endregion

function Remove-InstalledModules
{
function Remove-InstalledModules {
Get-InstalledModule -Name $ContosoServer -AllVersions -ErrorAction SilentlyContinue | PowerShellGet\Uninstall-Module -Force
}

Describe "PowerShellGet - Module public variable tests" {
BeforeAll {
if ($script:Initialized -eq $false) {
Initialize
$script:Initialized = $true
}
}

It "PSGetPath variable should exist" {
Test-Path -Path variable:PSGetPath | Should -BeTrue
}

It "PSGetPath - AllUsersModules should be $ProgramFilesModulesPath" {
$PSGetPath.AllUsersModules | Should -Be $script:ProgramFilesModulesPath
}

It "PSGetPath - AllUsersScripts should be $ProgramFilesScriptsPath" {
$PSGetPath.AllUsersScripts | Should -Be $script:ProgramFilesScriptsPath
}

It "PSGetPath - CurrentUserModules should be $ProgramFilesModulesPath" {
$PSGetPath.CurrentUserModules | Should -Be $script:MyDocumentsModulesPath
}

It "PSGetPath - CurrentUserScripts should be $ProgramFilesScriptsPath" {
$PSGetPath.CurrentUserScripts | Should -Be $script:MyDocumentsScriptsPath
}
}

Describe "PowerShellGet - Module tests" -tags "Feature" {

BeforeAll {
Expand Down Expand Up @@ -162,8 +177,7 @@ Describe "PowerShellGet - Module tests (Admin)" -tags @('Feature', 'RequireAdmin

$installedModuleInfo | Should Not Be $null
$installedModuleInfo.Name | Should Be $ContosoServer
if ($script:IsCoreCLR)
{
if ($script:IsCoreCLR) {
$installedModuleInfo.InstalledLocation.StartsWith($script:MyDocumentsModulesPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
}
else {
Expand All @@ -180,8 +194,7 @@ Describe "PowerShellGet - Module tests (Admin)" -tags @('Feature', 'RequireAdmin
}
}

function Remove-InstalledScripts
{
function Remove-InstalledScripts {
Get-InstalledScript -Name $FabrikamServerScript -ErrorAction SilentlyContinue | Uninstall-Script -Force
}

Expand Down Expand Up @@ -237,22 +250,20 @@ Describe "PowerShellGet - Script tests (Admin)" -tags @('Feature', 'RequireAdmin

$installedScriptInfo | Should Not Be $null
$installedScriptInfo.Name | Should Be $FabrikamServerScript
if ($script:IsCoreCLR)
{
if ($script:IsCoreCLR) {
$installedScriptInfo.InstalledLocation.StartsWith($script:MyDocumentsScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
}
else
{
else {
$installedScriptInfo.InstalledLocation.StartsWith($script:ProgramFilesScriptsPath, [System.StringComparison]::OrdinalIgnoreCase) | Should Be $true
}
}
}

AfterAll {
Remove-InstalledScripts
}
}

Describe 'PowerShellGet Type tests' -tags @('BVT','CI') {
Describe 'PowerShellGet Type tests' -tags @('BVT', 'CI') {
BeforeAll {
Import-Module PowerShellGet -Force
}
Expand All @@ -263,15 +274,15 @@ Describe 'PowerShellGet Type tests' -tags @('BVT','CI') {
InternalWebProxy = @('GetProxy', 'IsBypassed')
}

if((IsWindows)) {
$PowerShellGetTypeDetails['CERT_CHAIN_POLICY_PARA'] = @('cbSize','dwFlags','pvExtraPolicyPara')
$PowerShellGetTypeDetails['CERT_CHAIN_POLICY_STATUS'] = @('cbSize','dwError','lChainIndex','lElementIndex','pvExtraPolicyStatus')
if ((IsWindows)) {
$PowerShellGetTypeDetails['CERT_CHAIN_POLICY_PARA'] = @('cbSize', 'dwFlags', 'pvExtraPolicyPara')
$PowerShellGetTypeDetails['CERT_CHAIN_POLICY_STATUS'] = @('cbSize', 'dwError', 'lChainIndex', 'lElementIndex', 'pvExtraPolicyStatus')
$PowerShellGetTypeDetails['InternalSafeHandleZeroOrMinusOneIsInvalid'] = @('IsInvalid')
$PowerShellGetTypeDetails['InternalSafeX509ChainHandle'] = @('CertFreeCertificateChain','ReleaseHandle','InvalidHandle')
$PowerShellGetTypeDetails['InternalSafeX509ChainHandle'] = @('CertFreeCertificateChain', 'ReleaseHandle', 'InvalidHandle')
$PowerShellGetTypeDetails['Win32Helpers'] = @('CertVerifyCertificateChainPolicy', 'CertDuplicateCertificateChain', 'IsMicrosoftCertificate')
}

if('Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI' -as [Type]) {
if ('Microsoft.PowerShell.Telemetry.Internal.TelemetryAPI' -as [Type]) {
$PowerShellGetTypeDetails['Telemetry'] = @('TraceMessageArtifactsNotFound', 'TraceMessageNonPSGalleryRegistration')
}

Expand All @@ -284,7 +295,6 @@ Describe 'PowerShellGet Type tests' -tags @('BVT','CI') {
}
}

if($RegisteredINTRepo)
{
if ($RegisteredINTRepo) {
Get-PSRepository -Name $RepositoryName -ErrorAction SilentlyContinue | Unregister-PSRepository
}
36 changes: 31 additions & 5 deletions src/PowerShellGet/PSGet.Format.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader/>
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
Expand Down Expand Up @@ -52,7 +52,7 @@
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader/>
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
Expand Down Expand Up @@ -87,7 +87,7 @@
<TableColumnHeader>
<Width>20</Width>
</TableColumnHeader>
<TableColumnHeader/>
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
Expand Down Expand Up @@ -126,7 +126,7 @@
<TableColumnHeader>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader/>
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
Expand Down Expand Up @@ -164,7 +164,7 @@
<TableColumnHeader>
<Width>35</Width>
</TableColumnHeader>
<TableColumnHeader/>
<TableColumnHeader />
</TableHeaders>
<TableRowEntries>
<TableRowEntry>
Expand All @@ -186,5 +186,31 @@
</TableRowEntries>
</TableControl>
</View>
<View>
<Name>PSGetPath</Name>
<ViewSelectedBy>
<TypeName>Microsoft.PowerShell.Commands.PSGetPath</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>AllUsersModules</PropertyName>
</ListItem>
<ListItem>
<PropertyName>AllUsersScripts</PropertyName>
</ListItem>
<ListItem>
<PropertyName>CurrentUserModules</PropertyName>
</ListItem>
<ListItem>
<PropertyName>CurrentUserScripts</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
2 changes: 1 addition & 1 deletion src/PowerShellGet/PowerShellGet.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'Update-Script',
'Update-ScriptFileInfo')

VariablesToExport = "*"
VariablesToExport = 'PSGetPath'
AliasesToExport = @('inmo', 'fimo', 'upmo', 'pumo')
FileList = @('PSModule.psm1',
'PSGet.Format.ps1xml',
Expand Down
22 changes: 15 additions & 7 deletions src/PowerShellGet/private/modulefile/PartOne.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ $script:MyDocumentsModulesPath = Microsoft.PowerShell.Management\Join-Path -Path
$script:ProgramFilesScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesPSPath -ChildPath 'Scripts'
$script:MyDocumentsScriptsPath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsPSPath -ChildPath 'Scripts'

$script:PSGetPath = [pscustomobject]@{
AllUsersModules = $script:ProgramFilesModulesPath
AllUsersScripts = $script:ProgramFilesScriptsPath
CurrentUserModules = $script:MyDocumentsModulesPath
CurrentUserScripts = $script:MyDocumentsScriptsPath
PSTypeName = 'Microsoft.PowerShell.Commands.PSGetPath'
}

$script:TempPath = [System.IO.Path]::GetTempPath()
$script:PSGetItemInfoFileName = "PSGetModuleInfo.xml"

Expand Down Expand Up @@ -133,9 +141,9 @@ $script:NuGetProviderName = "NuGet"
$script:NuGetProviderVersion = [Version]'2.8.5.201'

$script:SupportsPSModulesFeatureName = "supports-powershell-modules"
$script:FastPackRefHashtable = @{}
$script:NuGetBinaryProgramDataPath = if ($script:IsWindows) {"$env:ProgramFiles\PackageManagement\ProviderAssemblies"}
$script:NuGetBinaryLocalAppDataPath = if ($script:IsWindows) {"$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies"}
$script:FastPackRefHashtable = @{ }
$script:NuGetBinaryProgramDataPath = if ($script:IsWindows) { "$env:ProgramFiles\PackageManagement\ProviderAssemblies" }
$script:NuGetBinaryLocalAppDataPath = if ($script:IsWindows) { "$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies" }
# go fwlink for 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe'
$script:NuGetClientSourceURL = 'https://aka.ms/psget-nugetexe'
$script:NuGetExeMinRequiredVersion = [Version]'4.1.0'
Expand Down Expand Up @@ -261,7 +269,7 @@ $script:PackageManagementSaveModuleMessageResolverScriptBlock = {

switch ($i) {
'ActionInstallPackage' { return "Save-Module" }
'QueryInstallUntrustedPackage' {return $QuerySaveUntrustedPackage}
'QueryInstallUntrustedPackage' { return $QuerySaveUntrustedPackage }
'TargetPackage' { return $PackageTarget }
Default {
$Message = $Message -creplace "Install", "Download"
Expand Down Expand Up @@ -326,7 +334,7 @@ function PackageManagementMessageResolver($MsgID, $Message) {
'SourceNotFound' { return $SourceNotFound }
'CaptionPackageNotTrusted' { return $ModuleIsNotTrusted }
'CaptionSourceNotTrusted' { return $RepositoryIsNotTrusted }
'QueryInstallUntrustedPackage' {return $QueryInstallUntrustedPackage}
'QueryInstallUntrustedPackage' { return $QueryInstallUntrustedPackage }
Default {
if ($Message) {
$tempMessage = $Message -creplace "PackageSource", "PSRepository"
Expand Down Expand Up @@ -359,7 +367,7 @@ $script:PackageManagementSaveScriptMessageResolverScriptBlock = {

switch ($i) {
'ActionInstallPackage' { return "Save-Script" }
'QueryInstallUntrustedPackage' {return $QuerySaveUntrustedPackage}
'QueryInstallUntrustedPackage' { return $QuerySaveUntrustedPackage }
'TargetPackage' { return $PackageTarget }
Default {
$Message = $Message -creplace "Install", "Download"
Expand Down Expand Up @@ -418,7 +426,7 @@ function PackageManagementMessageResolverForScripts($MsgID, $Message) {
'SourceNotFound' { return $SourceNotFound }
'CaptionPackageNotTrusted' { return $ScriptIsNotTrusted }
'CaptionSourceNotTrusted' { return $RepositoryIsNotTrusted }
'QueryInstallUntrustedPackage' {return $QueryInstallUntrustedPackage}
'QueryInstallUntrustedPackage' { return $QueryInstallUntrustedPackage }
Default {
if ($Message) {
$tempMessage = $Message -creplace "PackageSource", "PSRepository"
Expand Down
Loading