Skip to content

Commit 8ecca84

Browse files
lowlydbaAppveyor
andauthored
Code coverage (#103)
* Start code coverage based fixes * Generate cov xml report on build * Add upload of report to codecov * CI produced files * Fix verbose choco & nuget source * Only run code cov on 2019 * Fix code cov run blocks * CI produced files * Fix file path for sqlcover script * CI produced files * FIx line ending warnings from git * Try to remove crlf warning from build * Trim build cmds / output * Force sqlcover install * Finally quiet choco down ! * Update codecov.yml Co-authored-by: Appveyor <[email protected]>
1 parent 96819b1 commit 8ecca84

16 files changed

+3201
-77
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# linguist overrides
22
*.sql linguist-language=TSQL
3+
4+
# line endings for code coverage files
5+
appveyor/sqlcover/* text eol=lf

appveyor/appveyor.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ environment:
1111
APPVEYOR_RDP_PASSWORD: Np^VNSzJI5#OmRdUNqro2T9UVkCdZ
1212
MSSQL_LOGIN: sa
1313
MSSQL_PASS: Password12!
14-
TSQLTSETCLR: tests\tSQLt\SetClrEnabled.sql
14+
TSQLTSETCLR: tests\tSQLt\SetClrEnabled.sql
1515
TSQLTCREATEDB: tests\tSQLt\CreateDatabase.sql
1616
TSQLTINSTALL: tests\tSQLt\tSQLt.class.sql
1717
TSQLTBUILDPATH: tests\build
1818
TSQLTTESTPATH: tests\run
1919
TARGET_DB: tSQLt
20+
COV_REPORT: appveyor\sqlcover\Coverage.opencoverxml
2021

2122
matrix:
2223
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
2324
MSSQL: SQL2019
2425
DB_INSTANCE: (local)\SQL2019
2526
LINT_CONFIG: appveyor\tsqllint\.tsqllintrc_150
27+
LATEST: True
2628

2729
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
2830
MSSQL: SQL2017
@@ -49,6 +51,7 @@ clone_script:
4951
- ps: Add-Content "$HOME\.git-credentials" "https://$($env:access_token):[email protected]`n" -NoNewLine
5052
- git config --global user.email "[email protected]"
5153
- git config --global user.name "Appveyor"
54+
- git config --global core.safecrlf false
5255
- git clone -q --single-branch --branch=%APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH% https://github.com/LowlyDBA/ExpressSQL.git %APPVEYOR_BUILD_FOLDER%
5356
- cd %APPVEYOR_BUILD_FOLDER%
5457

@@ -62,18 +65,30 @@ build_script:
6265
- ps: .\appveyor\make_combined_script.ps1
6366
- ps: .\appveyor\install_expsql.ps1
6467
- ps: .\appveyor\build_tsqlt_tests.ps1
68+
- echo Running TSQLLint tests
69+
- npx tsqllint -c %LINT_CONFIG% *.sql
6570

71+
# Non-covered test run
6672
test_script:
6773
- ps: .\appveyor\run_tsqlt_tests.ps1
68-
- echo Running TSQLLint tests
69-
- npx tsqllint -c %LINT_CONFIG% *.sql
7074

75+
# Only run code cov & push changes on latest build env
7176
for:
7277
-
73-
# Only push for final test environment
7478
matrix:
7579
only:
76-
- MSSQL: SQL2012SP1
80+
- LATEST: True
81+
82+
# Setup codecov, SQL Cover
83+
before_test:
84+
- ps: Install-Package GOEddie.SQLCover -Force | Out-Null
85+
- ps: choco install codecov --no-progress --limit-output | Out-Null
86+
87+
# Run tests with SQL Cover analysis
88+
test_script:
89+
- ps: .\appveyor\sqlcover\Run_SQLCover.ps1
7790

91+
# Upload code coverage report, push generated files
7892
on_success:
93+
- codecov -f %COV_REPORT%
7994
- ps: .\appveyor\push_git_changes.ps1

appveyor/sqlcover/Coverage.opencoverxml

Lines changed: 413 additions & 0 deletions
Large diffs are not rendered by default.

appveyor/sqlcover/Run_SQLCover.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
$LocalTest = $false
2+
$SqlInstance = $env:DB_INSTANCE
3+
$Database = "tSQLt"
4+
$TestCommand = "EXEC tSQLt.RunAll"
5+
$TrustedConnection = "yes"
6+
$ConnString = "server=$SqlInstance;initial catalog=$Database;Trusted_Connection=$TrustedConnection"
7+
8+
# Setup files
9+
$NugetPath = (Get-Package GOEddie.SQLCover).Source | Convert-Path
10+
$SQLCoverRoot = Split-Path $NugetPath
11+
$SQLCoverPath = Join-Path $SQLCoverRoot "lib"
12+
$SQLCoverDllFullPath = Join-Path $SQLCoverPath "SQLCover.dll"
13+
14+
# Add DLL
15+
Add-Type -Path $SQLCoverDllFullPath
16+
17+
# Start covering
18+
$SQLCover = new-object SQLCover.CodeCoverage($ConnString, $Database)
19+
$IsCoverStarted = $SQLCover.Start()
20+
If ($IsCoverStarted) { Write-Host "Starting SQL Cover" }
21+
22+
# Run Tests
23+
. .\appveyor\run_tsqlt_tests.ps1
24+
25+
# Stop covering
26+
$coverageResults = $SQLCover.Stop()
27+
28+
# Export results
29+
$xmlPath = Join-Path -Path $PSSCriptRoot -ChildPath "Coverage.opencoverxml"
30+
$coverageResults.OpenCoverXml() | Out-File $xmlPath -Encoding utf8
31+
$coverageResults.SaveSourceFiles($PSScriptRoot)

0 commit comments

Comments
 (0)