File tree Expand file tree Collapse file tree 8 files changed +107
-0
lines changed
Expand file tree Collapse file tree 8 files changed +107
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ function Add-Numbers ($a , $b ) {
2+ return $a + $b
3+ }
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ function Describe ($name , [ScriptBlock ] $fixture ) {
2+ Write-Host - fore yellow Describing $name
3+ & $fixture
4+ }
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 1+ $pwd = Split-Path - Parent $MyInvocation.MyCommand.Path
2+
3+ Resolve-Path $pwd \Functions\* .ps1 | % { . $_.ProviderPath }
4+
You can’t perform that action at this time.
0 commit comments