Browse Source

Combine xunit and test for converage

pull/1061/head
James Jackson-South 6 years ago
parent
commit
f7e62adcab
  1. 38
      .github/workflows/build-and-test.yml
  2. 21
      Directory.Build.targets
  3. 17
      build.cmd
  4. 28
      build.ps1
  5. 101
      run-tests.ps1
  6. 2
      src/ImageSharp/ImageSharp.csproj
  7. 34
      test.ps1
  8. 3
      tests/Directory.Build.props
  9. 16
      tests/Directory.Build.targets
  10. 4
      tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj
  11. 6
      tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
  12. 13
      tests/ImageSharp.Tests/ImageSharp.Tests.csproj

38
.github/workflows/build-and-test.yml

@ -14,25 +14,25 @@ jobs:
Build:
strategy:
matrix:
opts:
options:
# - os: ubuntu-latest
# framework: netcoreapp2.1
# runtime: x64
# cover: false
# runtime: -x64
# codecov: false
- os: windows-latest
framework: netcoreapp2.1
runtime: x64 # Not currently used. See https://github.com/actions/setup-dotnet/issues/72
cover: true
runtime: -x64
codecov: true
- os: windows-latest
framework: net472
runtime: x64
cover: false
runtime: -x64
codecov: false
- os: windows-latest
framework: net472
runtime: x86
cover: false
runtime: -x86
codecov: false
runs-on: ${{ matrix.opts.os }}
runs-on: ${{ matrix.options.os }}
steps:
- uses: actions/checkout@v1
@ -52,22 +52,20 @@ jobs:
shell: pwsh
run: |
$DebugPreference = "Continue"
./build.ps1 "${{matrix.opts.framework}}"
./build.ps1 "${{matrix.options.framework}}"
- name: Test no Coverage
if: matrix.opts.cover == false
run: dotnet test -c Release -f "${{matrix.opts.framework}}" --no-build --filter Sandbox
- name: Test with Coverage
if: matrix.opts.cover == true
run: dotnet test -c Release -f "${{matrix.opts.framework}}" --no-build --filter Sandbox /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
- name: Test
shell: pwsh
run: ./test.ps1 "${{ matrix.options.os }}" "${{matrix.options.framework}}" "${{matrix.options.runtime}}" "${{matrix.options.codecov}}"
env:
XUNIT_PATH: .\tests\ImageSharp.Tests # Required for xunit
- name: Update Codecov
uses: iansu/codecov-action-node@v1.0.0
if: matrix.opts.cover == true
if: matrix.options.cover == true
with:
token: ${{secrets.CODECOV_TOKEN}}
file: "coverage.xml"
file: "coverage.${{matrix.options.framework}}.xml"
flags: unittests
# Publish:
# runs-on: windows-latest

21
Directory.Build.targets

@ -15,6 +15,13 @@
<DefineConstants>$(DefineConstants);$(OS)</DefineConstants>
</PropertyGroup>
<!-- Tool versions for tool references across all projects -->
<ItemGroup>
<!--dotnet tools does not have an x86 runner. You have to use separate SDKs-->
<!--https://github.com/actions/setup-dotnet/issues/72-->
<DotNetCliToolReference Update="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
<!-- Package versions for package references across all projects -->
<ItemGroup>
<!--Global Dependencies-->
@ -31,19 +38,7 @@
<PackageReference Update="System.Runtime.CompilerServices.Unsafe" Version="4.5.1" />
<PackageReference Update="System.Threading.Tasks.Parallel" Version="4.3.0" />
<PackageReference Update="System.ValueTuple" Version="4.5.0" />
<!--Test Dependencies-->
<PackageReference Update="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Update="Colourful" Version="2.0.3" />
<PackageReference Update="coverlet.collector" Version="1.1.0" />
<PackageReference Update="Magick.NET-Q16-AnyCPU" Version="7.14.4" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Update="Moq" Version="4.10.0" />
<PackageReference Update="Pfim" Version="0.9.1" />
<PackageReference Update="System.Drawing.Common" Version="4.7.0" />
<!--TODO: Fix implicit conversion issues so we can move to 2.4.1-->
<PackageReference Update="xunit" Version="2.3.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

