1
1
using namespace System.IO.Path
2
2
3
- param (
4
- [Parameter ()]
3
+ # PSScriptAnalyzer rule excludes
4
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSAvoidUsingWriteHost' , ' ' )]
5
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSUseShouldProcessForStateChangingFunctions' , ' ' )]
6
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSAvoidGlobalVars' , ' ' )]
7
+ param (
8
+ [Parameter ()]
5
9
[switch ]$LocalTest ,
6
10
[string ]$CoverageXMLPath = $env: COV_REPORT ,
7
11
[string ]$SqlInstance = $env: DB_INSTANCE ,
8
12
[string ]$Database = $env: TARGET_DB ,
9
13
[bool ]$IsAzureSQL = [System.Convert ]::ToBoolean($env: AzureSQL ),
10
14
[string ]$User = $env: AZURE_SQL_USER ,
11
15
[string ]$Pass = $env: AZURE_SQL_PASS ,
12
- [string ]$Color = " Green" ,
16
+ [System.ConsoleColor ]$Color = " Green" ,
13
17
[switch ]$CodeCoverage
14
18
)
19
+
15
20
. " .\tests\constants.ps1"
16
21
$ErrorActionPreference = " Stop"
17
22
$TestFiles = Get-ChildItem - Path .\tests\* .Tests.ps1
18
23
$FailedTests = 0
19
24
20
25
function Start-CodeCoverage {
26
+ param (
27
+ [string ]$SqlInstance ,
28
+ [string ]$Database ,
29
+ [string ]$User ,
30
+ [string ]$Pass ,
31
+ [bool ]$IsAzureSQL ,
32
+ [System.ConsoleColor ]$Color
33
+ )
21
34
# Setup vars
35
+ $ConnString = " server=$SqlInstance ;initial catalog=$Database ;Trusted_Connection=yes"
22
36
If ($IsAzureSQL ) {
23
37
$ConnString = " server=$SqlInstance ;initial catalog=$Database ;User Id=$User ;pwd=$Pass "
24
38
}
25
39
26
- Else {
27
- $ConnString = " server=$SqlInstance ;initial catalog=$Database ;Trusted_Connection=yes"
28
- }
29
-
30
40
$NugetPath = (Get-Package GOEddie.SQLCover).Source | Convert-Path
31
41
$SQLCoverRoot = Split-Path $NugetPath
32
42
$SQLCoverPath = Join-Path $SQLCoverRoot " lib"
@@ -42,7 +52,11 @@ function Start-CodeCoverage {
42
52
}
43
53
44
54
function Complete-CodeCoverage {
45
- # Stop covering
55
+ param (
56
+ [string ]$CoverageXMLPath ,
57
+ [string ]$Color
58
+ )
59
+ # Stop covering
46
60
Write-Host " Stopping SQLCover..." - ForegroundColor $Color
47
61
$coverageResults = $global :SQLCover.Stop ()
48
62
@@ -51,10 +65,10 @@ function Complete-CodeCoverage {
51
65
If (! ($LocalTest.IsPresent )) {
52
66
$SavePath = Join-Path - Path $PSScriptRoot - ChildPath " sqlcover"
53
67
$coverageResults.OpenCoverXml () | Out-File $CoverageXMLPath - Encoding utf8
54
- $coverageResults.SaveSourceFiles ($SavePath )
68
+ $coverageResults.SaveSourceFiles ($SavePath )
55
69
}
56
70
57
- Else {
71
+ Else {
58
72
# Don't save any files and bring up html report for review
59
73
$tmpFile = Join-Path $env: TEMP " Coverage.html"
60
74
Set-Content - Path $tmpFile - Value $coverageResults.Html2 () - Force
@@ -66,7 +80,15 @@ function Complete-CodeCoverage {
66
80
67
81
# Start Coverage
68
82
If ($CodeCoverage.IsPresent ) {
69
- Start-CodeCoverage
83
+ $Hash = @ {
84
+ SqlInstance = $SqlInstance
85
+ Database = $Database
86
+ User = $User
87
+ Pass = $Pass
88
+ IsAzureSQL = $IsAzureSQL
89
+ Color = $Color
90
+ }
91
+ Start-CodeCoverage @Hash
70
92
}
71
93
72
94
# Generate all-in-one installer script
@@ -88,7 +110,7 @@ ForEach ($file in $TestFiles) {
88
110
89
111
# End Coverage
90
112
If ($CodeCoverage.IsPresent ) {
91
- Complete-CodeCoverage
113
+ Complete-CodeCoverage - CoverageXMLPath $CoverageXMLPath - Color $Color
92
114
}
93
115
94
116
# Check for failures
0 commit comments