<commit_before>#!/bin/sh -eu

# function to display commands
exe() { echo; echo "\$ $*" ; "$@" ; }

# Parameters
framework="${1-netcoreapp2.1}"
config="${2-Debug}"

testResults="test/TestResults"
include="[AutoTest.*]*"
exclude="\"[*.Tests]*,[AutoTest.ExampleLibrary]*\""

# 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)

testProj1="$rootDir/test/AutoTest.ExampleLibrary.Tests/AutoTest.ExampleLibrary.Tests.csproj"
testProj2="$rootDir/test/AutoTest.ArgumentNullException.Tests/AutoTest.ArgumentNullException.Tests.csproj"

# Restore the packages
exe dotnet restore "$rootDir"

# Build the test projects
exe dotnet build --no-restore -f "$framework" -c "$config" "$testProj1"
exe dotnet build --no-restore -f "$framework" -c "$config" "$testProj2"

# Execute the tests
exe dotnet test --no-restore --no-build -f "$framework" -c "$config" \
"$testProj1" \
--results-directory "$rootDir/$testResults/output/" \
--logger "\"trx;LogFileName=$(basename "$testProj1" .csproj).trx\"" \
/p:CollectCoverage=true \
/p:Include="$include" \
/p:Exclude="$exclude" \
/p:CoverletOutput="$rootDir/$testResults/internal.coverage.json"

exe dotnet test --no-restore --no-build -f "$framework" -c "$config" \
"$testProj2" \
--results-directory "$rootDir/$testResults/output/" \
--logger "\"trx;LogFileName=$(basename "$testProj2" .csproj).trx\"" \
/p:CollectCoverage=true \
/p:Include="$include" \
/p:Exclude="$exclude" \
/p:MergeWith="$rootDir/$testResults/internal.coverage.json" \
/p:CoverletOutput="$rootDir/$testResults/" \
/p:CoverletOutputFormat="\"json,opencover\""

# Install trx2junit if not already installed
if [ ! -f "$rootDir/$testResults/tools/trx2junit" ]
then
   exe dotnet tool install trx2junit --tool-path "$rootDir/$testResults/tools"
fi

# Install ReportGenerator if not already installed
if [ ! -f "$rootDir/$testResults/tools/reportgenerator" ]
then
   exe dotnet tool install dotnet-reportgenerator-globaltool --tool-path "$rootDir/$testResults/tools"
fi

# Convert the MSTest trx files to junit xml
exe "$rootDir/$testResults/tools/trx2junit" "$rootDir/$testResults/output"/*.trx

# Generate the reports
exe "$rootDir/$testResults/tools/reportgenerator" \
"-verbosity:Info" \
"-reports:$rootDir/$testResults/coverage.opencover.xml" \
"-targetdir:$rootDir/$testResults/Report" \
"-reporttypes:Html"<commit_msg>:chart_with_upwards_trend: Capture all output<commit_after>#!/bin/sh -eu

# function to display commands
exe() { echo; echo "\$ $*" ; "$@" ; }

# Parameters
framework="${1-netcoreapp2.1}"
config="${2-Debug}"

include="[AutoTest.*]*"
exclude="\"[*.Tests]*,[AutoTest.ExampleLibrary]*\""

# 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/AutoTest.ExampleLibrary.Tests/AutoTest.ExampleLibrary.Tests.csproj"
testProj2="$rootDir/test/AutoTest.ArgumentNullException.Tests/AutoTest.ArgumentNullException.Tests.csproj"

# Restore the packages
exe dotnet restore "$rootDir"

# Build the test projects
exe dotnet build --no-restore -f "$framework" -c "$config" "$testProj1"
exe dotnet build --no-restore -f "$framework" -c "$config" "$testProj2"

# 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\"" \
/p:CollectCoverage=true \
/p:Include="$include" \
/p:Exclude="$exclude" \
/p:CoverletOutput="$output/internal.coverage.json"

exe dotnet test --no-restore --no-build -f "$framework" -c "$config" \
"$testProj2" \
--results-directory "$output/" \
--logger "\"trx;LogFileName=$(basename "$testProj2" .csproj).trx\"" \
/p:CollectCoverage=true \
/p:Include="$include" \
/p:Exclude="$exclude" \
/p:MergeWith="$output/internal.coverage.json" \
/p:CoverletOutput="$output/" \
/p:CoverletOutputFormat="\"json,opencover\""

# 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.opencover.xml" \
"-targetdir:$output/Report" \
"-reporttypes:Html"
{'fraction_non_alphanumeric': 0.1825296108291032, 'fraction_numerical': 0.010575296108291032, 'mean_word_length': 5.047314578005115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5641956', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1608, 'n_words': 334}