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
17 changes: 9 additions & 8 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,8 @@ Describe "TabCompletion" -Tags CI {
@{ inputStr = '$global:max'; expected = '$global:MaximumHistoryCount'; setup = $null }
@{ inputStr = '$PSMod'; expected = '$PSModuleAutoLoadingPreference'; setup = $null }
## tab completion for variable in path
@{ inputStr = 'cd $pshome\Modu'; expected = Join-Path $PSHOME 'Modules'; setup = $null }
## if $PSHOME contains a space tabcompletion adds ' around the path
@{ inputStr = 'cd $pshome\Modu'; expected = if($PSHOME.Contains(' ')) { "'$(Join-Path $PSHOME 'Modules')'" } else { Join-Path $PSHOME 'Modules' }; setup = $null }
@{ inputStr = 'cd "$pshome\Modu"'; expected = "`"$(Join-Path $PSHOME 'Modules')`""; setup = $null }
@{ inputStr = '$PSHOME\System.Management.Au'; expected = Join-Path $PSHOME 'System.Management.Automation.dll'; setup = $null }
@{ inputStr = '"$PSHOME\System.Management.Au"'; expected = "`"$(Join-Path $PSHOME 'System.Management.Automation.dll')`""; setup = $null }
Expand Down Expand Up @@ -467,7 +468,7 @@ Describe "TabCompletion" -Tags CI {
$beforeTab = "\\localhost\$homeDrive\wind"
$afterTab = "& '\\localhost\$homeDrive\Windows'"
$res = TabExpansion2 -inputScript $beforeTab -cursorColumn $beforeTab.Length
$res.CompletionMatches.Count | Should BeExactly 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Should BeGreaterThan 0 - else next line can throw with useless message.

Copy link
Member Author

@adityapatwardhan adityapatwardhan Oct 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iSazonov Can you elaborate. I want to check it for being exactly 1. If the check fails, the next line will not be executed and the It will be marked as 'Failed'.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If $res.CompletionMatches.Count = 0 then $res.CompletionMatches[0] will throw with generic message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if $res.CompletionMatches.Count = 2 and we are using Should BeGreaterThan 0 then the test might pass but we are getting more matches than expected.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder now - why are we removing this line with Should BeExactly 1 if we want just 1 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I confused this with the about_help test. This can be BeGreaterThan 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

$res.CompletionMatches.Count | Should BeGreaterThan 0
$res.CompletionMatches[0].CompletionText | Should Be $afterTab
}

Expand Down Expand Up @@ -496,7 +497,7 @@ Describe "TabCompletion" -Tags CI {
$afterTab = 'filesystem::/usr' -f $env:SystemDrive
}
$res = TabExpansion2 -inputScript $beforeTab -cursorColumn $beforeTab.Length
$res.CompletionMatches.Count | Should BeExactly 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Should BeGreaterThan 0 - else next line can throw with useless message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I confused this with the about_help test. This can be BeGreaterThan 0.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

$res.CompletionMatches.Count | Should BeGreaterThan 0
$res.CompletionMatches[0].CompletionText | Should Be $afterTab
}

Expand Down Expand Up @@ -914,13 +915,13 @@ dir -Recurse `
@{ inputStr = 'Get-CimInstance Win32_Process | ?{ $_.ProcessId -eq $Pid } | Get-CimAssociatedInstance -ResultClassName Win32_ComputerS'; expected = 'Win32_ComputerSystem' }
@{ inputStr = 'Get-CimInstance -Namespace root/Interop -ClassName Win32_PowerSupplyP'; expected = 'Win32_PowerSupplyProfile' }
@{ inputStr = 'Get-CimInstance __NAMESP'; expected = '__NAMESPACE' }
@{ inputStr = 'Get-CimInstance -Namespace root/Int'; expected = 'root/Interop' }
@{ inputStr = 'Get-CimInstance -Namespace root/Inter'; expected = 'root/Interop' }
@{ inputStr = 'Get-CimInstance -Namespace root/Int*ro'; expected = 'root/Interop' }
@{ inputStr = 'Get-CimInstance -Namespace root/Interop/'; expected = 'root/Interop/ms_409' }
@{ inputStr = 'New-CimInstance -Namespace root/Int'; expected = 'root/Interop' }
@{ inputStr = 'Invoke-CimMethod -Namespace root/Int'; expected = 'root/Interop' }
@{ inputStr = 'Get-CimClass -Namespace root/Int'; expected = 'root/Interop' }
@{ inputStr = 'Register-CimIndicationEvent -Namespace root/Int'; expected = 'root/Interop' }
@{ inputStr = 'New-CimInstance -Namespace root/Inter'; expected = 'root/Interop' }
@{ inputStr = 'Invoke-CimMethod -Namespace root/Inter'; expected = 'root/Interop' }
@{ inputStr = 'Get-CimClass -Namespace root/Inter'; expected = 'root/Interop' }
@{ inputStr = 'Register-CimIndicationEvent -Namespace root/Inter'; expected = 'root/Interop' }
@{ inputStr = '[Microsoft.Management.Infrastructure.CimClass]$c = $null; $c.CimClassNam'; expected = 'CimClassName' }
@{ inputStr = '[Microsoft.Management.Infrastructure.CimClass]$c = $null; $c.CimClassName.Substrin'; expected = 'Substring(' }
@{ inputStr = 'Get-CimInstance -ClassName Win32_Process | %{ $_.ExecutableP'; expected = 'ExecutablePath' }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Describe "Get-Process for admin" -Tags @('CI', 'RequireAdminOnWindows') {
It "Should support -IncludeUserName" {
(Get-Process powershell -IncludeUserName | Select-Object -First 1).UserName | Should Match $env:USERNAME
(Get-Process -Id $pid -IncludeUserName).UserName | Should Match $env:USERNAME
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Describe "CredSSP cmdlet tests" -Tags 'Feature','RequireAdminOnWindows' {
{
$PSDefaultParameterValues["it:skip"] = $true
}
else
else
{
if ([System.Globalization.CultureInfo]::CurrentCulture.Name -ne "en-US")
{
$notEnglish = $true
}
}
}

AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParameterValues
}
Expand Down
20 changes: 19 additions & 1 deletion test/powershell/engine/Api/ProxyCommand.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@ using namespace System.Collections.ObjectModel

Describe 'ProxyCommand Tests' -Tags "CI" {
BeforeAll {
function NormalizeCRLF {
param ($helpObj)

if($helpObj.Synopsis.Contains("`r`n"))
{
$helpObjText = ($helpObj.Synopsis).replace("`r`n", [System.Environment]::NewLine).trim()
}
else
{
$helpObjText = ($helpObj.Synopsis).replace("`n", [System.Environment]::NewLine).trim()
}

