Skip to content
Merged
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 cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ FUnit Test Runner
{
matcher.AddIncludePatterns(fileGlobs);
}
var csFiles = matcher.GetResultsInFullPath(currentDirectory).Where(File.Exists).ToList();
var csFiles = matcher.GetResultsInFullPath(currentDirectory).Where(File.Exists).ToArray();

List<string> validFUnitFiles = [];

Expand Down
3 changes: 1 addition & 2 deletions directives/FUnitSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public void Execute(GeneratorExecutionContext context)
var root = syntaxTree.GetCompilationUnitRoot();
var directives = root
.DescendantTrivia()
.Where(t => t.IsKind(SyntaxKind.WarningDirectiveTrivia))
.ToList(); // ToList is better than ToImmutableList in this case
.Where(t => t.IsKind(SyntaxKind.WarningDirectiveTrivia));

foreach (var trivia in directives)
{
Expand Down
8 changes: 4 additions & 4 deletions src/FUnit.TestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public sealed class TestSuite
/// Gets a read-only dictionary where the key is the test subject and the value is a list of test case descriptions.
/// </summary>
public IReadOnlyDictionary<string, IReadOnlyList<string>> TestsBySubject =>
this.cache_TestsBySubject ??= this._testCasesBySubject.ToDictionary(k => k.Key, v => v.Value.Select(x => x.Description).ToList() as IReadOnlyList<string>);
this.cache_TestsBySubject ??= this._testCasesBySubject.ToDictionary(k => k.Key, v => v.Value.Select(x => x.Description).ToArray() as IReadOnlyList<string>);
private Dictionary<string, IReadOnlyList<string>>? cache_TestsBySubject;

internal TestSuite(Action<Descriptor> builder)
Expand Down Expand Up @@ -278,7 +278,7 @@ internal async Task<TestResult> ExecuteCoreAsync(
foreach (var (description, error) in this._buildErrors)
{
errors.Add(
new(description, 1, new List<TestResult.Error>()
new(description, 1, new TestResult.Error[]
{
new(error.Message, error.StackTrace, IsFUnitSystemError: true, IsAssertionFailure: false),
}));
Expand All @@ -297,7 +297,7 @@ internal async Task<TestResult> ExecuteCoreAsync(

foreach (var tc in testCases)
{
List<TestResult.Error>? errors = null;
TestResult.Error[]? errors = null;

var failedCases = failedTestCases.Where(x => x.subject == tc.Subject && x.description == tc.Description);
if (failedCases.Any())
Expand All @@ -324,7 +324,7 @@ internal async Task<TestResult> ExecuteCoreAsync(

return new TestResult.Error(msg, e.StackTrace, IsFUnitSystemError: false, IsAssertionFailure: e is FUnitException);
})
.ToList();
.ToArray();
}

tests.Add(new(tc.Description, tc.ExecutionCount, errors));
Expand Down
16 changes: 8 additions & 8 deletions src/FUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ public static async Task<int> RunAsync(string[] args, Action<Descriptor> builder
var failedTestCases = Result.TestsBySubject
.SelectMany(x => x.Value.Select(test => (subject: x.Key, test)))
.Where(x => x.test.Errors?.Count is > 0)
.ToList();
.ToArray();
var skippedTestCases = Result.TestsBySubject
.SelectMany(x => x.Value)
.Where(x => x.ExecutionCount == 0)
.ToList();
.ToArray();

// NOTE: remove system errors from result
var totalTestCaseCount = Result.TestsBySubject.Sum(x => x.Value.Count(y => y.Errors?.All(error => error.IsFUnitSystemError) != true));
Expand All @@ -105,22 +105,22 @@ public static async Task<int> RunAsync(string[] args, Action<Descriptor> builder
ConsoleLogger.LogInfo("## Test Summary");
ConsoleLogger.LogInfo($"Options: {Result.Options} ");
ConsoleLogger.LogInfo($"Duration: {Result.TotalExecutionTime.ToString(TimeSpanFormat)} ");
if (skippedTestCases.Count > 0)
if (skippedTestCases.Length > 0)
{
ConsoleLogger.LogFailed($"{SR.MarkdownFailed} Total {skippedTestCases.Count} tests canceled");
ConsoleLogger.LogFailed($"{SR.MarkdownFailed} Total {skippedTestCases.Length} tests canceled");

return ~(failedTestCases.Count); // ok: bash treats -1 as 255 (byte)
return ~(failedTestCases.Length); // ok: bash treats -1 as 255 (byte)
}
else
{
if (failedTestCases.Count == 0)
if (failedTestCases.Length == 0)
{
ConsoleLogger.LogPassed($"{SR.MarkdownPassed} All Tests Passed: {totalTestCaseCount}");
}
else
{
var failedCount = failedTestCases.Count(x => x.test.Errors?.Any(y => y.IsAssertionFailure) ?? false);
var erroredCount = failedTestCases.Count - failedCount;
var erroredCount = failedTestCases.Length - failedCount;
ConsoleLogger.LogPassed($"Passed: {totalTestCaseCount - failedTestCaseCountWithoutSystemErrors} ({totalTestCaseCount}) ");
ConsoleLogger.LogFailed($"Failed: {failedCount} ");
if (erroredCount > 0)
Expand Down Expand Up @@ -157,7 +157,7 @@ public static async Task<int> RunAsync(string[] args, Action<Descriptor> builder
}
}

return failedTestCases.Count;
return failedTestCases.Length;
}
}
}