Fix tests that were broken by the sxs module path change. Also fix some unreliable tests.

This commit is contained in:
Dongbo Wang
2016-08-11 21:45:20 -07:00
parent 896577e285
commit 753b202a75
8 changed files with 29 additions and 26 deletions
@@ -11,8 +11,8 @@ Describe "Configuration file locations" -tags "CI","Slow" {
if ($IsWindows) {
$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", "PowerShell", "Modules")
$expectedProfile = [io.path]::Combine($env:USERPROFILE, "Documents","PowerShell",$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