From e64b9104eefbc8943c184f43c2abaa8dc2fd9abe Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Thu, 15 Jan 2026 18:46:20 +0100 Subject: [PATCH 1/4] Updated the testing environment for local development --- Agents.md | 26 +++- Directory.Build.targets | 102 +-------------- scripts/report-test-results.ps1 | 88 +++++++++++++ scripts/run-tests.ps1 | 215 ++++++++++++++++++++++++++++++++ scripts/test-utils.ps1 | 62 +++++++++ 5 files changed, 387 insertions(+), 106 deletions(-) create mode 100644 scripts/report-test-results.ps1 create mode 100644 scripts/run-tests.ps1 create mode 100644 scripts/test-utils.ps1 diff --git a/Agents.md b/Agents.md index b81241096..8a2583310 100644 --- a/Agents.md +++ b/Agents.md @@ -18,12 +18,19 @@ dotnet msbuild /t:DownloadNativeSDKs src/Sentry.Unity # Build the Unity SDK dotnet build -# Run all tests -./test.sh +# Run all tests (builds SDK first) +pwsh scripts/run-tests.ps1 -# Run specific test targets -dotnet msbuild /t:UnityEditModeTest /p:Configuration=Release test/Sentry.Unity.Editor.Tests -dotnet msbuild /t:UnityPlayModeTest /p:Configuration=Release +# Run specific test types +pwsh scripts/run-tests.ps1 -PlayMode +pwsh scripts/run-tests.ps1 -EditMode + +# Run filtered tests +pwsh scripts/run-tests.ps1 -Filter "TestClassName" +pwsh scripts/run-tests.ps1 -PlayMode -Filter "Throttler" + +# Skip build for faster iteration +pwsh scripts/run-tests.ps1 -SkipBuild -Filter "MyTest" # Integration testing (local) ./test/Scripts.Integration.Test/integration-test.ps1 -Platform "macOS" -UnityVersion "2021.3.45f2" @@ -482,7 +489,14 @@ Key options: ### Running All Tests ```bash -./test.sh +# Run all tests (builds SDK first) +pwsh scripts/run-tests.ps1 + +# Run with filtering +pwsh scripts/run-tests.ps1 -Filter "TestClassName" + +# Skip build for faster iteration +pwsh scripts/run-tests.ps1 -SkipBuild ``` ### Integration Test Scripts diff --git a/Directory.Build.targets b/Directory.Build.targets index 5e471defd..ba5064f3f 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -398,7 +398,7 @@ Related: https://forum.unity.com/threads/6572-debugger-agent-unable-to-listen-on - + @@ -411,7 +411,7 @@ Related: https://forum.unity.com/threads/6572-debugger-agent-unable-to-listen-on - + @@ -465,104 +465,6 @@ File.WriteAllLines(PackageManifestFile, lines); - - - - - - - - - - - - - 1 ? "s" : "")}."; -Log.LogError(errorMessage); - -Success = false; - -void PrintFailedTests(XElement element) -{ - foreach (var descendant in element.Descendants()) - { - if (descendant.Name != "test-case" - || descendant.Attribute("result")?.Value != "Failed") - { - continue; - } - - if (descendant.Descendants().Any(d => d.Name == "test-case")) - { - PrintFailedTests(descendant); - } - else - { - var sb = new StringBuilder() - .Append("Test ") - .Append(descendant.Attribute("id")?.Value) - .Append(": ") - .AppendLine(descendant.Attribute("name")?.Value); - - var failure = descendant.Descendants("failure") - .Descendants("message") - .FirstOrDefault() - ?.Value; - - var stack = descendant.Descendants("failure") - .Descendants("stack-trace") - .FirstOrDefault() - ?.Value; - - sb.AppendLine(failure) - .Append("Test StackTrace: ") - .AppendLine(stack); - -// MSBuild is breaking each line as if it was an error per line and not a single error. -// So Log.LogError got replaced by Console.WriteLine for now. - Console.WriteLine(sb.ToString()); - } - } -} -]]> - - - - - - - - - - - - - - - - - - - - - - + diff --git a/scripts/download-native-sdks.ps1 b/scripts/download-native-sdks.ps1 new file mode 100644 index 000000000..63c3b9588 --- /dev/null +++ b/scripts/download-native-sdks.ps1 @@ -0,0 +1,136 @@ +#!/usr/bin/env pwsh + +param( + [Parameter()] + [string]$RepoRoot = "$PSScriptRoot/.." +) + +Set-StrictMode -Version latest +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $true + +$ArtifactsDestination = Join-Path $RepoRoot "package-dev/Plugins" + +# SDK definitions with their existence checks +$SDKs = @( + @{ + Name = "Windows" + Destination = Join-Path $ArtifactsDestination "Windows" + CheckFile = "Sentry/sentry.dll" + }, + @{ + Name = "Linux" + Destination = Join-Path $ArtifactsDestination "Linux" + CheckFile = "Sentry/libsentry.so" + }, + @{ + Name = "Android" + Destination = Join-Path $ArtifactsDestination "Android" + CheckDir = "Sentry~" + ExpectedFileCount = 4 + } +) + +function Test-SDKPresent { + param($SDK) + + if ($SDK.ContainsKey('CheckFile')) { + $checkPath = Join-Path $SDK.Destination $SDK.CheckFile + return Test-Path $checkPath + } + elseif ($SDK.ContainsKey('CheckDir')) { + $checkPath = Join-Path $SDK.Destination $SDK.CheckDir + if (-not (Test-Path $checkPath)) { + return $false + } + $fileCount = (Get-ChildItem -Path $checkPath -File).Count + return $fileCount -ge $SDK.ExpectedFileCount + } + return $false +} + +function Get-LatestSuccessfulRunId { + Write-Host "Fetching latest successful CI run ID..." -ForegroundColor Yellow + + $result = gh run list --branch main --workflow CI --json "conclusion,databaseId" --jq 'first(.[] | select(.conclusion == "success") | .databaseId)' + + if (-not $result -or $result -eq "null") { + Write-Error "Failed to find a successful CI run on main branch" + exit 1 + } + + Write-Host "Found run ID: $result" -ForegroundColor Green + return $result +} + +function Download-SDK { + param( + [Parameter(Mandatory)] + [string]$Name, + [Parameter(Mandatory)] + [string]$Destination, + [Parameter(Mandatory)] + [string]$RunId + ) + + Write-Host "Downloading $Name SDK..." -ForegroundColor Yellow + + # Remove existing directory if present (partial download) + if (Test-Path $Destination) { + Write-Host " Removing existing directory..." -ForegroundColor Gray + Remove-Item -Path $Destination -Recurse -Force + } + + $artifactName = "$Name-sdk" + gh run download $RunId -n $artifactName -D $Destination + + if ($LASTEXITCODE -ne 0) { + Write-Error "Failed to download $Name SDK" + exit 1 + } + + Write-Host " Downloaded $Name SDK successfully" -ForegroundColor Green +} + +# Main logic +Write-Host "Checking native SDK status..." -ForegroundColor Cyan +Write-Host "" + +$sdksToDownload = @() + +foreach ($sdk in $SDKs) { + if (Test-SDKPresent $sdk) { + Write-Host "$($sdk.Name) SDK already present, skipping download." -ForegroundColor Green + } + else { + Write-Host "$($sdk.Name) SDK not found, will download." -ForegroundColor Yellow + $sdksToDownload += $sdk + } +} + +Write-Host "" + +if ($sdksToDownload.Count -eq 0) { + Write-Host "All native SDKs are already present." -ForegroundColor Green + exit 0 +} + +# Fetch run ID only if we need to download something +$runId = Get-LatestSuccessfulRunId + +foreach ($sdk in $sdksToDownload) { + Download-SDK -Name $sdk.Name -Destination $sdk.Destination -RunId $runId +} + +Write-Host "" +Write-Host "Restoring package-dev/Plugins to latest git commit..." -ForegroundColor Yellow +Push-Location $RepoRoot +try { + git restore package-dev/Plugins +} +finally { + Pop-Location +} + +Write-Host "" +Write-Host "Native SDK download completed successfully!" -ForegroundColor Green