Skip to content

Commit

Permalink
Fix #1 Added lib folder with requried module
Browse files Browse the repository at this point in the history
  • Loading branch information
DexterPOSH committed Jun 17, 2016
1 parent d34412f commit b3ca33b
Show file tree
Hide file tree
Showing 87 changed files with 11,173 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$here\Add-Numbers.ps1"

Describe -Tags "Example" "Add-Numbers" {

It "adds positive numbers" {
Add-Numbers 2 3 | Should Be 5
}

It "adds negative numbers" {
Add-Numbers (-2) (-2) | Should Be (-4)
}

It "adds one negative number to positive number" {
Add-Numbers (-2) 2 | Should Be 0
}

It "concatenates strings if given strings" {
Add-Numbers two three | Should Be "twothree"
}

It "should not be 0" {
Add-Numbers 2 3 | Should Not Be 0
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function Add-Numbers($a, $b) {
return $a + $b
}
36 changes: 36 additions & 0 deletions Remotely/lib/Pester_3.3.14/Examples/Validator/Validator.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

function MyValidator($thing_to_validate) {
return $thing_to_validate.StartsWith("s")
}

function Invoke-SomethingThatUsesMyValidator {
param(
[ValidateScript({MyValidator $_})]
$some_param
)
}

Describe "Testing a validator" {

It "calls MyValidator" {
Mock MyValidator -MockWith { return $true }
Invoke-SomethingThatUsesMyValidator "test"
$was_called_once = 1
Assert-MockCalled MyValidator $was_called_once
}

}

Describe "MyValidator" {

It "passes things that start with the letter S" {
$result = MyValidator "summer"
$result | Should Be $true
}

It "does not pass a param that does not start with S" {
$result = MyValidator "bummer"
$result | Should Be $false
}
}

76 changes: 76 additions & 0 deletions Remotely/lib/Pester_3.3.14/Functions/Assertions/Be.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Set-StrictMode -Version Latest

InModuleScope Pester {
Describe "PesterBe" {
It "returns true if the 2 arguments are equal" {
Test-PositiveAssertion (PesterBe 1 1)
}
It "returns true if the 2 arguments are equal and have different case" {
Test-PositiveAssertion (PesterBe "A" "a")
}

It "returns false if the 2 arguments are not equal" {
Test-NegativeAssertion (PesterBe 1 2)
}
}
Describe "PesterBeFailureMessage" {
#the correctness of difference index value and the arrow pointing to the correct place
#are not tested here thoroughly, but the behaviour was visually checked and is
#implicitly tested by using the whole output in the following tests


It "Returns nothing for two identical strings" {
#this situation should actually never happen, as the code is called
#only when the objects are not equal

$string = "string"
PesterBeFailureMessage $string $string | Should BeNullOrEmpty
}

It "Outputs less verbose message for two different objects that are not strings" {
PesterBeFailureMessage 2 1 | Should Be "Expected: {1}`nBut was: {2}"
}

It "Outputs verbose message for two strings of different length" {
PesterBeFailureMessage "actual" "expected" | Should Be "Expected string length 8 but was 6. Strings differ at index 0.`nExpected: {expected}`nBut was: {actual}`n-----------^"
}

It "Outputs verbose message for two different strings of the same length" {
PesterBeFailureMessage "x" "y" | Should Be "String lengths are both 1. Strings differ at index 0.`nExpected: {y}`nBut was: {x}`n-----------^"
}

It "Replaces non-printable characters correctly" {
PesterBeFailureMessage "`n`r`b`0`tx" "`n`r`b`0`ty" | Should Be "String lengths are both 6. Strings differ at index 5.`nExpected: {\n\r\b\0\ty}`nBut was: {\n\r\b\0\tx}`n---------------------^"
}

It "The arrow points to the correct position when non-printable characters are replaced before the difference" {
PesterBeFailureMessage "123`n456" "123`n789" | Should Be "String lengths are both 7. Strings differ at index 4.`nExpected: {123\n789}`nBut was: {123\n456}`n----------------^"
}

It "The arrow points to the correct position when non-printable characters are replaced after the difference" {
PesterBeFailureMessage "abcd`n123" "abc!`n123" | Should Be "String lengths are both 8. Strings differ at index 3.`nExpected: {abc!\n123}`nBut was: {abcd\n123}`n--------------^"
}
}
}

InModuleScope Pester {
Describe "BeExactly" {
It "passes if letter case matches" {
'a' | Should BeExactly 'a'
}
It "fails if letter case doesn't match" {
'A' | Should Not BeExactly 'a'
}
It "passes for numbers" {
1 | Should BeExactly 1
2.15 | Should BeExactly 2.15
}
}

Describe "PesterBeExactlyFailureMessage" {
It "Writes verbose message for strings that differ by case" {
PesterBeExactlyFailureMessage "a" "A" | Should Be "String lengths are both 1. Strings differ at index 0.`nExpected: {A}`nBut was: {a}`n-----------^"
}
}
}

115 changes: 115 additions & 0 deletions Remotely/lib/Pester_3.3.14/Functions/Assertions/Be.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#Be
function PesterBe($value, $expected) {
return ($expected -eq $value)
}

function PesterBeFailureMessage($value, $expected) {
if (-not (($expected -is [string]) -and ($value -is [string])))
{
return "Expected: {$expected}`nBut was: {$value}"
}
<#joining the output strings to a single string here, otherwise I get
Cannot find an overload for "Exception" and the argument count: "4".
at line: 63 in C:\Users\nohwnd\github\pester\Functions\Assertions\Should.ps1
This is a quickwin solution, doing the join in the Should directly might be better
way of doing this. But I don't want to mix two problems.
#>
( Get-CompareStringMessage -Expected $expected -Actual $value ) -join "`n"
}

function NotPesterBeFailureMessage($value, $expected) {
return "Expected: value was {$value}, but should not have been the same"
}

#BeExactly
function PesterBeExactly($value, $expected) {
return ($expected -ceq $value)
}

function PesterBeExactlyFailureMessage($value, $expected) {
if (-not (($expected -is [string]) -and ($value -is [string])))
{
return "Expected exactly: {$expected}`nBut was: {$value}"
}
<#joining the output strings to a single string here, otherwise I get
Cannot find an overload for "Exception" and the argument count: "4".
at line: 63 in C:\Users\nohwnd\github\pester\Functions\Assertions\Should.ps1
This is a quickwin solution, doing the join in the Should directly might be better
way of doing this. But I don't want to mix two problems.
#>
( Get-CompareStringMessage -Expected $expected -Actual $value -CaseSensitive ) -join "`n"
}

function NotPesterBeExactlyFailureMessage($value, $expected) {
return "Expected: value was {$value}, but should not have been exactly the same"
}

#common functions
function Get-CompareStringMessage {
param(
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$Expected,
[Parameter(Mandatory=$true)]
[AllowEmptyString()]
[String]$Actual,
[switch]$CaseSensitive
)

$expectedLength = $expected.Length
$actualLength = $actual.Length
$maxLength = $expectedLength,$actualLength | & $SafeCommands['Sort-Object'] -Descending | & $SafeCommands['Select-Object'] -First 1

$differenceIndex = $null
for ($i = 0; $i -lt $maxLength -and ($null -eq $differenceIndex); ++$i){
$differenceIndex = if ($CaseSensitive -and ($expected[$i] -cne $actual[$i]))
{
$i
}
elseif ($expected[$i] -ne $actual[$i])
{
$i
}
}

[string]$output = $null
if ($null -ne $differenceIndex)
{
if ($expected.Length -ne $actual.Length) {
"Expected string length $expectedLength but was $actualLength. Strings differ at index $differenceIndex."
}
else
{
"String lengths are both $expectedLength. Strings differ at index $differenceIndex."
}


"Expected: {{{0}}}" -f ( $expected | Expand-SpecialCharacters )
"But was: {{{0}}}" -f ( $actual | Expand-SpecialCharacters )

$specialCharacterOffset = $null
if ($differenceIndex -ne 0)
{
#count all the special characters before the difference
$specialCharacterOffset = ($actual[0..($differenceIndex-1)] |
& $SafeCommands['Where-Object'] {"`n","`r","`t","`b","`0" -contains $_} |
& $SafeCommands['Measure-Object'] |
& $SafeCommands['Select-Object'] -ExpandProperty Count)
}

'-'*($differenceIndex+$specialCharacterOffset+11)+'^'
}
}

function Expand-SpecialCharacters {
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[AllowEmptyString()]
[string[]]$InputObject)
process {
$InputObject -replace "`n","\n" -replace "`r","\r" -replace "`t","\t" -replace "`0", "\0" -replace "`b","\b"
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Set-StrictMode -Version Latest

InModuleScope Pester {
Describe "PesterBeGreaterThan" {
It "passes if value greater than expected" {
Test-PositiveAssertion (PesterBeGreaterThan 2 1)
2 | Should BeGreaterThan 1
}
It "fails if values equal" {
Test-NegativeAssertion (PesterBeGreaterThan 3 3)
}

It "fails if value less than expected" {
Test-NegativeAssertion (PesterBeGreaterThan 4 5)
}
}

}
14 changes: 14 additions & 0 deletions Remotely/lib/Pester_3.3.14/Functions/Assertions/BeGreaterThan.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function PesterBeGreaterThan($value, $expected)
{
return [bool]($value -gt $expected)
}

function PesterBeGreaterThanFailureMessage($value,$expected)
{
return "Expected {$value} to be greater than {$expected}"
}

function NotPesterBeGreaterThanFailureMessage($value,$expected)
{
return "Expected {$value} to be less than or equal to {$expected}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Set-StrictMode -Version Latest

InModuleScope Pester {
Describe "PesterBeLessThan" {
It "passes if value Less than expected" {
Test-PositiveAssertion (PesterBeLessThan 1 2)
1 | Should BeLessThan 2
}
It "fails if values equal" {
Test-NegativeAssertion (PesterBeLessThan 3 3)
}

It "fails if value greater than expected" {
Test-NegativeAssertion (PesterBeLessThan 5 4)
}
}
}
14 changes: 14 additions & 0 deletions Remotely/lib/Pester_3.3.14/Functions/Assertions/BeLessThan.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function PesterBeLessThan($value, $expected)
{
return [bool]($value -lt $expected)
}

function PesterBeLessThanFailureMessage($value,$expected)
{
return "Expected {$value} to be less than {$expected}"
}

function NotPesterBeLessThanFailureMessage($value,$expected)
{
return "Expected {$value} to be greater than or equal to {$expected}"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Set-StrictMode -Version Latest

InModuleScope Pester {
Describe "PesterBeNullOrEmpty" {
It "should return true if null" {
Test-PositiveAssertion (PesterBeNullOrEmpty $null)
}

It "should return true if empty string" {
Test-PositiveAssertion (PesterBeNullOrEmpty "")
}

It "should return true if empty array" {
Test-PositiveAssertion (PesterBeNullOrEmpty @())
}
}
}
23 changes: 23 additions & 0 deletions Remotely/lib/Pester_3.3.14/Functions/Assertions/BeNullOrEmpty.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

function PesterBeNullOrEmpty($value) {
if ($null -eq $value) {
return $true
}
if ([String] -eq $value.GetType()) {
return [String]::IsNullOrEmpty($value)
}
if ($null -ne $value.PSObject.Properties['Count'] -and
$null -ne $value.Count) {
return $value.Count -lt 1
}
return $false
}

function PesterBeNullOrEmptyFailureMessage($value) {
return "Expected: value to be empty but it was {$value}"
}

function NotPesterBeNullOrEmptyFailureMessage {
return "Expected: value to not be empty"
}

20 changes: 20 additions & 0 deletions Remotely/lib/Pester_3.3.14/Functions/Assertions/BeOfType.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Set-StrictMode -Version Latest

InModuleScope Pester {
Describe "PesterBeOfType" {
It "passes if value is of the expected type" {
Test-PositiveAssertion (PesterBeOfType 1 ([int]))
Test-PositiveAssertion (PesterBeOfType 1 "Int")
1 | Should BeOfType Int
2.0 | Should BeOfType ([double])
}
It "fails if value is of a different types" {
Test-NegativeAssertion (PesterBeOfType 2 double)
Test-NegativeAssertion (PesterBeOfType 2.0 ([string]))
}

It "fails if type isn't a type" {
Test-NegativeAssertion (PesterBeOfType 5 NotAType)
}
}
}
Loading

0 comments on commit b3ca33b

Please sign in to comment.