11using namespace System.IO.Path
22
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 ()]
59 [switch ]$LocalTest ,
610 [string ]$CoverageXMLPath = $env: COV_REPORT ,
711 [string ]$SqlInstance = $env: DB_INSTANCE ,
812 [string ]$Database = $env: TARGET_DB ,
913 [bool ]$IsAzureSQL = [System.Convert ]::ToBoolean($env: AzureSQL ),
1014 [string ]$User = $env: AZURE_SQL_USER ,
1115 [string ]$Pass = $env: AZURE_SQL_PASS ,
12- [string ]$Color = " Green" ,
16+ [System.ConsoleColor ]$Color = " Green" ,
1317 [switch ]$CodeCoverage
1418)
19+
1520. " .\tests\constants.ps1"
1621$ErrorActionPreference = " Stop"
1722$TestFiles = Get-ChildItem - Path .\tests\* .Tests.ps1
1823$FailedTests = 0
1924
2025function Start-CodeCoverage {
26+ param (
27+ [string ]$SqlInstance ,
28+ [string ]$Database ,
29+ [string ]$User ,
30+ [string ]$Pass ,
31+ [bool ]$IsAzureSQL ,
32+ [System.ConsoleColor ]$Color
33+ )
2134 # Setup vars
35+ $ConnString = " server=$SqlInstance ;initial catalog=$Database ;Trusted_Connection=yes"
2236 If ($IsAzureSQL ) {
2337 $ConnString = " server=$SqlInstance ;initial catalog=$Database ;User Id=$User ;pwd=$Pass "
2438 }
2539
26- Else {
27- $ConnString = " server=$SqlInstance ;initial catalog=$Database ;Trusted_Connection=yes"
28- }
29-
3040 $NugetPath = (Get-Package GOEddie.SQLCover).Source | Convert-Path
3141 $SQLCoverRoot = Split-Path $NugetPath
3242 $SQLCoverPath = Join-Path $SQLCoverRoot " lib"
@@ -42,7 +52,11 @@ function Start-CodeCoverage {
4252}
4353
4454function Complete-CodeCoverage {
45- # Stop covering
55+ param (
56+ [string ]$CoverageXMLPath ,
57+ [string ]$Color
58+ )
59+ # Stop covering
4660 Write-Host " Stopping SQLCover..." - ForegroundColor $Color
4761 $coverageResults = $global :SQLCover.Stop ()
4862
@@ -51,10 +65,10 @@ function Complete-CodeCoverage {
5165 If (! ($LocalTest.IsPresent )) {
5266 $SavePath = Join-Path - Path $PSScriptRoot - ChildPath " sqlcover"
5367 $coverageResults.OpenCoverXml () | Out-File $CoverageXMLPath - Encoding utf8
54- $coverageResults.SaveSourceFiles ($SavePath )
68+ $coverageResults.SaveSourceFiles ($SavePath )
5569 }
5670
57- Else {
71+ Else {
5872 # Don't save any files and bring up html report for review
5973 $tmpFile = Join-Path $env: TEMP " Coverage.html"
6074 Set-Content - Path $tmpFile - Value $coverageResults.Html2 () - Force
@@ -66,7 +80,15 @@ function Complete-CodeCoverage {
6680
6781# Start Coverage
6882If ($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
7092}
7193
7294# Generate all-in-one installer script
@@ -88,7 +110,7 @@ ForEach ($file in $TestFiles) {
88110
89111# End Coverage
90112If ($CodeCoverage.IsPresent ) {
91- Complete-CodeCoverage
113+ Complete-CodeCoverage - CoverageXMLPath $CoverageXMLPath - Color $Color
92114}
93115
94116# Check for failures
0 commit comments