-
-
Notifications
You must be signed in to change notification settings - Fork 58
chore: Updated the testing environment for local development #2480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+398
−109
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e64b910
Updated the testing environment for local development
bitsandfoxes 5d964a9
Added test logfile to gitignore and removed 'test.sh'
bitsandfoxes b102098
Feedback
bitsandfoxes ae5afe4
Merge branch 'main' into chore/testing-environment
bitsandfoxes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -398,7 +398,7 @@ Related: https://forum.unity.com/threads/6572-debugger-agent-unable-to-listen-on | |
| <!-- Unity exits with a non-zero exit code when running tests. We ignore it and manually check the test results instead. --> | ||
| <Delete Files="$(UnityTestPlayModeResultFilePath)" /> | ||
| <Exec EnvironmentVariables="IgnoreExitCode=true" Command="pwsh "$(RepoRoot)scripts/unity.ps1" $(UnityExec) -batchmode -nographics -runTests -testPlatform PlayMode -projectPath $(UnitySampleProjectPath) -testResults $(UnityTestPlayModeResultFilePath)" /> | ||
| <UnityTestResults Path="$(UnityTestPlayModeResultFilePath)" /> | ||
| <Exec Command="pwsh "$(RepoRoot)scripts/report-test-results.ps1" "$(UnityTestPlayModeResultFilePath)"" /> | ||
| </Target> | ||
|
|
||
| <!-- Run EditMode tests with dotnet msbuild /t:UnityEditModeTest test/Sentry.Unity.Editor.Tests --> | ||
|
|
@@ -411,7 +411,7 @@ Related: https://forum.unity.com/threads/6572-debugger-agent-unable-to-listen-on | |
| <!-- IgnoreStandardErrorWarningFormat="true" because of the intentional compilation error printed in GenerateOptions_NewSentryOptionsGarbageAppended_FailsToCompile(). --> | ||
| <Delete Files="$(UnityTestEditModeResultFilePath)" /> | ||
| <Exec EnvironmentVariables="IgnoreExitCode=true" IgnoreStandardErrorWarningFormat="true" Command="pwsh "$(RepoRoot)scripts/unity.ps1" $(UnityExec) -batchmode -nographics -runTests -testPlatform EditMode -projectPath $(UnitySampleProjectPath) -testResults $(UnityTestEditModeResultFilePath)"/> | ||
| <UnityTestResults Path="$(UnityTestEditModeResultFilePath)" /> | ||
| <Exec Command="pwsh "$(RepoRoot)scripts/report-test-results.ps1" "$(UnityTestEditModeResultFilePath)"" /> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now reuses the script that parses the test result for local development. |
||
| </Target> | ||
|
|
||
| <!-- Locate the TestRunner.dlls by filling the wildcard with the template version number. 3d is the default template --> | ||
|
|
@@ -465,104 +465,6 @@ File.WriteAllLines(PackageManifestFile, lines); | |
| </Task> | ||
| </UsingTask> | ||
|
|
||
| <!-- Parse test results --> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This now happens in |
||
| <UsingTask TaskName="UnityTestResults" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> | ||
| <ParameterGroup> | ||
| <Path ParameterType="System.String" Required="true" /> | ||
| </ParameterGroup> | ||
|
|
||
| <Task> | ||
| <Using Namespace="System" /> | ||
| <Using Namespace="System.IO" /> | ||
| <Using Namespace="System.Linq" /> | ||
| <Using Namespace="System.Xml.Linq" /> | ||
| <Code Type="Fragment" Language="cs"> | ||
| <![CDATA[ | ||
|
|
||
| if (!File.Exists(Path)) | ||
| { | ||
| Log.LogError("Test results file not found at " + Path); | ||
| return false; | ||
| } | ||
|
|
||
| var document = XDocument.Load(Path); | ||
| var testRun = document.Descendants("test-run").First(); | ||
|
|
||
| var total = testRun.Attribute("total").Value; | ||
| if (total == "0") | ||
| { | ||
| Log.LogError("Unity test results is empty."); | ||
| return false; | ||
| } | ||
|
|
||
| var result = testRun.Attribute("result").Value; | ||
|
|
||
| Log.LogCriticalMessage("UnityTestResults", null, null, null, 0, 0, 0, 0, "{0} in {1}s", result.Replace("(Child)", ""), testRun.Attribute("duration").Value); | ||
| Log.LogCriticalMessage("UnityTestResults", null, null, null, 0, 0, 0, 0, " Passed: {0,3}", testRun.Attribute("passed").Value); | ||
| Log.LogCriticalMessage("UnityTestResults", null, null, null, 0, 0, 0, 0, " Failed: {0,3}", testRun.Attribute("failed").Value); | ||
| Log.LogCriticalMessage("UnityTestResults", null, null, null, 0, 0, 0, 0, " Skipped: {0,3}", testRun.Attribute("skipped").Value); | ||
| Log.LogCriticalMessage("UnityTestResults", null, null, null, 0, 0, 0, 0, " Inconclusive: {0,3}", testRun.Attribute("inconclusive").Value); | ||
|
|
||
| if (result == "Passed") | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| PrintFailedTests(testRun); | ||
|
|
||
| var failed = testRun.Attribute("failed").Value; | ||
| var errorMessage = $"Test run completed with {failed} failing test{(int.Parse(failed) > 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()); | ||
| } | ||
| } | ||
| } | ||
| ]]> | ||
| </Code> | ||
| </Task> | ||
| </UsingTask> | ||
|
|
||
| <!-- Checks if the environment variable 'SENTRY_AUTH_TOKEN' has been set and creates the SentryCliOptions.asset for the sample project | ||
| This is meant for developers - so they don't have to configure the CLI options after each clean checkout (or git clean). | ||
| Gets automatically run after 'DownloadNativeSDKs' | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| <# | ||
| .SYNOPSIS | ||
| Reports Unity test results from NUnit XML file. | ||
|
|
||
| .DESCRIPTION | ||
| Parses NUnit XML test results and prints a summary. Exits with code 1 if tests failed. | ||
| Designed to be called from MSBuild targets. | ||
|
|
||
| .PARAMETER Path | ||
| Path to the NUnit XML test results file. | ||
|
|
||
| .EXAMPLE | ||
| pwsh scripts/report-test-results.ps1 artifacts/test/playmode/results.xml | ||
| #> | ||
|
|
||
| param( | ||
| [Parameter(Mandatory = $true, Position = 0)] | ||
| [string] $Path | ||
| ) | ||
|
|
||
| Set-StrictMode -Version latest | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| . $PSScriptRoot/test-utils.ps1 | ||
|
|
||
| if (-not (Test-Path $Path)) { | ||
| Write-Host "Test results file not found at $Path" -ForegroundColor Red | ||
| exit 1 | ||
| } | ||
|
|
||
| $results = Parse-TestResults $Path | ||
|
|
||
| if ($null -eq $results) { | ||
| Write-Host "Failed to parse test results" -ForegroundColor Red | ||
| exit 1 | ||
| } | ||
|
|
||
| if ($results.Total -eq 0) { | ||
| Write-Host "Unity test results is empty." -ForegroundColor Red | ||
| exit 1 | ||
| } | ||
|
|
||
| # Print summary (matching format from original C# implementation) | ||
| $status = if ($results.Success) { "Passed" } else { "Failed" } | ||
| Write-Host "$status in $($results.Duration)s" | ||
| Write-Host (" Passed: {0,3}" -f $results.Passed) | ||
| Write-Host (" Failed: {0,3}" -f $results.Failed) | ||
| Write-Host (" Skipped: {0,3}" -f $results.Skipped) | ||
| Write-Host (" Inconclusive: {0,3}" -f $results.Inconclusive) | ||
|
|
||
| # Print failed test details | ||
| if ($results.Failed -gt 0) { | ||
| Write-Host "" | ||
|
|
||
| # Re-parse to get stack traces (not included in Parse-TestResults) | ||
| [xml]$xml = Get-Content $Path | ||
| $failedNodes = $xml.SelectNodes("//test-case[@result='Failed']") | ||
|
|
||
| foreach ($node in $failedNodes) { | ||
| # Skip parent test-cases that contain child test-cases | ||
| if ($node.SelectNodes(".//test-case").Count -gt 0) { | ||
| continue | ||
| } | ||
|
|
||
| $name = $node.GetAttribute("name") | ||
| $id = $node.GetAttribute("id") | ||
| Write-Host "Test $id`: $name" | ||
|
|
||
| $message = $node.SelectSingleNode("failure/message") | ||
| if ($message) { | ||
| Write-Host $message.InnerText | ||
| } | ||
|
|
||
| $stackTrace = $node.SelectSingleNode("failure/stack-trace") | ||
| if ($stackTrace) { | ||
| Write-Host "Test StackTrace:" | ||
| Write-Host $stackTrace.InnerText | ||
| } | ||
|
|
||
| Write-Host "" | ||
| } | ||
|
|
||
| $testWord = if ($results.Failed -gt 1) { "tests" } else { "test" } | ||
| Write-Host "Test run completed with $($results.Failed) failing $testWord." -ForegroundColor Red | ||
| } | ||
|
|
||
| # Exit based on overall success (handles edge cases where result != "Passed" but failed count is 0) | ||
| if (-not $results.Success) { | ||
| exit 1 | ||
| } | ||
| exit 0 | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now reuses the script that parses the test result for local development.