initial commit
This commit is contained in:
parent
c33d976e9f
commit
868ea370d4
15
src/pester-tests/Test-Environment-Variables.Tests.ps1
Normal file
15
src/pester-tests/Test-Environment-Variables.Tests.ps1
Normal file
|
@ -0,0 +1,15 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Test-Environment-Variables" {
|
||||
It "Should have environment variable" {
|
||||
Get-Item ENV: | Should Not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Should be able to access the members of the environment variable in two ways" {
|
||||
(Get-Item ENV:os).Value | Should Match 'Windows' -or 'Linux'
|
||||
|
||||
$env:os | Should Match 'Windows' -or '*nux'
|
||||
}
|
||||
}
|
3
src/pester-tests/Test-Environment-Variables.ps1
Normal file
3
src/pester-tests/Test-Environment-Variables.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Test-Environment-Variables {
|
||||
|
||||
}
|
15
src/pester-tests/Test-Get-Alias.Tests.ps1
Normal file
15
src/pester-tests/Test-Get-Alias.Tests.ps1
Normal file
|
@ -0,0 +1,15 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = "test-" + (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Get-Alias" {
|
||||
It "should return 3 objects" {
|
||||
$val = Microsoft.PowerShell.Utility\Get-Alias a*
|
||||
$val.CommandType | Should Not BeNullOrEmpty
|
||||
$val.Name | Should Not BeNullOrEmpty
|
||||
$val.ModuleName | Should BeNullOrEmpty
|
||||
|
||||
$val.Name[0] | Should Be "ac"
|
||||
$val.Name[1] | Should Be "asnp"
|
||||
}
|
||||
}
|
36
src/pester-tests/Test-Get-ChildItem.Tests.ps1
Normal file
36
src/pester-tests/Test-Get-ChildItem.Tests.ps1
Normal file
|
@ -0,0 +1,36 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Test-Get-ChildItem" {
|
||||
Context ": non-aliased testing" {
|
||||
It "Should list the contents of the current folder" {
|
||||
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
|
||||
}
|
||||
|
||||
It "Should list the contents of the home directory" {
|
||||
pushd $HOME
|
||||
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
|
||||
popd
|
||||
}
|
||||
|
||||
}
|
||||
Context ": alias tests" {
|
||||
It "Should list the contents of the current folder" {
|
||||
(ls).Name.Length | Should BeGreaterThan 0
|
||||
}
|
||||
|
||||
It "Should list the contents of the home directory" {
|
||||
pushd $HOME
|
||||
(ls).Name.Length | Should BeGreaterThan 0
|
||||
popd
|
||||
}
|
||||
|
||||
It "Should list the contents of environment variables" {
|
||||
(ls ENV:).Count | Should BeGreaterThan 10
|
||||
(ls ENV:os).Value | Should Be (Get-ChildItem ENV:os).Value
|
||||
(ls ENV:PROCESSOR_ARCHITECTURE).Value | Should Be (Get-ChildItem ENV:PROCESSOR_ARCHITECTURE).Value
|
||||
(ls ENV:OS).Value | Should Be $env:OS
|
||||
}
|
||||
}
|
||||
}
|
3
src/pester-tests/Test-Get-ChildItem.ps1
Normal file
3
src/pester-tests/Test-Get-ChildItem.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Test-Get-ChildItem {
|
||||
|
||||
}
|
28
src/pester-tests/Test-Get-Content.Tests.ps1
Normal file
28
src/pester-tests/Test-Get-Content.Tests.ps1
Normal file
|
@ -0,0 +1,28 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Test-Get-Content" {
|
||||
<#
|
||||
Dependencies:
|
||||
1. mkdir
|
||||
#>
|
||||
It "Should throw an error on a directory " {
|
||||
# also tests that -erroraction SilentlyContinue will work.
|
||||
|
||||
Get-Content $HOME -ErrorAction SilentlyContinue| Should Throw
|
||||
cat $HOME -ErrorAction SilentlyContinue| Should Throw
|
||||
gc $HOME -ErrorAction SilentlyContinue| Should Throw
|
||||
|
||||
|
||||
}
|
||||
|
||||
It "Should deliver an array object when listing a file" {
|
||||
(Get-Content -Path .\Test-Get-Content.Tests.ps1).GetType().BaseType.Name | Should Be "Array"
|
||||
(Get-Content -Path .\Test-Get-Content.Tests.ps1)[0] |Should be "`$here = Split-Path -Parent `$MyInvocation.MyCommand.Path"
|
||||
}
|
||||
|
||||
It "Should support pipelines" {
|
||||
|
||||
}
|
||||
}
|
3
src/pester-tests/Test-Get-Content.ps1
Normal file
3
src/pester-tests/Test-Get-Content.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Test-Get-Content {
|
||||
|
||||
}
|
23
src/pester-tests/Test-Get-Dates.Tests.ps1
Normal file
23
src/pester-tests/Test-Get-Dates.Tests.ps1
Normal file
|
@ -0,0 +1,23 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Test-Get-Date" {
|
||||
<#
|
||||
1. foreach
|
||||
2.
|
||||
#>
|
||||
It "Should return a DateTime object upon being called" {
|
||||
(Get-Date).GetType().Name.Equals('DateTime') | Should Be $true
|
||||
}
|
||||
|
||||
It "Should filter properly when displayhint switch is used" {
|
||||
(Get-Date -DisplayHint Time).ToString().Contains(":") |Should be $true
|
||||
(Get-Date -DisplayHint Date).ToString().Contains(":") | Should be $false
|
||||
}
|
||||
|
||||
It "Should be able to pipe the output to another cmdlet" {
|
||||
$timestamp = Get-Date -Format o | foreach {$_ -replace ":", "."}
|
||||
$timestamp.ToString().Contains(":") | Should be $false
|
||||
}
|
||||
}
|
3
src/pester-tests/Test-Get-Dates.ps1
Normal file
3
src/pester-tests/Test-Get-Dates.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Test-Get-Date {
|
||||
|
||||
}
|
25
src/pester-tests/Test-Get-Item.Tests.ps1
Normal file
25
src/pester-tests/Test-Get-Item.Tests.ps1
Normal file
|
@ -0,0 +1,25 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Test-Get-Item" {
|
||||
It "Should list all the items in the current working directory when asterisk is used" {
|
||||
(Get-Item *).GetType().BaseType | Should Be 'array'
|
||||
(Get-Item *).GetType().Name | Should Be 'Object[]'
|
||||
}
|
||||
|
||||
It "Should return the name of the current working directory when a dot is used" {
|
||||
(Get-Item .).GetType().BaseType | Should Be 'System.IO.FileSystemInfo'
|
||||
(Get-Item .).Name | Should Be 'Tests'
|
||||
}
|
||||
|
||||
It "Should return the proper Name and BaseType for directory objects vs file system objects" {
|
||||
(Get-Item .).GetType().Name | Should Be 'DirectoryInfo'
|
||||
(Get-Item .\Test-Get-Item.Tests.ps1).GetType().Name | Should Be 'FileInfo'
|
||||
}
|
||||
|
||||
It "Should return a different directory when a path argument is used" {
|
||||
(Get-Item $HOME) | Should Not BeNullOrEmpty
|
||||
(Get-Item ..) | Should Not BeNullOrEmpty
|
||||
}
|
||||
}
|
3
src/pester-tests/Test-Get-Item.ps1
Normal file
3
src/pester-tests/Test-Get-Item.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Test-Get-Item {
|
||||
|
||||
}
|
29
src/pester-tests/Test-Get-Location.Tests.ps1
Normal file
29
src/pester-tests/Test-Get-Location.Tests.ps1
Normal file
|
@ -0,0 +1,29 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Test-Get-Location aka pwd" {
|
||||
<#Dependencies:
|
||||
pushd
|
||||
popd
|
||||
$HOME
|
||||
|
||||
#>
|
||||
$winHome = 'C:\Users\v-zafolw'
|
||||
$nixHome = '/home/zafolw'
|
||||
BeforeEach {
|
||||
pushd $HOME #on windows, this is c:\Users\XXXXX; for *nix, it's /home/XXXXX
|
||||
}
|
||||
|
||||
AfterEach { popd }
|
||||
|
||||
It "Should list the output of the current working directory" {
|
||||
(Get-Location).Path | Should Not BeNullOrEmpty
|
||||
(Get-Location).Path | Should Be ($winHome -or $nixHome)
|
||||
}
|
||||
|
||||
It "Should be able to use pwd the same way" {
|
||||
(pwd).Path | Should Not BeNullOrEmpty
|
||||
(pwd).Path | Should Be ($winHome -or $nixHome)
|
||||
}
|
||||
}
|
3
src/pester-tests/Test-Get-Location.ps1
Normal file
3
src/pester-tests/Test-Get-Location.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Test-Get-Location {
|
||||
|
||||
}
|
45
src/pester-tests/Test-Get-Member.Tests.ps1
Normal file
45
src/pester-tests/Test-Get-Member.Tests.ps1
Normal file
|
@ -0,0 +1,45 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Test-Get-Member" {
|
||||
It "Should be able to be called on string objects, ints, arrays, etc" {
|
||||
$a = 1 #test numbers
|
||||
$b = 1.3
|
||||
$c = $false #test bools
|
||||
$d = @(1,3) # test arrays
|
||||
$e = "anoeduntodeu" #test strings
|
||||
$f = 'asntoheusth' #test strings
|
||||
|
||||
Get-Member -InputObject $a | Should Not BeNullOrEmpty
|
||||
Get-Member -InputObject $b | Should Not BeNullOrEmpty
|
||||
Get-Member -InputObject $c | Should Not BeNullOrEmpty
|
||||
Get-Member -InputObject $d | Should Not BeNullOrEmpty
|
||||
Get-Member -InputObject $e | Should Not BeNullOrEmpty
|
||||
Get-Member -InputObject $f | Should Not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Should be able to extract a field from string objects, ints, arrays, etc" {
|
||||
$a = 1 #test numbers
|
||||
$b = 1.3
|
||||
$c = $false #test bools
|
||||
$d = @(1,3) # test arrays
|
||||
$e = "anoeduntodeu" #test strings
|
||||
$f = 'asntoheusth' #test strings
|
||||
|
||||
$a.GetType().Name | Should Be 'Int32'
|
||||
$b.GetType().Name | Should Be 'Double'
|
||||
$c.GetType().Name | Should Be 'Boolean'
|
||||
$d.GetType().Name | Should Be 'Object[]'
|
||||
$e.GetType().Name | Should Be 'String'
|
||||
$f.GetType().Name | Should Be 'String'
|
||||
}
|
||||
|
||||
It "Should be able to be called on a newly created PSObject" {
|
||||
$o = New-Object psobject
|
||||
# this creates a dependency on the Add-Member cmdlet.
|
||||
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
|
||||
|
||||
Get-Member -InputObject $o | Should Not BeNullOrEmpty
|
||||
}
|
||||
}
|
3
src/pester-tests/Test-Get-Member.ps1
Normal file
3
src/pester-tests/Test-Get-Member.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Test-Get-Member {
|
||||
|
||||
}
|
41
src/pester-tests/Test-Split-Path.Tests.ps1
Normal file
41
src/pester-tests/Test-Split-Path.Tests.ps1
Normal file
|
@ -0,0 +1,41 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "Test-Split-Path" {
|
||||
<#
|
||||
Dependencies:
|
||||
1. Split-Path - FUT
|
||||
2. ForEach
|
||||
3. Object piping
|
||||
4. ls/Get-ChildItem - filter output of ls
|
||||
|
||||
#>
|
||||
It "Should return a string object when invoked" {
|
||||
(Split-Path .).GetType().Name |Should Be "String"
|
||||
(Split-Path . -Leaf).GetType().Name | Should Be "String"
|
||||
(Split-Path . -Resolve).GetType().Name | Should Be "String"
|
||||
(Split-Path $HOME -Qualifier).GetType().Name | Should Be "String"
|
||||
}
|
||||
|
||||
It "Should return the name of the drive when the qualifier switch is used" {
|
||||
Split-Path $HOME -Qualifier | Should Be "C:"
|
||||
}
|
||||
|
||||
It "Should return the parent folder name when the leaf switch is used" {
|
||||
Split-Path . -Leaf | Should be "Tests"
|
||||
}
|
||||
|
||||
It "Should be able to accept regular expression input and output an array for multiple objects" {
|
||||
(Split-Path *Get*.ps1 -Leaf -Resolve).GetType().BaseType.Name | Should Be "Array"
|
||||
}
|
||||
|
||||
It "Should be able to tell if a given path is an absolute path" {
|
||||
(Split-Path $HOME -IsAbsolute) |Should be $true
|
||||
(Split-Path . -IsAbsolute) | Should be $false
|
||||
}
|
||||
|
||||
It "Should support piping" {
|
||||
($HOME | Split-Path) | Should Be "C:\Users"
|
||||
}
|
||||
}
|
3
src/pester-tests/Test-Split-Path.ps1
Normal file
3
src/pester-tests/Test-Split-Path.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function Test-Split-Path {
|
||||
|
||||
}
|
23
src/pester-tests/test-Add-Member.Tests.ps1
Normal file
23
src/pester-tests/test-Add-Member.Tests.ps1
Normal file
|
@ -0,0 +1,23 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "test-Add-Member" {
|
||||
|
||||
It "should be able to see a newly added member of an object" {
|
||||
$o = New-Object psobject
|
||||
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
|
||||
|
||||
$o.proppy | Should Not BeNullOrEmpty
|
||||
$o.proppy | Should Be "superVal"
|
||||
}
|
||||
|
||||
It "Should be able to add a member to an object that already has a member in it" {
|
||||
$o = New-Object psobject
|
||||
Add-Member -InputObject $o -MemberType NoteProperty -Name proppy -Value "superVal"
|
||||
Add-Member -InputObject $o -MemberType NoteProperty -Name AnotherMember -Value "AnotherValue"
|
||||
|
||||
$o.AnotherMember | Should Not BeNullOrEmpty
|
||||
$o.AnotherMember | Should Be "AnotherValue"
|
||||
}
|
||||
}
|
3
src/pester-tests/test-Add-Member.ps1
Normal file
3
src/pester-tests/test-Add-Member.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function test-Add-Member {
|
||||
|
||||
}
|
3
src/pester-tests/test-Get-Alias.ps1
Normal file
3
src/pester-tests/test-Get-Alias.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function test-Get-Alias{
|
||||
return Get-Alias a*
|
||||
}
|
20
src/pester-tests/test-New-Object.Tests.ps1
Normal file
20
src/pester-tests/test-New-Object.Tests.ps1
Normal file
|
@ -0,0 +1,20 @@
|
|||
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
|
||||
. "$here\$sut"
|
||||
|
||||
Describe "New-Object" {
|
||||
It "should create an object with 4 fields" {
|
||||
$o = New-Object psobject
|
||||
$val = $o.GetType()
|
||||
|
||||
$val.IsPublic | Should Not BeNullOrEmpty
|
||||
$val.Name | Should Not BeNullOrEmpty
|
||||
$val.IsSerializable | Should Not BeNullOrEmpty
|
||||
$val.BaseType | Should Not BeNullOrEmpty
|
||||
|
||||
$val.IsPublic | Should Be $true
|
||||
$val.IsSerializable | Should Be $false
|
||||
$val.Name | Should Be 'PSCustomObject'
|
||||
$val.BaseType | Should Be 'System.Object'
|
||||
}
|
||||
}
|
3
src/pester-tests/test-New-Object.ps1
Normal file
3
src/pester-tests/test-New-Object.ps1
Normal file
|
@ -0,0 +1,3 @@
|
|||
function test-New-Object {
|
||||
|
||||
}
|
Loading…
Reference in a new issue