From 753b202a759df64dfdf43dbed2ae8a3b52655643 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 11 Aug 2016 14:30:02 -0700 Subject: [PATCH] Fix tests that were broken by the sxs module path change. Also fix some unreliable tests. --- test/powershell/Host/Base-Directory.Tests.ps1 | 4 +-- .../Scripting.Classes.Modules.Tests.ps1 | 2 +- .../scripting.Classes.NestedModules.tests.ps1 | 2 +- .../Classes/scripting.Classes.using.tests.ps1 | 2 +- .../Export-Csv.Tests.ps1 | 4 +-- .../Export-FormatData.Tests.ps1 | 35 ++++++++++--------- .../Out-File.Tests.ps1 | 4 +-- .../Write-Stream.Tests.ps1 | 2 +- 8 files changed, 29 insertions(+), 26 deletions(-) diff --git a/test/powershell/Host/Base-Directory.Tests.ps1 b/test/powershell/Host/Base-Directory.Tests.ps1 index 11811fdb35..70f5163d31 100644 --- a/test/powershell/Host/Base-Directory.Tests.ps1 +++ b/test/powershell/Host/Base-Directory.Tests.ps1 @@ -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") diff --git a/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 b/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 index 5caca7d220..b9bc551326 100644 --- a/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 +++ b/test/powershell/Language/Classes/Scripting.Classes.Modules.Tests.ps1 @@ -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" } } diff --git a/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 b/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 index 86ae42c120..886ea067f5 100644 --- a/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.Classes.NestedModules.tests.ps1 @@ -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" } } diff --git a/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 b/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 index d4c6fc42f8..82fd317804 100644 --- a/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 +++ b/test/powershell/Language/Classes/scripting.Classes.using.tests.ps1 @@ -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" } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 index 0340ae3d40..f4c95abb4c 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 @@ -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 diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 index fc50695b83..7761cf4ac2 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Export-FormatData.Tests.ps1 @@ -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 "<" + } } } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 index cf99491fce..70e4ce1cd5 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Out-File.Tests.ps1 @@ -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" diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 index 4c52d3e045..7df534ae1e 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Write-Stream.Tests.ps1 @@ -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