17
build.cmd

@ -1,17 +0,0 @@
@echo Off
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& '.\build.ps1'"
if not "%errorlevel%"=="0" goto failure
:success
ECHO successfully built project
REM exit 0
goto end
:failure
ECHO failed to build.
REM exit -1
goto end
:end

28
build.ps1

@ -8,14 +8,6 @@ $version = ''
$tagRegex = '^v?(\d+\.\d+\.\d+)(?:-([a-zA-Z]+)\.?(\d*))?$'
$skipFullFramework = 'false'
# If we are trying to build only netcoreapp versions for testings then skip building the full framework targets
if ("$targetFramework".StartsWith("netcoreapp")) {
Write-Debug "Skipping Full Framework"
$skipFullFramework = 'true'
}
function ToBuildNumber {
param( $date )
@ -99,7 +91,7 @@ else {
Write-Debug "Discovered base version from tags '${version}'"
}
# Create a build number based on the current time.
# Create a build number based on the current datetime.
$buildNumber = ""
if ( "$env:GITHUB_SHA" -ne '') {
@ -133,20 +125,26 @@ else {
}
Write-Host "Building version '${version}'"
dotnet restore /p:packageversion=$version /p:DisableImplicitNuGetFallbackFolder=true /p:skipFullFramework=$skipFullFramework
$repositoryUrl = "https://github.com/SixLabors/"
if ($targetFramework -ne 'ALL') {
$targetFramework = "-f $targetFramework"
}
dotnet restore $targetFramework /p:packageversion=$version /p:DisableImplicitNuGetFallbackFolder=true
$repositoryUrl = ""
if ("$env:GITHUB_REPOSITORY" -ne "") {
$repositoryUrl = "https://github.com/$env:GITHUB_REPOSITORY"
}
Write-Host "Building projects"
dotnet build -c Release /p:packageversion=$version /p:skipFullFramework=$skipFullFramework /p:RepositoryUrl=$repositoryUrl
dotnet build -c Release $targetFramework /p:packageversion=$version /p:RepositoryUrl=$repositoryUrl
if ($LASTEXITCODE ) { Exit $LASTEXITCODE }
Write-Host "Packaging projects"
# Write-Host "Packaging projects"
dotnet pack -c Release --output "$PSScriptRoot/artifacts" --no-build /p:packageversion=$version /p:skipFullFramework=$skipFullFramework /p:RepositoryUrl=$repositoryUrl
if ($LASTEXITCODE ) { Exit $LASTEXITCODE }
# dotnet pack -c Release --output "$PSScriptRoot/artifacts" --no-build /p:packageversion=$version /p:skipFullFramework=$skipFullFramework /p:RepositoryUrl=$repositoryUrl
# if ($LASTEXITCODE ) { Exit $LASTEXITCODE }

101
run-tests.ps1

@ -1,101 +0,0 @@
param(
[string]$os,
[string]$targetFramework,
[string]$doCoverage = "False",
[string]$is32Bit = "False"
)
if (!$os) {
Write-Host "run-tests.ps1 ERROR: os is undefined!"
exit 1
}
if (!$targetFramework) {
Write-Host "run-tests.ps1 ERROR: targetFramework is undefined!"
exit 1
}
function VerifyPath($path, $errorMessage) {
if (!(Test-Path -Path $path)) {
Write-Host "run-tests.ps1 $errorMessage `n $xunitRunnerPath"
exit 1
}
}
function CheckSubmoduleStatus() {
$submoduleStatus = (git submodule status) | Out-String
# if the result string is empty, the command failed to run (we didn't capture the error stream)
if ($submoduleStatus) {
# git has been called successfully, what about the status?
if (($submoduleStatus -match "\-") -or ($submoduleStatus -match "\(\(null\)\)")) {
# submodule has not been initialized!
return 2;
}
elseif ($submoduleStatus -match "\+") {
# submodule is not synced:
return 1;
}
else {
# everything fine:
return 0;
}
}
else {
# git call failed, so we should warn
return 3;
}
}
if (($os -eq "windows-latest") -and ($doCoverage -eq "True") -and ($env:CI -eq "True") -and ($is32Bit -ne "True")) {
# We execute CodeCoverage.cmd only for one specific job on CI (windows + coverageTargetFramework + 64bit )
$testRunnerCmd = ".\tests\CodeCoverage\CodeCoverage.cmd"
}
else {
Set-Location .\tests
$xunitArgs = "-nobuild -c Release -framework $targetFramework"
$coreTargetFrameworkRegex = '^netcoreapp(\d+\.\d+)$'
if ($targetFramework -match $coreTargetFrameworkRegex) {
# There were issues matching the correct installed runtime if we do not specify it explicitly:
$fxVersion = $matches[1] + ".0"
$xunitArgs += " --fx-version $fxVersion"
}
if ($is32Bit -eq "True") {
$xunitArgs += " -x86"
}
$testRunnerCmd = "dotnet xunit $xunitArgs"
}
Write-Host "running:"
Write-Host $testRunnerCmd
Write-Host "..."
Invoke-Expression $testRunnerCmd
Set-Location $PSScriptRoot
$exitCodeOfTests = $LASTEXITCODE;
if (0 -ne ([int]$exitCodeOfTests)) {
# check submodule status
$submoduleStatus = CheckSubmoduleStatus
if ([int]$submoduleStatus -eq 1) {
# not synced
Write-Host -ForegroundColor Yellow "Check if submodules are up to date. You can use 'git submodule update' to fix this";
}
elseif ($submoduleStatus -eq 2) {
# not initialized
Write-Host -ForegroundColor Yellow "Check if submodules are initialized. You can run 'git submodule init' to initialize them."
}
elseif ($submoduleStatus -eq 3) {
# git not found, maybe submodules not synced?
Write-Host -ForegroundColor Yellow "Could not check if submodules are initialized correctly. Maybe git is not installed?"
}
else {
#Write-Host "Submodules are up to date";
}
}
exit $exitCodeOfTests

2
src/ImageSharp/ImageSharp.csproj

@ -10,8 +10,6 @@
<VersionPrefix Condition="$(packageversion) != ''">$(packageversion)</VersionPrefix>
<VersionPrefix Condition="$(packageversion) == ''">0.0.1</VersionPrefix>
<TargetFrameworks>netcoreapp2.1;netstandard1.3;netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(skipFullFramework) != 'true'">$(TargetFrameworks);net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;netstandard2.0;netstandard1.3;net472</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

34
test.ps1

@ -0,0 +1,34 @@
param(
[Parameter(Mandatory, Position = 0)]
[string]$os,
[Parameter(Mandatory, Position = 1)]
[string]$targetFramework,
[Parameter(Mandatory, Position = 2)]
[string]$platform,
[Parameter(Mandatory, Position = 3)]
[bool]$codecov
)
if ($codecov -eq $TRUE) {
# xunit doesn't understand the CollectCoverage params
dotnet clean -c Debug
dotnet test -c Debug -f $targetFramework /p:codecov=true /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput='../../../coverage.xml'
}
else {
# There were issues matching the correct installed runtime if we do not specify it explicitly:
# https://github.com/xunit/xunit/issues/1476
# This fix assumes the base version is installed.
$coreTargetFrameworkRegex = '^netcoreapp(\d+\.\d+)$'
if ($targetFramework -match $coreTargetFrameworkRegex) {
$fxVersion = "--fx-version ${matches[1]}.0"
}
Set-Location $env:XUNIT_PATH
dotnet clean -c Release
dotnet xunit -c Release -f $targetFramework $fxVersion $platform
Set-Location $PSScriptRoot
}

3
tests/Directory.Build.props

@ -26,7 +26,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" IsImplicitlyDefined="true" />
<PackageReference Include="xunit" IsImplicitlyDefined="true" />
<PackageReference Include="xunit.runner.visualstudio" IsImplicitlyDefined="true" />
<PackageReference Include="coverlet.collector" IsImplicitlyDefined="true" />
<!--<PackageReference Include="coverlet.collector" IsImplicitlyDefined="true" />
<PackageReference Include="coverlet.msbuild" IsImplicitlyDefined="true" />-->
</ItemGroup>
<ItemGroup>

16
tests/Directory.Build.targets

@ -15,5 +15,19 @@
</PropertyGroup>
<Import Project="$(MSBuildThisFileDirectory)..\Directory.Build.targets" />
<ItemGroup>
<!--Test Dependencies-->
<PackageReference Update="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Update="Colourful" Version="2.0.3" />
<PackageReference Update="Magick.NET-Q16-AnyCPU" Version="7.14.4" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Update="Moq" Version="4.10.0" />
<PackageReference Update="Pfim" Version="0.9.1" />
<PackageReference Update="System.Drawing.Common" Version="4.7.0" />
<!--TODO: Fix implicit conversion issues so we can move to 2.4.1-->
<PackageReference Update="xunit" Version="2.3.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

4
tests/ImageSharp.Benchmarks/ImageSharp.Benchmarks.csproj

@ -5,9 +5,9 @@
<AssemblyName>ImageSharp.Benchmarks</AssemblyName>
<OutputType>Exe</OutputType>
<RootNamespace>SixLabors.ImageSharp.Benchmarks</RootNamespace>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks Condition="$(skipFullFramework) != 'true'">$(TargetFrameworks);net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
<GenerateProgramFile>false</GenerateProgramFile>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
<ItemGroup>

6
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj

@ -8,9 +8,9 @@
<Prefer32Bit>false</Prefer32Bit>
<RootNamespace>SixLabors.ImageSharp.Sandbox46</RootNamespace>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks Condition="$(skipFullFramework) != 'true'">$(TargetFrameworks);net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;net472</TargetFrameworks>
<StartupObject>SixLabors.ImageSharp.Sandbox46.Program</StartupObject>
<IsTestProject>false</IsTestProject>
</PropertyGroup>
<ItemGroup>
@ -22,5 +22,5 @@
<PackageReference Include="Moq" />
<PackageReference Include="System.Drawing.Common" />
</ItemGroup>
</Project>

13
tests/ImageSharp.Tests/ImageSharp.Tests.csproj

@ -2,8 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1</TargetFrameworks>
<TargetFrameworks Condition="$(skipFullFramework) != 'true'">$(TargetFrameworks);net462;net472</TargetFrameworks>
<TargetFrameworks>netcoreapp2.1;net462;net472</TargetFrameworks>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<DebugType Condition="$(codecov) != ''">full</DebugType>
@ -12,12 +11,22 @@
<AssemblyName>SixLabors.ImageSharp.Tests</AssemblyName>
<Platforms>AnyCPU;x64;x86</Platforms>
<RootNamespace>SixLabors.ImageSharp.Tests</RootNamespace>
<!--Used by coverlet dues to reference issueswith SixLabors.Core-->
<!--https://github.com/tonerdo/coverlet/blob/master/Documentation/KnowIssues.md#4-failed-to-resolve-assembly-during-instrumentation-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<DotNetCliToolReference Include="dotnet-xunit" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Magick.NET-Q16-AnyCPU" />
<PackageReference Include="Moq" />
<PackageReference Include="System.Drawing.Common" />
<PackageReference Include="coverlet.collector" Version="1.1.0"/>
<PackageReference Include="coverlet.msbuild" Version="2.8.0" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save