Skip to content

Commit

Permalink
Initial commit with the basics working
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmuc authored and Scott Muc committed Jan 2, 2011
0 parents commit a1d6a0e
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Examples/Calculator/Add-Numbers.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$pwd = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$pwd\Add-Numbers.ps1"
. "$pwd\..\..\Source\Pester.ps1"

Describe "Add-Numbers" {

It "adds positive numbers" {
$sum = Add-Numbers 2 3
$sum.should.be(4)
}

It "adds negative numbers" {
$sum = Add-Numbers (-2) (-2)
$sum.should.be((-4))
}

It "adds one negative number to positive number" {
$sum = Add-Numbers (-2) 2
$sum.should.be(0)
}

It "concatenates strings if given strings" {
$sum = Add-Numbers two three
$sum.should.be("twothree")
}

}
3 changes: 3 additions & 0 deletions Examples/Calculator/Add-Numbers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function Add-Numbers($a, $b) {
return $a + $b
}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Pester
======

Objective
---------

I wanted to make a convention based Powershell Unit testing framework that didn't require the following:

* Installer of any sort
* Changing a users Profile script

The things I wanted it do do is:

* Find all tests by some sort of convention
* Emulate RSpec assertions and fixture setup
* Create NUnit XML reports
4 changes: 4 additions & 0 deletions Source/Functions/Describe.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function Describe($name, [ScriptBlock] $fixture) {
Write-Host -fore yellow Describing $name
& $fixture
}
13 changes: 13 additions & 0 deletions Source/Functions/It.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function It($name, [ScriptBlock] $test)
{
Write-Host -fore DarkCyan $name -NoNewLine

$test_result = & $test

if ($test_result) {
Write-Host -ForegroundColor green " Success"
} else {
Write-Host -ForegroundColor red " Failure`n$($test.ToString())"
}
}

28 changes: 28 additions & 0 deletions Source/ObjectAdaptations/types.ps1xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>System.Object</Name>
<Members>
<ScriptProperty>
<Name>should</Name>
<GetScriptBlock>
$value = $this
$object = New-Object Object |
Add-Member ScriptMethod be {
param($expected)
return ($expected -eq $this.actual)
} -PassThru |
Add-Member NoteProperty -Name actual -Value $null -PassThru |
Add-Member ScriptProperty -Name ThisValue -Value { $this.actual } `
{
param($newactual)
$this.actual = $newactual
} -PassThru
$object.ThisValue = $value

return $object
</GetScriptBlock>
</ScriptProperty>
</Members>
</Type>
</Types>
12 changes: 12 additions & 0 deletions Source/Pester-Console.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
param($relative_path = ".")

$script_dir = Split-Path -Parent $MyInvocation.MyCommand.Path
Update-TypeData -pre "$script_dir\ObjectAdaptations\types.ps1xml" -ErrorAction SilentlyContinue

$fixtures_path = Resolve-Path $relative_path
Write-Host Executing all tests in $fixtures_path

Get-ChildItem $fixtures_path -Recurse |
? { $_.Name -match ".Tests." } |
% { & $_.PSPath }

4 changes: 4 additions & 0 deletions Source/Pester.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$pwd = Split-Path -Parent $MyInvocation.MyCommand.Path

Resolve-Path $pwd\Functions\*.ps1 | % { . $_.ProviderPath }

0 comments on commit a1d6a0e

Please sign in to comment.