forked from psake/psake
-
Notifications
You must be signed in to change notification settings - Fork 17
/
psake-buildTester.ps1
84 lines (76 loc) · 2.26 KB
/
psake-buildTester.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function Main()
{
write-host "Running psake build tests" -ForeGroundColor GREEN
remove-module psake -ea SilentlyContinue
import-module .\psake.psm1
$psake.run_by_psake_build_tester = $true
$results = runBuilds
remove-module psake
""
$results | Sort 'Name' | % { if ($_.Result -eq "Passed") { write-host ($_.Name + " (Passed)") -ForeGroundColor 'GREEN'} else { write-host ($_.Name + " (Failed)") -ForeGroundColor 'RED'}}
""
$failed = $results | ? { $_.Result -eq "Failed" }
if ($failed)
{
write-host "One or more of the build files failed" -ForeGroundColor RED
exit 1
}
else
{
write-host "All Builds Passed" -ForeGroundColor GREEN
exit 0
}
}
function runBuilds()
{
$buildFiles = ls specs\*.ps1
$testResults = @()
#Add a fake build file to the $buildFiles array so that we can verify
#that Invoke-psake fails
$non_existant_buildfile = "" | select Name, FullName
$non_existant_buildfile.Name = "specifying_a_non_existant_buildfile_should_fail.ps1"
$non_existant_buildfile.FullName = "c:\specifying_a_non_existant_buildfile_should_fail.ps1"
$buildFiles += $non_existant_buildfile
foreach($buildFile in $buildFiles)
{
$testResult = "" | select Name, Result
$testResult.Name = $buildFile.Name
invoke-psake $buildFile.FullName -Parameters @{'p1'='v1'; 'p2'='v2'} -Properties @{'x'='1'; 'y'='2'} -Initialization { if(!$container) { $container = @{}; } $container.bar = "bar"; $container.baz = "baz"; $bar = 2; $baz = 3 } | Out-Null
$testResult.Result = (getResult $buildFile.Name $psake.build_success)
$testResults += $testResult
if ($testResult.Result -eq "Passed")
{
write-host "." -ForeGroundColor GREEN -NoNewLine
}
else
{
write-host "F" -ForeGroundColor RED -NoNewLine
}
}
return $testResults
}
function getResult([string]$fileName, [bool]$buildSucceeded)
{
$shouldSucceed = $null
if ($fileName.EndsWith("_should_pass.ps1"))
{
$shouldSucceed = $true
}
elseif ($fileName.EndsWith("_should_fail.ps1"))
{
$shouldSucceed = $false
}
else
{
throw "Invalid specification syntax. Specs should end with _should_pass or _should_fail. $fileName"
}
if ($buildSucceeded -eq $shouldSucceed)
{
"Passed"
}
else
{
"Failed"
}
}
main