diff --git a/src/pester-tests/Get-HelloWorld.Tests.ps1 b/src/pester-tests/Get-HelloWorld.Tests.ps1 deleted file mode 100644 index eac96930e6..0000000000 --- a/src/pester-tests/Get-HelloWorld.Tests.ps1 +++ /dev/null @@ -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!' - } -} diff --git a/src/pester-tests/Get-HelloWorld.ps1 b/src/pester-tests/Get-HelloWorld.ps1 deleted file mode 100644 index c89b09a965..0000000000 --- a/src/pester-tests/Get-HelloWorld.ps1 +++ /dev/null @@ -1,3 +0,0 @@ -function Get-HelloWorld { - 'Hello world!' -} diff --git a/src/pester-tests/Test-Environment-Variables.Tests.ps1 b/src/pester-tests/Test-Environment-Variables.Tests.ps1 new file mode 100644 index 0000000000..3be444e566 --- /dev/null +++ b/src/pester-tests/Test-Environment-Variables.Tests.ps1 @@ -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 + } +} diff --git a/src/pester-tests/Test-Environment-Variables.ps1 b/src/pester-tests/Test-Environment-Variables.ps1 new file mode 100644 index 0000000000..983948f242 --- /dev/null +++ b/src/pester-tests/Test-Environment-Variables.ps1 @@ -0,0 +1,3 @@ +function Test-Environment-Variables { + +} diff --git a/src/pester-tests/Test-Get-Alias.Tests.ps1 b/src/pester-tests/Test-Get-Alias.Tests.ps1 new file mode 100644 index 0000000000..b34e52f030 --- /dev/null +++ b/src/pester-tests/Test-Get-Alias.Tests.ps1 @@ -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 + } +} diff --git a/src/pester-tests/Test-Get-Alias.ps1 b/src/pester-tests/Test-Get-Alias.ps1 new file mode 100644 index 0000000000..9bdc128b77 --- /dev/null +++ b/src/pester-tests/Test-Get-Alias.ps1 @@ -0,0 +1,3 @@ +function test-Get-Alias{ + return Get-Alias a* +} \ No newline at end of file diff --git a/src/pester-tests/Test-Get-ChildItem.Tests.ps1 b/src/pester-tests/Test-Get-ChildItem.Tests.ps1 new file mode 100644 index 0000000000..77d34e1a69 --- /dev/null +++ b/src/pester-tests/Test-Get-ChildItem.Tests.ps1 @@ -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 + + } +} diff --git a/src/pester-tests/Test-Get-ChildItem.ps1 b/src/pester-tests/Test-Get-ChildItem.ps1 new file mode 100644 index 0000000000..21395e4bb0 --- /dev/null +++ b/src/pester-tests/Test-Get-ChildItem.ps1 @@ -0,0 +1,3 @@ +function Test-Get-ChildItem { + +} diff --git a/src/pester-tests/Test-Get-Content.Tests.ps1 b/src/pester-tests/Test-Get-Content.Tests.ps1 new file mode 100644 index 0000000000..0cb48aeea0 --- /dev/null +++ b/src/pester-tests/Test-Get-Content.Tests.ps1 @@ -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" + + } +} diff --git a/src/pester-tests/Test-Get-Content.ps1 b/src/pester-tests/Test-Get-Content.ps1 new file mode 100644 index 0000000000..690b9a05fb --- /dev/null +++ b/src/pester-tests/Test-Get-Content.ps1 @@ -0,0 +1,3 @@ +function Test-Get-Content { + +} diff --git a/src/pester-tests/Test-Get-Dates.Tests.ps1 b/src/pester-tests/Test-Get-Dates.Tests.ps1 new file mode 100644 index 0000000000..1efa3eccd2 --- /dev/null +++ b/src/pester-tests/Test-Get-Dates.Tests.ps1 @@ -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 + + + } + +} + diff --git a/src/pester-tests/Test-Get-Dates.ps1 b/src/pester-tests/Test-Get-Dates.ps1 new file mode 100644 index 0000000000..3809810e04 --- /dev/null +++ b/src/pester-tests/Test-Get-Dates.ps1 @@ -0,0 +1,3 @@ +function Test-Get-Date { + +} diff --git a/src/pester-tests/Test-Get-Item.Tests.ps1 b/src/pester-tests/Test-Get-Item.Tests.ps1 new file mode 100644 index 0000000000..ede9928b1d --- /dev/null +++ b/src/pester-tests/Test-Get-Item.Tests.ps1 @@ -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 + } +} diff --git a/src/pester-tests/Test-Get-Item.ps1 b/src/pester-tests/Test-Get-Item.ps1 new file mode 100644 index 0000000000..08164c80e5 --- /dev/null +++ b/src/pester-tests/Test-Get-Item.ps1 @@ -0,0 +1,3 @@ +function Test-Get-Item { + +} diff --git a/src/pester-tests/Test-Get-Location.Tests.ps1 b/src/pester-tests/Test-Get-Location.Tests.ps1 new file mode 100644 index 0000000000..e345fb20cd --- /dev/null +++ b/src/pester-tests/Test-Get-Location.Tests.ps1 @@ -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) + } +} diff --git a/src/pester-tests/Test-Get-Location.ps1 b/src/pester-tests/Test-Get-Location.ps1 new file mode 100644 index 0000000000..cdea068ea4 --- /dev/null +++ b/src/pester-tests/Test-Get-Location.ps1 @@ -0,0 +1,3 @@ +function Test-Get-Location { + +} diff --git a/src/pester-tests/Test-Get-Member.Tests.ps1 b/src/pester-tests/Test-Get-Member.Tests.ps1 new file mode 100644 index 0000000000..54605aade2 --- /dev/null +++ b/src/pester-tests/Test-Get-Member.Tests.ps1 @@ -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 + } +} diff --git a/src/pester-tests/Test-Get-Member.ps1 b/src/pester-tests/Test-Get-Member.ps1 new file mode 100644 index 0000000000..4315e54a66 --- /dev/null +++ b/src/pester-tests/Test-Get-Member.ps1 @@ -0,0 +1,3 @@ +function Test-Get-Member { + +} diff --git a/src/pester-tests/Test-Split-Path.Tests.ps1 b/src/pester-tests/Test-Split-Path.Tests.ps1 new file mode 100644 index 0000000000..2cd5ca2f58 --- /dev/null +++ b/src/pester-tests/Test-Split-Path.Tests.ps1 @@ -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" + } +} diff --git a/src/pester-tests/Test-Split-Path.ps1 b/src/pester-tests/Test-Split-Path.ps1 new file mode 100644 index 0000000000..40781d6a59 --- /dev/null +++ b/src/pester-tests/Test-Split-Path.ps1 @@ -0,0 +1,3 @@ +function Test-Split-Path { + +} diff --git a/src/pester-tests/test-Add-Member.Tests.ps1 b/src/pester-tests/test-Add-Member.Tests.ps1 new file mode 100644 index 0000000000..4c4c4ea0ac --- /dev/null +++ b/src/pester-tests/test-Add-Member.Tests.ps1 @@ -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" + } +} diff --git a/src/pester-tests/test-Add-Member.ps1 b/src/pester-tests/test-Add-Member.ps1 new file mode 100644 index 0000000000..1eb9372f88 --- /dev/null +++ b/src/pester-tests/test-Add-Member.ps1 @@ -0,0 +1,3 @@ +function test-Add-Member { + +} diff --git a/src/pester-tests/test-New-Object.Tests.ps1 b/src/pester-tests/test-New-Object.Tests.ps1 new file mode 100644 index 0000000000..ea7cc516ce --- /dev/null +++ b/src/pester-tests/test-New-Object.Tests.ps1 @@ -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' + } +} diff --git a/src/pester-tests/test-New-Object.ps1 b/src/pester-tests/test-New-Object.ps1 new file mode 100644 index 0000000000..13397b05a3 --- /dev/null +++ b/src/pester-tests/test-New-Object.ps1 @@ -0,0 +1,3 @@ +function test-New-Object { + +}