roslyn-sdk icon indicating copy to clipboard operation
roslyn-sdk copied to clipboard

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

Open Youssef1313 opened this issue 2 years ago • 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,
				}
			}

Youssef1313 avatar Sep 24 '23 15:09 Youssef1313

We already allow Sources to be empty if the test includes a generated document: https://github.com/dotnet/roslyn-sdk/blob/5f6ffda5efd6198836c038e1ab07cd3b0aba77a7/src/Microsoft.CodeAnalysis.Testing/Microsoft.CodeAnalysis.Analyzer.Testing/AnalyzerTest%601.cs#L190-L194

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

sharwell avatar Sep 26 '23 13:09 sharwell

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.

Youssef1313 avatar Sep 26 '23 14:09 Youssef1313

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

sharwell avatar Sep 26 '23 14:09 sharwell