Merge branch 'develop' into dev/measure-object
This commit is contained in:
commit
e10b129aac
@ -40,8 +40,15 @@ monad-impersonate()
|
||||
local CUSER=$(id -un)
|
||||
local CGID=$(id -g)
|
||||
local CGROUP=$(id -gn)
|
||||
# default docker-machine VM does not change
|
||||
if [[ $OSTYPE == darwin* ]]; then
|
||||
CUID=1000
|
||||
CUSER=docker
|
||||
CGID=50
|
||||
CGROUP=staff
|
||||
fi
|
||||
echo \
|
||||
groupadd -g $CGID $CGROUP '&&' \
|
||||
groupadd -o -f -g $CGID $CGROUP '&&' \
|
||||
useradd -u $CUID -g $CGID -d /opt $CUSER '&&' \
|
||||
sudo --set-home -u $CUSER -g $CGROUP --
|
||||
}
|
||||
|
@ -417,7 +417,7 @@ namespace Microsoft.Samples.PowerShell.Host
|
||||
|
||||
// Read commands and run them until the ShouldExit flag is set by
|
||||
// the user calling "exit".
|
||||
while (!this.ShouldExit)
|
||||
while (!this.ShouldExit && this.myHost.Runspace != null)
|
||||
{
|
||||
string prompt = Prompt(this.myHost.Runspace);
|
||||
|
||||
|
11
src/pester-tests/ConvertTo-SecureString.Tests.ps1
Normal file
11
src/pester-tests/ConvertTo-SecureString.Tests.ps1
Normal file
@ -0,0 +1,11 @@
|
||||
Describe "ConvertTo-SecureString" {
|
||||
|
||||
Context "Checking return types of ConvertTo-SecureString" {
|
||||
|
||||
It "Should return System.Security.SecureString after converting plaintext variable"{
|
||||
$PesterTestConvert = (ConvertTo-SecureString "plaintextpester" -AsPlainText -force)
|
||||
($PesterTestConvert).GetType() | Should Be securestring
|
||||
|
||||
}
|
||||
}
|
||||
}
|
25
src/pester-tests/Export-FormatData.Tests.ps1
Normal file
25
src/pester-tests/Export-FormatData.Tests.ps1
Normal file
@ -0,0 +1,25 @@
|
||||
Describe "Export-FormatData" {
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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 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
|
||||
}
|
||||
}
|
||||
}
|
35
src/pester-tests/Format-Custom.Tests.ps1
Normal file
35
src/pester-tests/Format-Custom.Tests.ps1
Normal file
@ -0,0 +1,35 @@
|
||||
Describe "Format-Custom" {
|
||||
|
||||
Context "Check Format-Custom can be called validly." {
|
||||
It "Should be able to be called without error" {
|
||||
{ Get-FormatData | Format-Custom } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should be able to call the fc alias without error" {
|
||||
{ Get-FormatData | fc } | Should Not Throw
|
||||
}
|
||||
}
|
||||
|
||||
Context "Check Format-Custom aliases" {
|
||||
|
||||
It "Should have the same output between the alias and the unaliased function" {
|
||||
$nonaliased = Get-FormatData | Format-Custom
|
||||
$aliased = Get-FormatData | fc
|
||||
$($nonaliased | Out-String).CompareTo($($aliased | Out-String)) | Should Be 0
|
||||
}
|
||||
}
|
||||
|
||||
Context "Check specific flags on Format-Custom" {
|
||||
|
||||
It "Should be able to specify the depth in output" {
|
||||
$getprocesspester = Get-FormatData | Format-Custom -depth 1
|
||||
($getprocesspester).Count | Should BeGreaterThan 0
|
||||
}
|
||||
|
||||
It "Should be able to use the Property flag to select properties" {
|
||||
$ProcessName = Get-Process | Format-Custom -Property "Name"
|
||||
$ProcessName | Should Not Match "Handle"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
30
src/pester-tests/Get-EventSubscriber.Tests.ps1
Normal file
30
src/pester-tests/Get-EventSubscriber.Tests.ps1
Normal file
@ -0,0 +1,30 @@
|
||||
Describe "Get-EventSubscriber" {
|
||||
|
||||
AfterEach {
|
||||
Unregister-Event -SourceIdentifier PesterTestRegister -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
Context "Check return type of Get-EventSubscriber" {
|
||||
|
||||
It "Should return System.Management.Automation.PSEventSubscriber as return type of New-Event" {
|
||||
$pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object])
|
||||
Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister
|
||||
(Get-EventSubscriber).GetType() | Should Be System.Management.Automation.PSEventSubscriber
|
||||
}
|
||||
}
|
||||
|
||||
Context "Check Get-EventSubscriber can validly register events"{
|
||||
It "Should return source identifier of PesterTimer " {
|
||||
$pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object])
|
||||
Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister
|
||||
(Get-EventSubscriber -SourceIdentifier PesterTestRegister).SourceIdentifier | Should Be "PesterTestRegister"
|
||||
}
|
||||
|
||||
It "Should return an integer greater than 0 for the SubscriptionId" {
|
||||
$pesterobject = (New-Object System.Collections.ObjectModel.ObservableCollection[object])
|
||||
Register-ObjectEvent -InputObject $pesterobject -EventName CollectionChanged -SourceIdentifier PesterTestRegister
|
||||
(Get-EventSubscriber -SourceIdentifier PesterTestRegister).SubscriptionId | Should BeGreaterThan 0
|
||||
|
||||
}
|
||||
}
|
||||
}
|
10
src/pester-tests/Get-ExecutionPolicy.Tests.ps1
Normal file
10
src/pester-tests/Get-ExecutionPolicy.Tests.ps1
Normal file
@ -0,0 +1,10 @@
|
||||
Describe "Get-ExecutionPolicy"{
|
||||
|
||||
Context "Check return type of Get-ExecutionPolicy"{
|
||||
|
||||
It "Should return Microsoft.Powershell.ExecutionPolicy PSObject"{
|
||||
(Get-ExecutionPolicy).GetType() | Should Be Microsoft.Powershell.ExecutionPolicy
|
||||
}
|
||||
|
||||
}
|
||||
}
|
13
src/pester-tests/Get-FormatData.Tests.ps1
Normal file
13
src/pester-tests/Get-FormatData.Tests.ps1
Normal file
@ -0,0 +1,13 @@
|
||||
Describe "Get-FormatData" {
|
||||
|
||||
Context "Check return type of Get-FormatData" {
|
||||
|
||||
It "Should return an object[] as the return type" {
|
||||
(Get-FormatData).GetType() | Should be System.Object[]
|
||||
}
|
||||
|
||||
It "Should return a System.Object[] with a count greater than 0" {
|
||||
(Get-formatData).Count | Should BeGreaterThan 0
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
}
|
||||
It "Should return a random number less than 100 " {
|
||||
Get-Random -Maximum 100 | Should BeLessThan 100
|
||||
Get-Random -Maximum 100 | Should BeGreaterThan 0
|
||||
Get-Random -Maximum 100 | Should BeGreaterThan -1
|
||||
}
|
||||
|
||||
It "Should return a random number less than 100 and greater than -100 " {
|
||||
|
17
src/pester-tests/Get-TypeData.Tests.ps1
Normal file
17
src/pester-tests/Get-TypeData.Tests.ps1
Normal file
@ -0,0 +1,17 @@
|
||||
Describe "Get-TypeData" {
|
||||
It "Should be able to call Get-TypeData with no arguments without throwing" {
|
||||
{ Get-TypeData } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should return an array of several elements when no arguments are used" {
|
||||
$output = Get-TypeData
|
||||
|
||||
$output.Length | Should BeGreaterThan 1
|
||||
}
|
||||
|
||||
It "Should be able to take wildcard input" {
|
||||
$output = Get-TypeData *Sys*
|
||||
|
||||
$output.Length | Should BeGreaterThan 1
|
||||
}
|
||||
}
|
23
src/pester-tests/New-Event.Tests.ps1
Normal file
23
src/pester-tests/New-Event.Tests.ps1
Normal file
@ -0,0 +1,23 @@
|
||||
Describe "New-Event" {
|
||||
|
||||
Context "Check return type of New-Event" {
|
||||
|
||||
It "Should return PSEventArgs as return type of New-Event" {
|
||||
(New-Event -SourceIdentifier a).GetType() | Should Be System.Management.Automation.PSEventArgs
|
||||
}
|
||||
}
|
||||
|
||||
Context "Check New-Event can register an event"{
|
||||
It "Should return PesterTestMessage as the MessageData" {
|
||||
(New-Event -sourceidentifier PesterTimer -sender windows.timer -messagedata "PesterTestMessage")
|
||||
(Get-Event -SourceIdentifier PesterTimer).MessageData | Should Be "PesterTestMessage"
|
||||
Remove-Event -sourceidentifier PesterTimer
|
||||
}
|
||||
|
||||
It "Should return Sender as windows.timer" {
|
||||
(New-Event -sourceidentifier PesterTimer -sender windows.timer -messagedata "PesterTestMessage")
|
||||
(Get-Event -SourceIdentifier PesterTimer).Sender | Should be windows.timer
|
||||
Remove-Event -sourceIdentifier PesterTimer
|
||||
}
|
||||
}
|
||||
}
|
44
src/pester-tests/Out-String.Tests.ps1
Normal file
44
src/pester-tests/Out-String.Tests.ps1
Normal file
@ -0,0 +1,44 @@
|
||||
Describe "Out-String" {
|
||||
if (Test-Path /tmp)
|
||||
{
|
||||
$nl = "`n"
|
||||
}
|
||||
else
|
||||
{
|
||||
$nl = "`r`n"
|
||||
}
|
||||
|
||||
It "Should accumulate the strings and returns them as a single string" {
|
||||
$testArray = "a", " b"
|
||||
|
||||
$testArray.GetType().BaseType | Should Be array
|
||||
|
||||
$testArray | Out-String | Should Be "a$nl b$nl"
|
||||
|
||||
$($testArray | Out-String).GetType() | Should Be string
|
||||
}
|
||||
|
||||
It "Should be able to return an array of strings using the stream switch" {
|
||||
$testInput = "a", "b"
|
||||
|
||||
$($testInput | Out-String).GetType() | Should Be string
|
||||
|
||||
$($testInput | Out-String -Stream).GetType().BaseType.Name | Should Be array
|
||||
}
|
||||
|
||||
It "Should send all objects through a pipeline when not using the stream switch" {
|
||||
$testInput = "a", "b"
|
||||
$streamoutputlength = $($testInput | Out-String -Stream).Length
|
||||
$nonstreamoutputlength = $($testInput | Out-String).Length
|
||||
|
||||
$nonstreamoutputlength| Should BeGreaterThan $streamoutputlength
|
||||
}
|
||||
|
||||
It "Should send a single object through a pipeline when the stream switch is used" {
|
||||
$testInput = "a", "b"
|
||||
$streamoutputlength = $($testInput | Out-String -Stream).Length
|
||||
$nonstreamoutputlength = $($testInput | Out-String).Length
|
||||
|
||||
$streamoutputlength | Should BeLessThan $nonstreamoutputlength
|
||||
}
|
||||
}
|
104
src/pester-tests/Start-Process.Tests.ps1
Normal file
104
src/pester-tests/Start-Process.Tests.ps1
Normal file
@ -0,0 +1,104 @@
|
||||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
. $here/Test-Common.ps1
|
||||
|
||||
Describe "Start-Process" {
|
||||
$pingCommand = (Get-Command -CommandType Application ping)[0].Definition
|
||||
$pingDirectory = Split-Path $pingCommand -Parent
|
||||
$tempDir = GetTempDir
|
||||
$tempFile = $tempDir + "PSTest"
|
||||
$assetsFile = $here + "/assets/SortTest.txt"
|
||||
$windows = IsWindows
|
||||
if ($windows)
|
||||
{
|
||||
$pingParamNoStop = "localhost -t"
|
||||
$pingParamStop = "localhost -n 2"
|
||||
}
|
||||
else
|
||||
{
|
||||
$pingParamNoStop = "localhost"
|
||||
$pingParamStop = "localhost -c 2"
|
||||
}
|
||||
|
||||
AfterEach {
|
||||
Stop-Process -Name ping -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
It "Should start a process without error" {
|
||||
{ Start-Process ping } | Should Not Throw
|
||||
}
|
||||
|
||||
It "Should process arguments without error" {
|
||||
{ Start-Process ping -ArgumentList $pingParamNoStop} | Should Not Throw
|
||||
|
||||
$process = Get-Process -Name ping
|
||||
|
||||
$process.Length | Should Be 1
|
||||
$process.Id | Should BeGreaterThan 1
|
||||
$process.ProcessName | Should Be "ping"
|
||||
}
|
||||
|
||||
It "Should create process object when used with PassThru argument" {
|
||||
$process = Start-Process ping -ArgumentList $pingParamNoStop -PassThru
|
||||
|
||||
$process.Length | Should Be 1
|
||||
$process.Id | Should BeGreaterThan 1
|
||||
$process.ProcessName | Should Be "ping"
|
||||
}
|
||||
|
||||
It "Should work correctly when used with full path name" {
|
||||
$process = Start-Process $pingCommand -ArgumentList $pingParamNoStop -PassThru
|
||||
|
||||
$process.Length | Should Be 1
|
||||
$process.Id | Should BeGreaterThan 1
|
||||
$process.ProcessName | Should Be "ping"
|
||||
}
|
||||
|
||||
It "Should invoke correct path when used with FilePath argument" {
|
||||
$process = Start-Process -FilePath $pingCommand -ArgumentList $pingParamNoStop -PassThru
|
||||
|
||||
$process.Length | Should Be 1
|
||||
$process.Id | Should BeGreaterThan 1
|
||||
$process.ProcessName | Should Be "ping"
|
||||
}
|
||||
|
||||
It "Should wait for command completion if used with Wait argument" {
|
||||
Start-Process ping -ArgumentList $pingParamStop -Wait
|
||||
|
||||
$process = Get-Process -Name ping -ErrorAction SilentlyContinue
|
||||
|
||||
$process.Length | Should Be 0
|
||||
}
|
||||
|
||||
It "Should work correctly with WorkingDirectory argument" {
|
||||
$process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParamNoStop -PassThru
|
||||
|
||||
$process.Length | Should Be 1
|
||||
$process.Id | Should BeGreaterThan 1
|
||||
$process.ProcessName | Should Be "ping"
|
||||
}
|
||||
|
||||
It "Should should handle stderr redirection without error" {
|
||||
$process = Start-Process ping -ArgumentList $pingParamNoStop -PassThru -RedirectStandardError $tempFile
|
||||
|
||||
$process.Length | Should Be 1
|
||||
$process.Id | Should BeGreaterThan 1
|
||||
$process.ProcessName | Should Be "ping"
|
||||
}
|
||||
|
||||
It "Should should handle stdout redirection without error" {
|
||||
$process = Start-Process ping -ArgumentList $pingParamStop -Wait -RedirectStandardOutput $tempFile
|
||||
$dirEntry = dir $tempFile
|
||||
|
||||
$dirEntry.Length | Should BeGreaterThan 0
|
||||
}
|
||||
|
||||
It "Should should handle stdin redirection without error" {
|
||||
$process = Start-Process sort -Wait -RedirectStandardOutput $tempFile -RedirectStandardInput $assetsFile
|
||||
$dirEntry = dir $tempFile
|
||||
|
||||
$dirEntry.Length | Should BeGreaterThan 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
22
src/pester-tests/Test-Common.ps1
Normal file
22
src/pester-tests/Test-Common.ps1
Normal file
@ -0,0 +1,22 @@
|
||||
Function IsWindows
|
||||
{
|
||||
$pingCommand = Get-Command -CommandType Application ping
|
||||
if ($pingCommand.Definition.IndexOf("\\") -ne -1)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Function GetTempDir
|
||||
{
|
||||
if (IsWindows)
|
||||
{
|
||||
return $env:TEMP
|
||||
}
|
||||
else
|
||||
{
|
||||
return "/tmp/"
|
||||
}
|
||||
}
|
||||
|
5
src/pester-tests/assets/SortTest.txt
Normal file
5
src/pester-tests/assets/SortTest.txt
Normal file
@ -0,0 +1,5 @@
|
||||
5
|
||||
10
|
||||
3
|
||||
4
|
||||
8
|
Loading…
Reference in New Issue
Block a user