dotnet/roslyn-sdk

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

Youssef1313 opened this issue · 3 comments

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,
				}
			}

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.

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.

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