Created
October 18, 2010 18:33
-
-
Save RhysC/632749 to your computer and use it in GitHub Desktop.
Powershell with PSEventing and Nunit to watch my bin folder and auto run tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( (Get-PSSnapin -Name pseventing -ErrorAction SilentlyContinue) -eq $null ) | |
{ | |
Add-PsSnapin pseventing | |
} | |
Start-KeyHandler -CaptureCtrlC | |
$Script:initialdir = "C:\SG\SDP\Trunk\SDP\SDP" | |
$fsw = new-object system.io.filesystemwatcher | |
$fsw.Path = "$initialdir\Bin\Desktop\" | |
$fsw.EnableRaisingEvents = $true | |
connect-event fsw changed,created | |
WRITE-HOST "watching $($fsw.path)" -ForegroundColor Yellow | |
WRITE-HOST "entering loop... ctrl+c to exit" -ForegroundColor Yellow | |
$done = $false; | |
while ($events = @(read-event -wait)) { | |
# read-event always returns a collection | |
foreach ($event in $events) { | |
WRITE-HOST $event.name | |
switch ($event.name) { | |
"ctrlc" { | |
WRITE-HOST "Cancelling..." -ForegroundColor Yellow | |
$done = $true | |
} | |
{($_ = "Changed") -or ($_ = "Created") } | |
{ | |
$file = $event.Args.FullPath | |
$filter = "*Order*.*Tests*.dll" | |
#$file = $Event.SourceEventArgs.FullPath | |
if($file -like $filter) | |
{ | |
$nunit = "C:\SG\SDP\Trunk\SDP\3rdParty\NUnit-2.5.2\nunit-console" | |
$currentdate = get-date -format g | |
write-Host "Running Tests on $file $currentdate" -ForegroundColor Yellow | |
&"$nunit" /out:$file.Name_testresult.txt $file 2>&1 | |
if($LastExitCode -ne 0) | |
{ | |
WRITE-HOST "Test have failed for $file"-ForegroundColor RED | |
} | |
else | |
{ | |
WRITE-HOST "Test have passed for $file"-ForegroundColor GREEN | |
} | |
} | |
} | |
} | |
} | |
if ($done -eq $true) { | |
Disconnect-Event fsw changed,created | |
break | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment