Skip to content
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

Use index operator #4419

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/Adapter/MSTest.TestAdapter/DynamicDataOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private static bool TryHandleTupleDataSource(object data, List<object[]> objects
#else
Type type = data.GetType();
if (IsTupleOrValueTuple(data.GetType(), out int tupleSize)
&& (objects.Count == 0 || objects[objects.Count - 1].Length == tupleSize))
&& (objects.Count == 0 || objects[^1].Length == tupleSize))
{
object[] array = new object[tupleSize];
for (int i = 0; i < tupleSize; i++)
Expand Down
8 changes: 2 additions & 6 deletions src/Adapter/MSTest.TestAdapter/Execution/TestClassInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,7 @@ void DoRun()
{
if (results.Length > 0)
{
#pragma warning disable IDE0056 // Use index operator
UnitTestResult lastResult = results[results.Length - 1];
#pragma warning restore IDE0056 // Use index operator
UnitTestResult lastResult = results[^1];
lastResult.Outcome = ObjectModelUnitTestOutcome.Error;
lastResult.ErrorMessage = ex.Message;
lastResult.ErrorStackTrace = ex.StackTrace;
Expand All @@ -733,9 +731,7 @@ void DoRun()
{
if (results.Length > 0)
{
#pragma warning disable IDE0056 // Use index operator
UnitTestResult lastResult = results[results.Length - 1];
#pragma warning restore IDE0056 // Use index operator
UnitTestResult lastResult = results[^1];
lastResult.StandardOut += initializationLogs;
lastResult.StandardError += initializationErrorLogs;
lastResult.DebugTrace += initializationTrace;
Expand Down
14 changes: 6 additions & 8 deletions src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,14 @@ UnitTestResult[] SafeRunTestMethod(string initializationLogs, string initializat
result = [new()];
}

#pragma warning disable IDE0056 // Use index operator
result[result.Length - 1] = new UnitTestResult(new TestFailedException(UnitTestOutcome.Error, ex.TryGetMessage(), ex.TryGetStackTraceInformation()))
result[^1] = new UnitTestResult(new TestFailedException(UnitTestOutcome.Error, ex.TryGetMessage(), ex.TryGetStackTraceInformation()))
{
StandardOut = result[result.Length - 1].StandardOut,
StandardError = result[result.Length - 1].StandardError,
DebugTrace = result[result.Length - 1].DebugTrace,
TestContextMessages = result[result.Length - 1].TestContextMessages,
Duration = result[result.Length - 1].Duration,
StandardOut = result[^1].StandardOut,
StandardError = result[^1].StandardError,
DebugTrace = result[^1].DebugTrace,
TestContextMessages = result[^1].TestContextMessages,
Duration = result[^1].Duration,
};
#pragma warning restore IDE0056 // Use index operator
}
finally
{
Expand Down
8 changes: 2 additions & 6 deletions src/Adapter/MSTest.TestAdapter/Execution/UnitTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ private static void RunAssemblyCleanupIfNeeded(ITestContext testContext, ClassCl
{
if (results.Length > 0)
{
#pragma warning disable IDE0056 // Use index operator
UnitTestResult lastResult = results[results.Length - 1];
#pragma warning restore IDE0056 // Use index operator
UnitTestResult lastResult = results[^1];
lastResult.Outcome = UnitTestOutcome.Error;
lastResult.ErrorMessage = ex.Message;
lastResult.ErrorStackTrace = ex.StackTrace;
Expand All @@ -293,9 +291,7 @@ private static void RunAssemblyCleanupIfNeeded(ITestContext testContext, ClassCl
{
if (results.Length > 0)
{
#pragma warning disable IDE0056 // Use index operator
UnitTestResult lastResult = results[results.Length - 1];
#pragma warning restore IDE0056 // Use index operator
UnitTestResult lastResult = results[^1];
lastResult.StandardOut += initializationLogs;
lastResult.StandardError += initializationErrorLogs;
lastResult.DebugTrace += initializationTrace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ public void Sort(Comparison<T> compare)

public void CopyTo(T[] array, int start) => _builder.CopyTo(array, start);

public T Last() =>
#pragma warning disable IDE0056
_builder[_builder.Count - 1];
#pragma warning restore IDE0056
public T Last() => _builder[^1];

public T First() => _builder[0];

Expand Down
Loading