Skip to content

Commit a1d6a0e

Browse files
scottmucScott Muc
authored andcommitted
Initial commit with the basics working
0 parents  commit a1d6a0e

File tree

8 files changed

+107
-0
lines changed

8 files changed

+107
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
$pwd = Split-Path -Parent $MyInvocation.MyCommand.Path
2+
. "$pwd\Add-Numbers.ps1"
3+
. "$pwd\..\..\Source\Pester.ps1"
4+
5+
Describe "Add-Numbers" {
6+
7+
It "adds positive numbers" {
8+
$sum = Add-Numbers 2 3
9+
$sum.should.be(4)
10+
}
11+
12+
It "adds negative numbers" {
13+
$sum = Add-Numbers (-2) (-2)
14+
$sum.should.be((-4))
15+
}
16+
17+
It "adds one negative number to positive number" {
18+
$sum = Add-Numbers (-2) 2
19+
$sum.should.be(0)
20+
}
21+
22+
It "concatenates strings if given strings" {
23+
$sum = Add-Numbers two three
24+
$sum.should.be("twothree")
25+
}
26+
27+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function Add-Numbers($a, $b) {
2+
return $a + $b
3+
}

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Pester
2+
======
3+
4+
Objective
5+
---------
6+
7+
I wanted to make a convention based Powershell Unit testing framework that didn't require the following:
8+
9+
* Installer of any sort
10+
* Changing a users Profile script
11+
12+
The things I wanted it do do is:
13+
14+
* Find all tests by some sort of convention
15+
* Emulate RSpec assertions and fixture setup
16+
* Create NUnit XML reports

Source/Functions/Describe.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
function Describe($name, [ScriptBlock] $fixture) {
2+
Write-Host -fore yellow Describing $name
3+
& $fixture
4+
}

Source/Functions/It.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function It($name, [ScriptBlock] $test)
2+
{
3+
Write-Host -fore DarkCyan $name -NoNewLine
4+
5+
$test_result = & $test
6+
7+
if ($test_result) {
8+
Write-Host -ForegroundColor green " Success"
9+
} else {
10+
Write-Host -ForegroundColor red " Failure`n$($test.ToString())"
11+
}
12+
}
13+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Types>
3+
<Type>
4+
<Name>System.Object</Name>
5+
<Members>
6+
<ScriptProperty>
7+
<Name>should</Name>
8+
<GetScriptBlock>
9+
$value = $this
10+
$object = New-Object Object |
11+
Add-Member ScriptMethod be {
12+
param($expected)
13+
return ($expected -eq $this.actual)
14+
} -PassThru |
15+
Add-Member NoteProperty -Name actual -Value $null -PassThru |
16+
Add-Member ScriptProperty -Name ThisValue -Value { $this.actual } `
17+
{
18+
param($newactual)
19+
$this.actual = $newactual
20+
} -PassThru
21+
$object.ThisValue = $value
22+
23+
return $object
24+
</GetScriptBlock>
25+
</ScriptProperty>
26+
</Members>
27+
</Type>
28+
</Types>

Source/Pester-Console.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
param($relative_path = ".")
2+
3+
$script_dir = Split-Path -Parent $MyInvocation.MyCommand.Path
4+
Update-TypeData -pre "$script_dir\ObjectAdaptations\types.ps1xml" -ErrorAction SilentlyContinue
5+
6+
$fixtures_path = Resolve-Path $relative_path
7+
Write-Host Executing all tests in $fixtures_path
8+
9+
Get-ChildItem $fixtures_path -Recurse |
10+
? { $_.Name -match ".Tests." } |
11+
% { & $_.PSPath }
12+

Source/Pester.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
$pwd = Split-Path -Parent $MyInvocation.MyCommand.Path
2+
3+
Resolve-Path $pwd\Functions\*.ps1 | % { . $_.ProviderPath }
4+

0 commit comments

Comments
 (0)