Repository navigation
fix(sourcegen): report generic test rows whose type arguments cannot be inferred #7187
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba818d1
fix(sourcegen): report generic test rows whose type arguments cannot …
thomhurst 0e0a62b
fix(sourcegen): run every data source that infers an existing instant…
thomhurst ccf1b36
fix(sourcegen): name Nullable<T> return types by their open form
thomhurst 7128cf6
fix(sourcegen): name return types that take type parameters from a co…
thomhurst 891ec8f
fix(sourcegen): keep dropping duplicate-inferring sources on [Generat…
thomhurst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
tests/TUnit.Core.SourceGenerator.Tests/Bugs/7163/Tests7163.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| namespace TUnit.Core.SourceGenerator.Tests; | ||
|
|
||
| /// <summary> | ||
| /// A generic test method whose type arguments its data source's declared type cannot determine must | ||
| /// be emitted as an entry whose rows fail with an explanation, instead of being dropped (#7163). | ||
| /// </summary> | ||
| internal class Tests7163 : TestsBase | ||
| { | ||
| [Test] | ||
| public Task Test() => RunTest(Path.Combine( | ||
| Git.TestsDirectory.FullName, | ||
| "TUnit.TestProject", | ||
| "Bugs", | ||
| "_7163", | ||
| "UninferableGenericMethodTests.cs"), | ||
| async generatedFiles => | ||
| { | ||
| const string cannotInfer = "Could not infer the type arguments of generic test method 'Generic' from data source [MethodDataSource(nameof(Rows))]"; | ||
|
|
||
| string SourceFor(string className) => generatedFiles.Single(f => | ||
| f.Contains($"typeof(global::TUnit.TestProject.Bugs._7163.{className})")); | ||
|
|
||
| // Uninferable rows: the data source is wrapped so each of its rows fails. | ||
| foreach (var className in new[] { "ObjectRowsTests", "ObjectArrayRowsTests" }) | ||
| { | ||
| var source = SourceFor(className); | ||
| await Assert.That(source).Contains($"global::TUnit.Core.GenericConstraintViolationDataSource.Create(\"{cannotInfer}"); | ||
| await Assert.That(source).DoesNotContain("instance.Generic<"); | ||
| } | ||
|
|
||
| // The inferable row still runs, beside the failing source. | ||
| var partly = SourceFor("PartlyInferableTests"); | ||
| await Assert.That(partly).Contains("instance.Generic<int>("); | ||
| await Assert.That(partly).Contains($"global::TUnit.Core.GenericConstraintViolationDataSource.Create(\"{cannotInfer}"); | ||
|
|
||
| // [GenerateGenericTest] lists the type arguments, so nothing is reported. | ||
| var generateGeneric = SourceFor("GenerateGenericTestWithObjectRowsTests"); | ||
| await Assert.That(generateGeneric).Contains("instance.Generic<int>("); | ||
| await Assert.That(generateGeneric).DoesNotContain("GenericConstraintViolationDataSource"); | ||
|
|
||
| // No data source: a single failing row. | ||
| var noDataSource = SourceFor("NoDataSourceTests"); | ||
| await Assert.That(noDataSource).Contains("global::TUnit.Core.GenericConstraintViolationDataSource.Create(\"Could not infer the type arguments of generic test method 'Generic': it has no data source to infer them from."); | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.