Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions .github/workflows/net48-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,17 @@ jobs:
- name: Run the complete net48 test suite with coverage
shell: pwsh
run: |
$testProjects = @(
'UnitsNet.Tests/UnitsNet.Tests.csproj',
'UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj',
'UnitsNet.NumberExtensions.CS14.Tests/UnitsNet.NumberExtensions.CS14.Tests.csproj',
'UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj'
)
Import-Module ./Build/build-functions.psm1
$testProjects = @(Get-TestProjects -Framework 'net48')
if ($testProjects.Count -eq 0) {
throw 'No test projects targeting net48 were found.'
}

New-Item -ItemType Directory -Force -Path Artifacts/Coverage | Out-Null

foreach ($testProject in $testProjects) {
$projectName = [IO.Path]::GetFileNameWithoutExtension($testProject)

$testArguments = @(
$testProject,
$testProject.FullName,
'--configuration', 'Release',
'--framework', 'net48',
'--logger', 'trx',
Expand All @@ -73,7 +70,7 @@ jobs:

dotnet tool run dotCover -- cover-dotnet `
--TargetWorkingDir $PWD.Path `
--Output "Artifacts/Coverage/$projectName.coverage.xml" `
--Output "Artifacts/Coverage/$($testProject.BaseName).coverage.xml" `
--ReportType DetailedXML `
--Filters '+:module=UnitsNet*;-:module=*Tests' `
--ReturnTargetExitCode `
Expand Down
38 changes: 27 additions & 11 deletions Build/build-functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,34 @@ function Start-Build {
write-host -foreground blue "Start-Build...END`n"
}

function Get-TestProjects {
Param(
[Parameter(Mandatory)]
[string] $Framework
)

$testProjects = Get-ChildItem -Path $root -Recurse -Filter "*.Tests.csproj" -File | Sort-Object FullName
foreach ($testProject in $testProjects) {
$propertiesJson = & dotnet msbuild $testProject.FullName `
-getProperty:TargetFrameworks,TargetFramework `
-nologo
if ($lastexitcode -ne 0) { throw "Failed to read target frameworks from $($testProject.FullName)." }

$properties = $propertiesJson | ConvertFrom-Json
$targetFrameworks = @($properties.Properties.TargetFrameworks -split ';') + $properties.Properties.TargetFramework
if ($targetFrameworks -contains $Framework) {
$testProject
}
}
}

function Start-Tests {
Param(
[switch] $SkipCoverage
)

$projectPaths = @(
"UnitsNet.Tests/UnitsNet.Tests.csproj",
"UnitsNet.NumberExtensions.Tests/UnitsNet.NumberExtensions.Tests.csproj",
"UnitsNet.NumberExtensions.CS14.Tests/UnitsNet.NumberExtensions.CS14.Tests.csproj",
"UnitsNet.Serialization.JsonNet.Tests/UnitsNet.Serialization.JsonNet.Tests.csproj"
)
$testProjects = @(Get-TestProjects -Framework "net10.0")
if ($testProjects.Count -eq 0) { throw "No test projects targeting net10.0 were found." }

# Parent dir must exist before xunit tries to write files to it
new-item -type directory -force $testReportDir 1> $null
Expand All @@ -52,10 +69,9 @@ function Start-Tests {
}

write-host -foreground blue "Run tests...`n---"
foreach ($projectPath in $projectPaths) {
$projectFileNameNoEx = [System.IO.Path]::GetFileNameWithoutExtension($projectPath)
$coverageReportFile = Join-Path $testCoverageDir "${projectFileNameNoEx}.coverage.xml"
$projectDir = Join-Path $root ([System.IO.Path]::GetDirectoryName($projectPath))
foreach ($testProject in $testProjects) {
$coverageReportFile = Join-Path $testCoverageDir "$($testProject.BaseName).coverage.xml"
$projectDir = $testProject.DirectoryName

# dotnet commands (xunit, dotcover) must run in same dir as project
push-location $projectDir
Expand Down Expand Up @@ -138,4 +154,4 @@ function Compress-ArtifactsAsZip {
write-host -foreground blue "Zip artifacts...END`n"
}

export-modulemember -function Remove-ArtifactsDir, Update-GeneratedCode, Start-Build, Start-Tests, Start-PackNugets, Compress-ArtifactsAsZip
export-modulemember -function Remove-ArtifactsDir, Update-GeneratedCode, Start-Build, Get-TestProjects, Start-Tests, Start-PackNugets, Compress-ArtifactsAsZip
Loading