/// <summary> /// Initializes a new instance of the <see cref="AttributeTargetGeneratorTestResult"/> struct. /// </summary> /// <param name="generatorDriver">A <see cref="CSharpGeneratorDriver"/> that was used to perform the test.</param> /// <param name="inputCompilation">A <see cref="CSharpCompilation"/> that represent an input for the tested <see cref="ISourceGenerator"/>.</param> /// <param name="outputCompilation">A <see cref="CSharpCompilation"/> that was created by the tested <see cref="ISourceGenerator"/>.</param> public AttributeTargetGeneratorTestResult(GeneratorDriver generatorDriver, CSharpCompilation inputCompilation, CSharpCompilation outputCompilation) { InputCompilation = inputCompilation; OutputCompilation = outputCompilation; _runResult = generatorDriver.GetRunResult().Results[0]; if (_runResult.Exception is null && _runResult.GeneratedSources.Length > 1) { Attribute = _runResult.GeneratedSources[0]; Source = _runResult.GeneratedSources[1]; IsGenerated = Attribute.SyntaxTree is CSharpSyntaxTree && Source.SyntaxTree is CSharpSyntaxTree; }
/// <summary> /// Initializes a new instance of the <see cref="SingletonGeneratorTestResult"/> struct. /// </summary> /// <param name="generatorDriver">A <see cref="CSharpGeneratorDriver"/> that was used to perform the test.</param> /// <param name="inputCompilation">A <see cref="CSharpCompilation"/> that represent an input for the tested <see cref="ISourceGenerator"/>.</param> /// <param name="outputCompilation">A <see cref="CSharpCompilation"/> that was created by the tested <see cref="ISourceGenerator"/>.</param> /// <param name="sourceIndex">Index of the target <see cref="CSharpSyntaxTree"/> in the generator's output.</param> public SingletonGeneratorTestResult(CSharpGeneratorDriver generatorDriver, CSharpCompilation inputCompilation, CSharpCompilation outputCompilation, int sourceIndex) { InputCompilation = inputCompilation; OutputCompilation = outputCompilation; _runResult = generatorDriver.GetRunResult().Results[0]; bool isGenerated = _runResult.Exception is null && _runResult.GeneratedSources.Length > sourceIndex; if (isGenerated) { _sourceResult = _runResult.GeneratedSources[sourceIndex]; _tree = _sourceResult.SyntaxTree as CSharpSyntaxTree; isGenerated = _tree is not null; } else { _sourceResult = default; _tree = null; } IsGenerated = isGenerated; }