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

Tests should be allowed to be run with empty TestState.Sources #1121

Open
Youssef1313 opened this issue Sep 24, 2023 · 3 comments
Open

Tests should be allowed to be run with empty TestState.Sources #1121

Youssef1313 opened this issue Sep 24, 2023 · 3 comments
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing

Comments

@Youssef1313
Copy link
Member

Currently this scenario fails with:

Assert.IsTrue failed. expected 'TestState.Sources' to be non-empty

My use case is testing a generator where I only need to supply an additional file. For now, I have to add the following as a workaround:

			TestState =
			{
				Sources =
				{
					string.Empty,
				}
			}
@sharwell
Copy link
Member

We already allow Sources to be empty if the test includes a generated document:

if (!TestState.GeneratedSources.Any())
{
// Verify the test state has at least one source, which may or may not be generated
Verify.NotEmpty($"{nameof(TestState)}.{nameof(SolutionState.Sources)}", TestState.Sources);
}

It might be fine to remove this check. I'm not aware of any case where it's caught a test bug.

@Youssef1313
Copy link
Member Author

Youssef1313 commented Sep 26, 2023

Ah, I was using the generator testing you done somewhere where there is a #define WRITE_EXPECTED that adds (or writes) the generated code to disk.

So, with the first test run there wasn't GeneratedSources. That is probably why I hit this assert.

@sharwell
Copy link
Member

That's the same way I've hit this assert 😄

@sharwell sharwell added the Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-MS.CA.Testing Microsoft.CodeAnalysis.Testing
Projects
None yet
Development

No branches or pull requests

2 participants