-
Notifications
You must be signed in to change notification settings - Fork 9
/
coverage.sh
executable file
·61 lines (48 loc) · 1.65 KB
/
coverage.sh
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
#!/bin/sh -eu
# function to display commands
exe() { echo; echo "\$ $*" ; "$@" ; }
# Parameters
framework="${1-netcoreapp3.1}"
config="${2-Debug}"
include="[Tesla.NET]*"
exclude="[*.Tests]*"
# Cannot use a bash solution in alpine builds https://stackoverflow.com/a/246128
#rootDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
rootDir=$(pwd)
testResults="test/TestResults"
output="$rootDir/$testResults/output"
tools="$rootDir/$testResults/tools"
testProj1="$rootDir/test/Tesla.NET.Tests/Tesla.NET.Tests.csproj"
# Restore the packages
exe dotnet restore "$rootDir"
# Build the test projects
exe dotnet build --no-restore -f "$framework" -c "$config" "$testProj1"
# Execute the tests
exe dotnet test --no-restore --no-build -f "$framework" -c "$config" \
"$testProj1" \
--results-directory "$output/" \
--logger "\"trx;LogFileName=$(basename "$testProj1" .csproj).trx\"" \
--logger "\"Console;noprogress=true\"" \
-p:CollectCoverage=true \
-p:Include="$include" \
-p:Exclude="$exclude" \
-p:CoverletOutput="$output/" \
-p:CoverletOutputFormat="\"json,opencover,cobertura\""
# Install trx2junit if not already installed
if [ ! -f "$tools/trx2junit" ]
then
exe dotnet tool install trx2junit --tool-path "$tools"
fi
# Install ReportGenerator if not already installed
if [ ! -f "$tools/reportgenerator" ]
then
exe dotnet tool install dotnet-reportgenerator-globaltool --tool-path "$tools"
fi
# Convert the MSTest trx files to junit xml
exe "$tools/trx2junit" "$output"/*.trx
# Generate the reports
exe "$tools/reportgenerator" \
"-verbosity:Info" \
"-reports:$output/coverage.$framework.opencover.xml" \
"-targetdir:$output/Report" \
"-reporttypes:Html"