Skip to content

Commit aecda3c

Browse files
committed
#453 the test file can be struct :)
1 parent df9d611 commit aecda3c

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

test/FastExpressionCompiler.IssueTests/Issue455_TypeAs_should_return_null.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace FastExpressionCompiler.LightExpression.IssueTests;
99
namespace FastExpressionCompiler.IssueTests;
1010
#endif
1111

12-
public class Issue455_TypeAs_should_return_null : ITest, ITestX
12+
public struct Issue455_TypeAs_should_return_null : ITest, ITestX
1313
{
1414
public int Run()
1515
{

test/FastExpressionCompiler.UnitTests/TestTools.cs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ public record struct TestFailure(
573573

574574
public record struct TestStats(
575575
string TestsName,
576-
string TestsFile,
577576
Exception TestStopException,
578577
int TestCount,
579578
int FirstFailureIndex,
@@ -591,10 +590,11 @@ public struct TestContext
591590
public readonly TestRun TestRun;
592591
public TestContext(TestRun testRun) => TestRun = testRun;
593592

593+
// A trick to automatically increment the test count when passing the TestRun to the test method expecting TextContext,
594+
// so that while wrapping TestRun in Context, it additionally increments the test count without incrementing it manually.
594595
[MethodImpl(MethodImplOptions.AggressiveInlining)]
595596
public static implicit operator TestContext(TestRun t)
596597
{
597-
// A trick to automatically increment the test count when passing context to the test method
598598
t.TotalTestCount += 1;
599599
return new TestContext(t);
600600
}
@@ -656,20 +656,19 @@ public bool AreEqual<T>(T expected, T actual,
656656
[CallerLineNumber]
657657
#endif
658658
int sourceLineNumber = -1) =>
659-
Equals(expected, actual) ||
660-
AddFailure(testName, sourceLineNumber, AssertKind.AreEqual,
661-
$"Expected `AreEqual({expectedName}, {actualName})`, but found `{expected.ToCode()}` is Not equal to `{actual.ToCode()}`");
659+
Equals(expected, actual) ||
660+
AddFailure(testName, sourceLineNumber, AssertKind.AreEqual,
661+
$"Expected `AreEqual({expectedName}, {actualName})`, but found `{expected.ToCode()}` is Not equal to `{actual.ToCode()}`");
662662
}
663663

664664
/// <summary>Per-thread context, accumulating the stats and failures in its Run method.</summary>
665665
public sealed class TestRun
666666
{
667667
public int TotalTestCount;
668-
// todo: @perf it may use ImTools.SmallList for the stats and failures to more local access to the Count
669-
public List<TestStats> Stats = new();
670-
public List<TestFailure> Failures = new();
668+
public SmallList<TestStats> Stats;
669+
public SmallList<TestFailure> Failures;
671670

672-
public void Run(ITestX test, TestTracking tracking = TestTracking.TrackFailedTestsOnly)
671+
public void Run<T>(T test, TestTracking tracking = TestTracking.TrackFailedTestsOnly) where T : ITestX
673672
{
674673
var totalTestCount = TotalTestCount;
675674
var failureCount = Failures.Count;
@@ -688,14 +687,12 @@ public void Run(ITestX test, TestTracking tracking = TestTracking.TrackFailedTes
688687
tracking == TestTracking.TrackAllTests ||
689688
tracking == TestTracking.TrackFailedTestsOnly & testFailureCount > 0)
690689
{
691-
// todo: @wip is there a more performant way to get the test name and file?
690+
// todo: @perf Or may be we can put it under the debug only?
692691
var testsType = test.GetType();
693692
var testsName = testsType.Name;
694-
var testsFile = new Uri(testsType.Assembly.Location).LocalPath;
695-
696693
var testCount = TotalTestCount - totalTestCount;
697694

698-
var stats = new TestStats(testsName, testsFile, testStopException, testCount, failureCount, testFailureCount);
695+
var stats = new TestStats(testsName, testStopException, testCount, failureCount, testFailureCount);
699696
Stats.Add(stats);
700697

701698
// todo: @wip better output?
@@ -709,7 +706,7 @@ public void Run(ITestX test, TestTracking tracking = TestTracking.TrackFailedTes
709706
Console.WriteLine($"Test '{testsName}' failed {testFailureCount} time{(testFailureCount == 1 ? "" : "s")}:");
710707
for (var i = 0; i < testFailureCount; ++i)
711708
{
712-
var f = Failures[failureCount + i];
709+
ref var f = ref Failures.GetSurePresentItemRef(failureCount + i);
713710
Console.WriteLine($"#{i} at line {f.SourceLineNumber}:{Environment.NewLine}'{f.Message}'");
714711
}
715712
}

0 commit comments

Comments
 (0)