Skip to content

Commit

Permalink
Use index operator
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 21, 2024
1 parent 5e4d216 commit 159e1f5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 25 deletions.
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

0 comments on commit 159e1f5

Please sign in to comment.