return $helpObjText
}

function GetSectionText {
param ($object)
$texts = $object | Out-String -Stream | ForEach-Object {
Expand Down Expand Up @@ -82,7 +97,10 @@ Describe 'ProxyCommand Tests' -Tags "CI" {
Set-Item -Path function:\TestHelpComment -Value $bodySB
$newHelpObj = Get-Help TestHelpComment -Full

$helpObj.Synopsis | Should Be $newHelpObj.Synopsis
$helpObjText = NormalizeCRLF -helpObj $helpObj
$newHelpObjText = NormalizeCRLF -helpObj $newHelpObj

$helpObjText | Should Be $newHelpObjText
$oldDespText = GetSectionText $helpObj.description
$newDespText = GetSectionText $newHelpObj.description
$oldDespText | Should Be $newDespText
Expand Down
4 changes: 4 additions & 0 deletions test/powershell/engine/Help/HelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,14 @@ Describe "Validate about_help.txt under culture specific folder works" -Tags @('
New-ModuleManifest -Path $modulePath\test.psd1 -RootModule test.psm1
Set-Content -Path $modulePath\test.psm1 -Value "function foo{}"
Set-Content -Path $modulePath\en-US\about_testhelp.help.txt -Value "Hello" -NoNewline
## This is needed for getting about topics. We use -Force, so we always update.
Update-Help -Force
}

AfterAll {
Remove-Item $modulePath -Recurse -Force
# Remove all the help content.
Get-ChildItem -Path $PSHOME -Include @('about_*.txt', "*help.xml") -Recurse | Remove-Item -Force -ErrorAction SilentlyContinue
}

It "Get-Help should return help text and not multiple HelpInfo objects when help is under `$pshome path" {
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Help/UpdatableHelpSystem.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function RunUpdateHelpTests
It "Validate Update-Help for module '$moduleName'" -Pending:$Pending {

# If the help file is already installed, delete it.
Get-ChildItem $testCases[$moduleName].HelpInstallationPath -Include @("about_*.txt","*help.xml") -Recurse -ea SilentlyContinue |
Get-ChildItem $testCases[$moduleName].HelpInstallationPath -Include @("*help.xml") -Recurse -ea SilentlyContinue |
Remove-Item -Force -ErrorAction SilentlyContinue

if ((Get-UICulture).Name -ne "en-Us")
Expand Down
13 changes: 9 additions & 4 deletions test/powershell/engine/Remoting/SSHRemotingAPI.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ Describe "SSH Remoting API Tests" -Tags "Feature" {

Context "SSHConnectionInfo Class Tests" {

BeforeAll {
## Skip the test if ssh is not present.
$skipTest = (Get-Command 'ssh' -CommandType Application -ErrorAction SilentlyContinue) -eq $null
}

AfterEach {
if ($null -ne $rs) {
$rs.Dispose()
Expand All @@ -17,7 +22,7 @@ Describe "SSH Remoting API Tests" -Tags "Feature" {
0) } | ShouldBeErrorId "PSArgumentNullException"
}

It "SSHConnectionInfo should throw file not found exception for invalid key file path" {
It "SSHConnectionInfo should throw file not found exception for invalid key file path" -Skip:$skipTest {

try
{
Expand All @@ -29,7 +34,7 @@ Describe "SSH Remoting API Tests" -Tags "Feature" {

$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
$rs.Open()

throw "No Exception!"
}
catch
Expand All @@ -39,7 +44,7 @@ Describe "SSH Remoting API Tests" -Tags "Feature" {
}

It "SSHConnectionInfo should throw argument exception for invalid port (non 16bit uint)" {
try
try
{
$sshConnectionInfo = [System.Management.Automation.Runspaces.SSHConnectionInfo]::new(
"UserName",
Expand All @@ -49,7 +54,7 @@ Describe "SSH Remoting API Tests" -Tags "Feature" {

$rs = [runspacefactory]::CreateRunspace($sshConnectionInfo)
$rs.Open()

throw "No Exception!"
}
catch
Expand Down
109 changes: 66 additions & 43 deletions test/tools/CodeCoverageAutomation/Start-CodeCoverageRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function ConvertTo-CodeCovJson
$progress=0
foreach($f in $keys)
{
Write-Progress -Id 1 -Activity "Converting to JSON" -Status 'Converting' -PercentComplete ($progress * 100 / $keys.Count)
Write-Progress -Id 1 -Activity "Converting to JSON" -Status 'Converting' -PercentComplete ($progress * 100 / $keys.Count)
$fileCoverage = GetSequencePointsForFile -fileId $f
$fileName = $Script:fileTable[$f]
$previousFileCoverage = $totalCoverage.coverage.${fileName}
Expand All @@ -77,7 +77,7 @@ function ConvertTo-CodeCovJson

Write-Progress -Id 1 -Completed -Activity "Converting to JSON"

$totalCoverage | ConvertTo-Json -Depth 5 -Compress | out-file $DestinationPath -Encoding ascii
$totalCoverage | ConvertTo-Json -Depth 5 -Compress | Out-File $DestinationPath -Encoding ascii
}

function Write-LogPassThru
Expand Down Expand Up @@ -151,26 +151,67 @@ try

$oldErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
$oldProgressPreference = $ProgressPreference
$ProgressPreference = 'SilentlyContinue'
Write-LogPassThru -Message "Starting downloads."

$CoverageZipFilePath = "$outputBaseFolder\PSCodeCoverage.zip"
if(Test-Path $CoverageZipFilePath)
{
Remove-Item $CoverageZipFilePath -Force
}
Invoke-WebRequest -uri $codeCoverageZip -outfile "$outputBaseFolder\PSCodeCoverage.zip"
Invoke-WebRequest -uri $testContentZip -outfile "$outputBaseFolder\tests.zip"
Invoke-WebRequest -uri $openCoverZip -outfile "$outputBaseFolder\OpenCover.zip"
Write-LogPassThru -Message "Downloads complete. Starting expansion"

Expand-Archive -path "$outputBaseFolder\PSCodeCoverage.zip" -destinationpath "$psBinPath" -Force
Expand-Archive -path "$outputBaseFolder\tests.zip" -destinationpath $testRootPath -Force
Expand-Archive -path "$outputBaseFolder\OpenCover.zip" -destinationpath $openCoverPath -Force
$TestsZipFilePath = "$outputBaseFolder\tests.zip"
if(Test-Path $TestsZipFilePath)
{
Remove-Item $TestsZipFilePath -Force
}
Invoke-WebRequest -uri $testContentZip -outfile $TestsZipFilePath

## Download Coveralls.net uploader
$coverallsToolsUrl = 'https://github.com/csMACnz/coveralls.net/releases/download/0.7.0/coveralls.net.0.7.0.nupkg'
$coverallsPath = "$outputBaseFolder\coveralls"
$OpenCoverZipFilePath = "$outputBaseFolder\OpenCover.zip"
if(Test-Path $OpenCoverZipFilePath)
{
Remove-Item $OpenCoverZipFilePath -Force
}
Invoke-WebRequest -uri $openCoverZip -outfile $OpenCoverZipFilePath

## Saving the nupkg as zip so we can expand it.
Invoke-WebRequest -uri $coverallsToolsUrl -outfile "$outputBaseFolder\coveralls.zip"
Expand-Archive -Path "$outputBaseFolder\coveralls.zip" -DestinationPath $coverallsPath -Force
Write-LogPassThru -Message "Downloads complete. Starting expansion"

if(Test-Path $psBinPath)
{
Remove-Item -Force -Recurse $psBinPath
}
Expand-Archive -path $CoverageZipFilePath -destinationpath "$psBinPath" -Force

if(Test-Path $testRootPath)
{
Remove-Item -Force -Recurse $testRootPath
}
Expand-Archive -path $TestsZipFilePath -destinationpath $testRootPath -Force

if(Test-Path $openCoverPath)
{
Remove-Item -Force -Recurse $openCoverPath
}
Expand-Archive -path $OpenCoverZipFilePath -destinationpath $openCoverPath -Force
Write-LogPassThru -Message "Expansion complete."

if(Test-Path $elevatedLogs)
{
Remove-Item -Force -Recurse $elevatedLogs
}

if(Test-Path $unelevatedLogs)
{
Remove-Item -Force -Recurse $unelevatedLogs
}

if(Test-Path $outputLog)
{
Remove-Item $outputLog -Force -ErrorAction SilentlyContinue
}

Import-Module "$openCoverPath\OpenCover" -Force
Install-OpenCover -TargetDirectory $openCoverTargetDirectory -force
Write-LogPassThru -Message "OpenCover installed."
Expand Down Expand Up @@ -210,11 +251,15 @@ try
# clean up partial repo clone before starting
if ( Test-Path "$outputBaseFolder/.git" )
{
remove-item -force -recurse "${outputBaseFolder}/.git"
Remove-Item -Force -Recurse "${outputBaseFolder}/.git"
}
if ( Test-Path "$outputBaseFolder/src" )
{
remove-item -force -recurse "${outputBaseFolder}/src"
Remove-Item -Force -Recurse "${outputBaseFolder}/src"
}
if ( Test-Path "$outputBaseFolder/assests" )
{
Remove-Item -Force -Recurse "${outputBaseFolder}/assets"
}
Write-LogPassThru -Message "initializing repo in $outputBaseFolder"
& $gitexe init
Expand All @@ -229,7 +274,8 @@ try
Write-LogPassThru -Message "git operation 'set sparse-checkout' returned $LASTEXITCODE"

Write-LogPassThru -Message "pulling sparse repo"
"src" | out-file -encoding ascii .git\info\sparse-checkout
"src" | Out-File -Encoding ascii .git\info\sparse-checkout -Force
"assets" | Out-File -Encoding ascii .git\info\sparse-checkout -Append
& $gitexe pull origin master
Write-LogPassThru -Message "git operation 'pull' returned $LASTEXITCODE"

Expand All @@ -245,10 +291,6 @@ try
$openCoverParams | Out-String | Write-LogPassThru
Write-LogPassThru -Message "Starting test run."

if(Test-Path $outputLog)
{
Remove-Item $outputLog -Force -ErrorAction SilentlyContinue
}
# now invoke opencover
Invoke-OpenCover @openCoverParams

Expand All @@ -261,31 +303,11 @@ try

Write-LogPassThru -Message $commitId

$coverallsPath = "$outputBaseFolder\coveralls"

$commitInfo = Invoke-RestMethod -Method Get "https://api.github.com/repos/powershell/powershell/git/commits/$commitId"
$message = ($commitInfo.message).replace("`n", " ")
$author = $commitInfo.author.name
$email = $commitInfo.author.email

$coverallsExe = Join-Path $coverallsPath "tools\csmacnz.Coveralls.exe"
$coverallsParams = @("--opencover",
"-i $outputLog",
"--repoToken $coverallsToken",
"--commitId $commitId",
"--commitBranch master",
"--commitAuthor `"$author`"",
"--commitEmail $email",
"--commitMessage `"$message`""
)

$coverallsParams | ForEach-Object { Write-LogPassThru -Message $_ }

Write-LogPassThru -Message "Uploading to CoverAlls"
& $coverallsExe """$coverallsParams"""

Write-LogPassThru -Message "Uploading to CodeCov"
if ( test-path $outputLog ) {
if ( Test-Path $outputLog ) {
ConvertTo-CodeCovJson -Path $outputLog -DestinationPath $jsonFile
Push-CodeCovData -file $jsonFile -CommitID $commitId -token $codecovToken -Branch 'master'

Expand All @@ -303,7 +325,7 @@ finally
{
# the powershell execution should be done, be sure that there are no PowerShell test executables running because
# they will cause subsequent coverage runs to behave poorly. Make sure that the path is properly formatted, and
# we need to use like rather than match because on Windows, there will be "\" as path separators which would need
# we need to use like rather than match because on Windows, there will be "\" as path separators which would need
# escaping for -match
$ResolvedPSBinPath = (Resolve-Path ${psbinpath}).Path
Get-Process PowerShell | Where-Object { $_.Path -like "*${ResolvedPSBinPath}*" } | Stop-Process -Force -ErrorAction Continue
Expand All @@ -328,4 +350,5 @@ finally
## Disable the cleanup till we stabilize.
#Remove-Item -recurse -force -path $outputBaseFolder
$ErrorActionPreference = $oldErrorActionPreference
$ProgressPreference = $oldProgressPreference
}
4 changes: 3 additions & 1 deletion test/tools/OpenCover/OpenCover.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,10 @@ function Invoke-OpenCover
# create the arguments for OpenCover

$updatedEnvPath = "${PowerShellExeDirectory}\Modules;$TestToolsModulesPath"
$testToolsExePath = (Resolve-Path(Join-Path $TestPath -ChildPath "..\tools\TestExe\bin")).Path
$updatedProcessEnvPath = "${testToolsExePath};${env:PATH}"

$startupArgs = "Set-ExecutionPolicy Bypass -Force -Scope Process; `$env:PSModulePath = '${updatedEnvPath}';"
$startupArgs = "Set-ExecutionPolicy Bypass -Force -Scope Process; `$env:PSModulePath = '${updatedEnvPath}'; `$env:Path = '${updatedProcessEnvPath}'"
$targetArgs = "${startupArgs}", "Invoke-Pester","${TestPath}","-OutputFormat $PesterLogFormat"

if ( $CIOnly )
Expand Down