-
Notifications
You must be signed in to change notification settings - Fork 292
Convert ExitCodes from static class to enum #7876
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -108,7 +108,7 @@ await ExecuteRequestAsync( | |||||
| { | ||||||
| requestExecuteStop ??= _clock.UtcNow; | ||||||
|
|
||||||
| exitCode = ExitCodes.TestSessionAborted; | ||||||
| exitCode = (int)ExitCodes.TestSessionAborted; | ||||||
| await _logger.LogInformationAsync("Test session canceled.").ConfigureAwait(false); | ||||||
| } | ||||||
| finally | ||||||
|
|
@@ -128,7 +128,7 @@ await ExecuteRequestAsync( | |||||
| { TelemetryProperties.RequestProperties.AdapterLoadStop, adapterLoadStop }, | ||||||
| { TelemetryProperties.RequestProperties.RequestExecuteStart, requestExecuteStart }, | ||||||
| { TelemetryProperties.RequestProperties.RequestExecuteStop, requestExecuteStop }, | ||||||
| { TelemetryProperties.HostProperties.ExitCodePropertyName, cancellationToken.IsCancellationRequested ? ExitCodes.TestSessionAborted : exitCode.ToString(CultureInfo.InvariantCulture) }, | ||||||
| { TelemetryProperties.HostProperties.ExitCodePropertyName, cancellationToken.IsCancellationRequested ? (int)ExitCodes.TestSessionAborted : exitCode.ToString(CultureInfo.InvariantCulture) }, | ||||||
|
||||||
| { TelemetryProperties.HostProperties.ExitCodePropertyName, cancellationToken.IsCancellationRequested ? (int)ExitCodes.TestSessionAborted : exitCode.ToString(CultureInfo.InvariantCulture) }, | |
| { TelemetryProperties.HostProperties.ExitCodePropertyName, exitCode.ToString(CultureInfo.InvariantCulture) }, |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,16 +129,16 @@ public Task ConsumeAsync(IDataProducer dataProducer, IData value, CancellationTo | |
|
|
||
| public int GetProcessExitCode() | ||
| { | ||
| int exitCode = ExitCodes.Success; | ||
| exitCode = exitCode == ExitCodes.Success && _policiesService.IsMaxFailedTestsTriggered ? ExitCodes.TestExecutionStoppedForMaxFailedTests : exitCode; | ||
| exitCode = exitCode == ExitCodes.Success && _testAdapterTestSessionFailure ? ExitCodes.TestAdapterTestSessionFailure : exitCode; | ||
| exitCode = exitCode == ExitCodes.Success && _failedTestsCount > 0 ? ExitCodes.AtLeastOneTestFailed : exitCode; | ||
| exitCode = exitCode == ExitCodes.Success && _policiesService.IsAbortTriggered ? ExitCodes.TestSessionAborted : exitCode; | ||
| exitCode = exitCode == ExitCodes.Success && _totalRanTests == 0 ? ExitCodes.ZeroTests : exitCode; | ||
| int exitCode = (int)ExitCodes.Success; | ||
| exitCode = exitCode == (int)ExitCodes.Success && _policiesService.IsMaxFailedTestsTriggered ? (int)ExitCodes.TestExecutionStoppedForMaxFailedTests : exitCode; | ||
| exitCode = exitCode == (int)ExitCodes.Success && _testAdapterTestSessionFailure ? (int)ExitCodes.TestAdapterTestSessionFailure : exitCode; | ||
| exitCode = exitCode == (int)ExitCodes.Success && _failedTestsCount > 0 ? (int)ExitCodes.AtLeastOneTestFailed : exitCode; | ||
| exitCode = exitCode == (int)ExitCodes.Success && _policiesService.IsAbortTriggered ? (int)ExitCodes.TestSessionAborted : exitCode; | ||
| exitCode = exitCode == (int)ExitCodes.Success && _totalRanTests == 0 ? (int)ExitCodes.ZeroTests : exitCode; | ||
|
Comment on lines
+132
to
+137
|
||
|
|
||
| if (_commandLineOptions.TryGetOptionArgumentList(PlatformCommandLineProvider.MinimumExpectedTestsOptionKey, out string[]? argumentList)) | ||
| { | ||
| exitCode = exitCode == ExitCodes.Success && _totalRanTests < int.Parse(argumentList[0], CultureInfo.InvariantCulture) ? ExitCodes.MinimumExpectedTestsPolicyViolation : exitCode; | ||
| exitCode = exitCode == (int)ExitCodes.Success && _totalRanTests < int.Parse(argumentList[0], CultureInfo.InvariantCulture) ? (int)ExitCodes.MinimumExpectedTestsPolicyViolation : exitCode; | ||
| } | ||
|
|
||
| // If the user has specified the IgnoreExitCode, then we don't want to return a non-zero exit code if the exit code matches the one specified. | ||
|
|
@@ -155,7 +155,7 @@ public int GetProcessExitCode() | |
| { | ||
| if (exitCodeToIgnore.Split(';').Any(code => int.TryParse(code, out int parsedExitCode) && parsedExitCode == exitCode)) | ||
| { | ||
| exitCode = ExitCodes.Success; | ||
| exitCode = (int)ExitCodes.Success; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -226,7 +226,7 @@ public async Task RunTests_With_MSTestRunner_Standalone_Selectively_Enabled_Exte | |
| testHostResult.AssertOutputContainsSummary(0, 1, 0); | ||
|
|
||
| testHostResult = await testHost.ExecuteAsync(command: invalidCommandLineArg, cancellationToken: TestContext.CancellationToken); | ||
| Assert.AreEqual(ExitCodes.InvalidCommandLine, testHostResult.ExitCode); | ||
| Assert.AreEqual((int)ExitCodes.InvalidCommandLine, testHostResult.ExitCode); | ||
|
Contributor
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. [Assertion] This PR adds a typed Impact: Harder to diagnose CI failures — the assertion failure message won't include the test host output that shows why the exit code was wrong. Suggestion: Replace with the typed overload for a more informative failure message: // instead of:
Assert.AreEqual((int)ExitCodes.InvalidCommandLine, testHostResult.ExitCode);
// use:
testHostResult.AssertExitCodeIs(ExitCodes.InvalidCommandLine); |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -283,7 +283,7 @@ public async Task RunTests_With_MSTestRunner_Standalone_Enable_Default_Extension | |
| } | ||
| else | ||
| { | ||
| Assert.AreEqual(ExitCodes.InvalidCommandLine, testHostResult.ExitCode); | ||
| Assert.AreEqual((int)ExitCodes.InvalidCommandLine, testHostResult.ExitCode); | ||
| } | ||
| } | ||
| } | ||
|
|
||
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.
Renaming wasn't addressed here.