Merge pull request 72 from initialTestSuites into develop

This commit is contained in:
Zach Folwick 2015-07-16 23:14:28 +00:00
commit 68fa654813
24 changed files with 364 additions and 16 deletions

View File

@ -1,13 +0,0 @@
"starting test script" | out-host
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$here | out-host
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
$sut | out-host
. "$here\$sut"
Describe "Get-HelloWorld" {
It "outputs 'Hello world!'" {
Get-HelloWorld | Should Be 'Hello world!'
}
}

View File

@ -1,3 +0,0 @@
function Get-HelloWorld {
'Hello world!'
}

View File

@ -0,0 +1,19 @@
$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:HOME).Value | Should be "/root"
(Get-Item ENV:HOSTNAME).Value | Should Not BeNullOrEmpty
(Get-Item ENV:PATH).Value | Should Not BeNullOrEmpty
(ls ENV:HOME).Value | Should be "/root"
(ls ENV:HOSTNAME).Value | Should Not BeNullOrEmpty
(ls ENV:PATH).Value | Should Not BeNullOrEmpty
}
}

View File

@ -0,0 +1,3 @@
function Test-Environment-Variables {
}

View File

@ -0,0 +1,41 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
Describe "Get-Alias" {
It "Should have a return type of System.Array when gal returns more than one object" {
$val1=(Get-Alias a*)
$val2=(Get-Alias c*)
$i=0
$val1 | ForEach-Object{ $i++};
if($i -lt 2) {
$val1.GetType().BaseType.FullName | Should Be "System.Management.Automation.CommandInfo"
}
else {
$val1.GetType().BaseType.FullName | Should Be "System.Array"
}
$val2 | ForEach-Object{ $i++};
if($i -lt 2) {
$val2.GetType().BaseType.FullName | Should Be "System.Management.Automation.CommandInfo"
}
else {
$val2.GetType().BaseType.FullName | Should Be "System.Array"
}
}
It "should return an array of 3 objects" {
$val = Get-Alias a*
$alias = gal a*
$val.CommandType | Should Not BeNullOrEmpty
$val.Name | Should Not BeNullOrEmpty
$val.ModuleName | Should BeNullOrEmpty
$alias.CommandType | Should Not BeNullOrEmpty
$alias.Name | Should Not BeNullOrEmpty
$alias.ModuleName | Should BeNullOrEmpty
}
}

View File

@ -0,0 +1,3 @@
function test-Get-Alias{
return Get-Alias a*
}

View File

@ -0,0 +1,22 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
Describe "Test-Get-ChildItem" {
It "Should list the contents of the current folder" {
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
(ls .).Name.Length | Should BeGreaterThan 0
}
It "Should list the contents of the home directory" {
pushd /usr/
(Get-ChildItem .).Name.Length | Should BeGreaterThan 0
popd
pushd /usr/
(ls .).Name.Length | Should BeGreaterThan 0
popd
}
}

View File

@ -0,0 +1,3 @@
function Test-Get-ChildItem {
}

View File

@ -0,0 +1,30 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
Describe "Test-Get-Content" {
It "Should throw an error on a directory " {
# also tests that -erroraction SilentlyContinue will work.
Get-Content . -ErrorAction SilentlyContinue | Should Throw
cat . -ErrorAction SilentlyContinue | Should Throw
gc . -ErrorAction SilentlyContinue | Should Throw
type . -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"
(gc -Path .\Test-Get-Content.Tests.ps1).GetType().BaseType.Name | Should Be "Array"
(gc -Path .\Test-Get-Content.Tests.ps1)[0] |Should be "`$here = Split-Path -Parent `$MyInvocation.MyCommand.Path"
(type -Path .\Test-Get-Content.Tests.ps1).GetType().BaseType.Name | Should Be "Array"
(type -Path .\Test-Get-Content.Tests.ps1)[0] |Should be "`$here = Split-Path -Parent `$MyInvocation.MyCommand.Path"
(cat -Path .\Test-Get-Content.Tests.ps1).GetType().BaseType.Name | Should Be "Array"
(cat -Path .\Test-Get-Content.Tests.ps1)[0] |Should be "`$here = Split-Path -Parent `$MyInvocation.MyCommand.Path"
}
}

View File

@ -0,0 +1,3 @@
function Test-Get-Content {
}

View File

@ -0,0 +1,37 @@
$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 have colons when ToString method is used" {
(Get-Date).ToString().Contains(":") | Should be $true
(Get-Date -DisplayHint Time).ToString().Contains(":") | Should be $true
(Get-Date -DisplayHint Date).ToString().Contains(":") | Should be $true
}
It "Should be able to use the format flag" {
# You would think that one could use simple loops here, but apparently powershell in windows returns different values in loops
(Get-Date -Format d).Contains("/") | Should be $true
(Get-Date -Format D).Contains(",") | Should be $true
(Get-Date -Format f).Contains(",") -and (Get-Date -Format f).Contains(":") | Should be $true
(Get-Date -Format F).Contains(",") -and (Get-Date -Format F).Contains(":") | Should be $true
(Get-Date -Format g).Contains("/") -and (Get-Date -Format g).Contains(":") | Should be $true
(Get-Date -Format G).Contains("/") -and (Get-Date -Format G).Contains(":") | Should be $true
(Get-Date -Format m).Contains(",") -or `
(Get-Date -Format m).Contains(":") -or `
(Get-Date -Format m).Contains("/") | Should be $false
}
}

View File

@ -0,0 +1,3 @@
function Test-Get-Date {
}

View 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 'pester-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 /usr/bin) | Should Not BeNullOrEmpty
(Get-Item ..) | Should Not BeNullOrEmpty
}
}

View File

@ -0,0 +1,3 @@
function Test-Get-Item {
}

View 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)
}
}

View File

@ -0,0 +1,3 @@
function Test-Get-Location {
}

View 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
}
}

View File

@ -0,0 +1,3 @@
function Test-Get-Member {
}

View File

@ -0,0 +1,40 @@
$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"
}
It "Should return the name of the drive when the qualifier switch is used" {
Split-Path / -Qualifier | Should Be "/"
}
It "Should return the parent folder name when the leaf switch is used" {
Split-Path . -Leaf | Should be "pester-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 /usr/bin -IsAbsolute) |Should be $true
(Split-Path . -IsAbsolute) | Should be $false
}
It "Should support piping" {
("." | Split-Path -leaf) | Should Be "pester-tests"
}
}

View File

@ -0,0 +1,3 @@
function Test-Split-Path {
}

View 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"
}
}

View File

@ -0,0 +1,3 @@
function test-Add-Member {
}

View 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'
}
}

View File

@ -0,0 +1,3 @@
function test-New-Object {
}