mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 04:36:39 +00:00
Merge pull request #1721 from PowerShell/dongbo/module-path
Address the side-by-side module path for OPS
This commit is contained in:
commit
539c59cc35
23 files changed
+508
-294
No files matched your search
@@ -10,9 +10,14 @@ Describe "Configuration file locations" -tags "CI","Slow" {
|
||||
BeforeAll {
|
||||
|
||||
if ($IsWindows) {
|
||||
$ProductName = "WindowsPowerShell"
|
||||
if ($IsCoreCLR -and ($PSHOME -notlike "*Windows\System32\WindowsPowerShell\v1.0"))
|
||||
{
|
||||
$ProductName = "PowerShell"
|
||||
}
|
||||
$expectedCache = [IO.Path]::Combine($env:LOCALAPPDATA, "Microsoft", "Windows", "PowerShell", "StartupProfileData-NonInteractive")
|
||||
$expectedModule = [IO.Path]::Combine($env:USERPROFILE, "Documents", "WindowsPowerShell", "Modules")
|
||||
$expectedProfile = [io.path]::Combine($env:USERPROFILE, "Documents","WindowsPowerShell",$profileName)
|
||||
$expectedModule = [IO.Path]::Combine($env:USERPROFILE, "Documents", $ProductName, "Modules")
|
||||
$expectedProfile = [io.path]::Combine($env:USERPROFILE, "Documents", $ProductName, $profileName)
|
||||
$expectedReadline = [IO.Path]::Combine($env:AppData, "Microsoft", "Windows", "PowerShell", "PSReadline", "ConsoleHost_history.txt")
|
||||
} else {
|
||||
$expectedCache = [IO.Path]::Combine($env:HOME, ".cache", "powershell", "StartupProfileData-NonInteractive")
|
||||
|
||||
@@ -26,7 +26,7 @@ Describe 'use of a module from two runspaces' -Tags "CI" {
|
||||
|
||||
$resolvedTestDrivePath = Split-Path ((get-childitem TestDrive:\)[0].FullName)
|
||||
if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) {
|
||||
$env:PSMODULEPATH += ";$resolvedTestDrivePath"
|
||||
$env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ Describe 'NestedModules' -Tags "CI" {
|
||||
|
||||
$resolvedTestDrivePath = Split-Path ((get-childitem TestDrive:\)[0].FullName)
|
||||
if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) {
|
||||
$env:PSMODULEPATH += ";$resolvedTestDrivePath"
|
||||
$env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Describe 'using module' -Tags "CI" {
|
||||
|
||||
$resolvedTestDrivePath = Split-Path ((get-childitem "${TestDrive}\$ModulePathPrefix")[0].FullName)
|
||||
if (-not ($env:PSMODULEPATH -like "*$resolvedTestDrivePath*")) {
|
||||
$env:PSMODULEPATH += ";$resolvedTestDrivePath"
|
||||
$env:PSMODULEPATH += "$([System.IO.Path]::PathSeparator)$resolvedTestDrivePath"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Describe "Export-Csv" -Tags "CI" {
|
||||
$testObject = @("test","object","array")
|
||||
$testCsv = "output.csv"
|
||||
$testCsv = Join-Path -Path $TestDrive -ChildPath "output.csv"
|
||||
|
||||
AfterEach {
|
||||
Remove-Item $testCsv -Force -ErrorAction SilentlyContinue
|
||||
@@ -51,7 +51,7 @@ Describe "Export-Csv" -Tags "CI" {
|
||||
It "Should have the same information when using the alias vs the cmdlet" {
|
||||
$testObject | Export-Csv -Path $testCsv
|
||||
|
||||
$aliasObject = "alias.csv"
|
||||
$aliasObject = Join-Path -Path $TestDrive -ChildPath "alias.csv"
|
||||
|
||||
$testObject | epcsv -Path $aliasObject
|
||||
|
||||
|
||||
@@ -16,26 +16,29 @@ Describe "Export-FormatData DRT Unit Tests" -Tags "CI" {
|
||||
|
||||
Describe "Export-FormatData" -Tags "CI" {
|
||||
|
||||
$testOutput = Join-Path -Path $TestDrive -ChildPath "outputfile"
|
||||
|
||||
AfterEach {
|
||||
Remove-Item $testOutput -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
Context "Check Export-FormatData can be called validly." {
|
||||
It "Should be able to be called without error" {
|
||||
{ Get-FormatData | Export-FormatData -Path "outputfile" } | Should Not Throw
|
||||
Remove-Item "outputfile" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
It "Should be able to be called without error" {
|
||||
{ Get-FormatData | Export-FormatData -Path $testOutput } | Should Not Throw
|
||||
}
|
||||
}
|
||||
|
||||
Context "Check that the output is in the correct format" {
|
||||
It "Should not return an empty xml file" {
|
||||
Get-FormatData | Export-FormatData -Path "outputfile"
|
||||
$piped = Get-Content "outputfile"
|
||||
$piped | Should Not Be ""
|
||||
Remove-Item "outputfile" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
It "Should not return an empty xml file" {
|
||||
Get-FormatData | Export-FormatData -Path $testOutput
|
||||
$piped = Get-Content $testOutput
|
||||
$piped | Should Not Be ""
|
||||
}
|
||||
|
||||
It "Should have a valid xml tag at the start of the file" {
|
||||
Get-FormatData | Export-FormatData -Path "outputfile"
|
||||
$piped = Get-Content "outputfile"
|
||||
$piped[0] | Should Be "<"
|
||||
Remove-Item "outputfile" -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
It "Should have a valid xml tag at the start of the file" {
|
||||
Get-FormatData | Export-FormatData -Path $testOutput
|
||||
$piped = Get-Content $testOutput
|
||||
$piped[0] | Should Be "<"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
Describe "Out-File DRT Unit Tests" -Tags "CI" {
|
||||
It "Should be able to write the contens into a file with -pspath" {
|
||||
$tempFile = "ExposeBug928965"
|
||||
$tempFile = Join-Path -Path $TestDrive -ChildPath "ExposeBug928965"
|
||||
{ 1 | Out-File -PSPath $tempFile } | Should Not Throw
|
||||
$fileContents = Get-Content $tempFile
|
||||
$fileContents | Should be 1
|
||||
@@ -8,7 +8,7 @@ Describe "Out-File DRT Unit Tests" -Tags "CI" {
|
||||
}
|
||||
|
||||
It "Should be able to write the contens into a file with -pspath" {
|
||||
$tempFile = "outfileAppendTest.txt"
|
||||
$tempFile = Join-Path -Path $TestDrive -ChildPath "outfileAppendTest.txt"
|
||||
{ 'This is first line.' | out-file $tempFile } | Should Not Throw
|
||||
{ 'This is second line.' | out-file -append $tempFile } | Should Not Throw
|
||||
$tempFile |Should Contain "first"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Describe "Stream writer tests" -Tags "CI" {
|
||||
$targetfile = "writeoutput.txt"
|
||||
$targetfile = Join-Path -Path $TestDrive -ChildPath "writeoutput.txt"
|
||||
|
||||
# A custom function is defined here do handle the debug stream dealing with the confirm prompt
|
||||
# that would normally
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
Describe "SxS Module Path Basic Tests" -tags "CI" {
|
||||
|
||||
BeforeAll {
|
||||
|
||||
if ($IsWindows)
|
||||
{
|
||||
$powershell = "$PSHOME\powershell.exe"
|
||||
$ProductName = "WindowsPowerShell"
|
||||
if ($IsCoreCLR -and ($PSHOME -notlike "*Windows\System32\WindowsPowerShell\v1.0"))
|
||||
{
|
||||
$ProductName = "PowerShell"
|
||||
}
|
||||
$expectedUserPath = Join-Path -Path $HOME -ChildPath "Documents\$ProductName\Modules"
|
||||
$expectedSharedPath = Join-Path -Path $env:ProgramFiles -ChildPath "$ProductName\Modules"
|
||||
}
|
||||
else
|
||||
{
|
||||
$powershell = "$PSHOME/powershell"
|
||||
$expectedUserPath = [System.Management.Automation.Platform]::SelectProductNameForDirectory("USER_MODULES")
|
||||
$expectedSharedPath = [System.Management.Automation.Platform]::SelectProductNameForDirectory("SHARED_MODULES")
|
||||
}
|
||||
$expectedSystemPath = Join-Path -Path $PSHOME -ChildPath 'Modules'
|
||||
}
|
||||
|
||||
BeforeEach {
|
||||
$originalModulePath = $env:PSMODULEPATH
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
$env:PSMODULEPATH = $originalModulePath
|
||||
}
|
||||
|
||||
It "validate sxs module path" {
|
||||
|
||||
$env:PSMODULEPATH = ""
|
||||
$defaultModulePath = & $powershell -nopro -c '$env:PSMODULEPATH'
|
||||
|
||||
$paths = $defaultModulePath -split [System.IO.Path]::PathSeparator
|
||||
|
||||
$paths.Count | Should Be 3
|
||||
$paths[0] | Should Be $expectedUserPath
|
||||
$paths[1] | Should Be $expectedSharedPath
|
||||
$paths[2] | Should Be $expectedSystemPath
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user