initial commit

This commit is contained in:
Zachary Folwick 2015-07-15 10:15:39 -07:00
parent c33d976e9f
commit 868ea370d4
22 changed files with 333 additions and 0 deletions

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

View file

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

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

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

View file

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

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

View file

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

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

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

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

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,3 @@
function test-Get-Alias{
return Get-Alias a*
}

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