diff --git a/src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs b/src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs index f2151e1..4d40b30 100644 --- a/src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs +++ b/src/Pretender.SourceGenerator/Emitter/GrandEmitter.cs @@ -1,14 +1,20 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System.Collections.Immutable; +using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Pretender.SourceGenerator.Emitter { internal class GrandEmitter { - public GrandEmitter() + private readonly ImmutableArray _pretendEmitters; + + public GrandEmitter(ImmutableArray pretendEmitters) + { + _pretendEmitters = pretendEmitters; + } + + public CompilationUnitSyntax Emit(CancellationToken cancellationToken) { - + throw new NotImplementedException(); } } } diff --git a/src/Pretender.SourceGenerator/Fakes/IKnownFake.cs b/src/Pretender.SourceGenerator/Fakes/IKnownFake.cs new file mode 100644 index 0000000..1b1a626 --- /dev/null +++ b/src/Pretender.SourceGenerator/Fakes/IKnownFake.cs @@ -0,0 +1,10 @@ +using Microsoft.CodeAnalysis; +using Pretender.SourceGenerator.Parser; + +namespace Pretender.SourceGenerator.Fakes +{ + internal interface IKnownFake + { + bool TryConstruct(INamedTypeSymbol typeSymbol, KnownTypeSymbols knownTypeSymbols, CancellationToken cancellationToken, out ITypeSymbol? fakeType); + } +} diff --git a/src/Pretender.SourceGenerator/Fakes/ILoggerFake.cs b/src/Pretender.SourceGenerator/Fakes/ILoggerFake.cs new file mode 100644 index 0000000..7e8ff76 --- /dev/null +++ b/src/Pretender.SourceGenerator/Fakes/ILoggerFake.cs @@ -0,0 +1,19 @@ +using Microsoft.CodeAnalysis; +using Pretender.SourceGenerator.Parser; + +namespace Pretender.SourceGenerator.Fakes +{ + internal class ILoggerFake : IKnownFake + { + public bool TryConstruct(INamedTypeSymbol typeSymbol, KnownTypeSymbols knownTypeSymbols, CancellationToken cancellationToken, out ITypeSymbol? fakeType) + { + fakeType = null; + if (SymbolEqualityComparer.Default.Equals(typeSymbol, knownTypeSymbols.MicrosoftExtensionsLoggingILogger)) + { + // TODO: Support this + } + + return false; + } + } +} diff --git a/src/Pretender.SourceGenerator/Parser/CreateParser.cs b/src/Pretender.SourceGenerator/Parser/CreateParser.cs index fb6c521..8db069a 100644 --- a/src/Pretender.SourceGenerator/Parser/CreateParser.cs +++ b/src/Pretender.SourceGenerator/Parser/CreateParser.cs @@ -2,7 +2,6 @@ using Microsoft.CodeAnalysis; using Pretender.SourceGenerator.Emitter; using Pretender.SourceGenerator.Invocation; -using static Pretender.SourceGenerator.PretenderSourceGenerator; namespace Pretender.SourceGenerator.Parser { @@ -11,26 +10,20 @@ internal class CreateParser private readonly CreateInvocation _createInvocation; private readonly ImmutableArray _locations; private readonly int _index; - private readonly bool _isLanguageVersionSupported; private readonly KnownTypeSymbols _knownTypeSymbols; - public CreateParser(CreateInvocation createInvocation, ImmutableArray locations, int index, CompilationData compilationData) + public CreateParser(CreateInvocation createInvocation, ImmutableArray locations, int index, KnownTypeSymbols knownTypeSymbols) { _createInvocation = createInvocation; _locations = locations; _index = index; - _isLanguageVersionSupported = compilationData.LanguageVersionIsSupported; - _knownTypeSymbols = compilationData.TypeSymbols!; + _knownTypeSymbols = knownTypeSymbols; } public (CreateEmitter? Emitter, ImmutableArray? Diagnostics) Parse(CancellationToken cancellationToken) { - if (!_isLanguageVersionSupported) - { - return (null, ImmutableArray.Create(Diagnostic.Create(DiagnosticDescriptors.UnsupportedLanguageVersion, null))); - } - - // TODO:Do deeper introspection to make sure the supplied args match with supplied type arguments + cancellationToken.ThrowIfCancellationRequested(); + // TODO: Do deeper introspection to make sure the supplied args match with supplied type arguments // and we should provide the constructor to use to the emitter maybe var emitter = new CreateEmitter( _createInvocation.Operation, diff --git a/src/Pretender.SourceGenerator/Parser/KnownTypeSymbols.cs b/src/Pretender.SourceGenerator/Parser/KnownTypeSymbols.cs index 9e8b7ff..e5e2a6a 100644 --- a/src/Pretender.SourceGenerator/Parser/KnownTypeSymbols.cs +++ b/src/Pretender.SourceGenerator/Parser/KnownTypeSymbols.cs @@ -5,7 +5,7 @@ namespace Pretender.SourceGenerator.Parser { internal sealed class KnownTypeSymbols { - public CSharpCompilation Compilation { get; } + public Compilation Compilation { get; } // INamedTypeSymbols public INamedTypeSymbol? Pretend { get; } @@ -17,9 +17,16 @@ internal sealed class KnownTypeSymbols public INamedTypeSymbol? ValueTask { get; } public INamedTypeSymbol? ValueTaskOfT_Unbound { get; } + // Known abstractions with fakes + public INamedTypeSymbol? MicrosoftExtensionsLoggingILogger { get; } + public INamedTypeSymbol? MicrosoftExtensionsLoggingTestingFakeLogger { get; } + public INamedTypeSymbol? MicrosoftExtensionsLoggingAbstractionsNullLogger { get; } + public INamedTypeSymbol? MicrosoftExtensionsLoggingILoggerOfT { get; } - public KnownTypeSymbols(CSharpCompilation compilation) + + + public KnownTypeSymbols(Compilation compilation) { Compilation = compilation; @@ -32,6 +39,22 @@ public KnownTypeSymbols(CSharpCompilation compilation) TaskOfT_Unbound = compilation.GetTypeByMetadataName("System.Threading.Tasks.Task`1")?.ConstructUnboundGenericType(); ValueTask = compilation.GetTypeByMetadataName("System.Threading.Tasks.ValueTask"); ValueTaskOfT_Unbound = compilation.GetTypeByMetadataName("System.Threading.Tasks.ValueTask`1")?.ConstructUnboundGenericType(); + + // Fakes + // ILogger + MicrosoftExtensionsLoggingILogger = compilation.GetTypeByMetadataName("Microsoft.Extensions.Logging.ILogger"); + MicrosoftExtensionsLoggingTestingFakeLogger = compilation.GetTypeByMetadataName("Microsoft.Extensions.Logging.Testing.FakeLogger"); + MicrosoftExtensionsLoggingAbstractionsNullLogger = compilation.GetTypeByMetadataName("Microsoft.Extensions.Logging.Abstractions.NullLogger"); + + // ILogger + MicrosoftExtensionsLoggingILoggerOfT = compilation.GetTypeByMetadataName("Microsoft.Extensions.Logging.ILogger`1"); + MicrosoftExtensionsLoggingTestingFakeLogger = compilation.GetTypeByMetadataName("Microsoft.Extensions.Logging.Testing.FakeLogger`1"); + MicrosoftExtensionsLoggingAbstractionsNullLogger = compilation.GetTypeByMetadataName("Microsoft.Extensions.Logging.Abstractions.NullLogger`1"); + + // ILoggerProvider + + // TODO: data protection + // TODO: FakeTimeProvider } public static bool IsPretend(INamedTypeSymbol type) diff --git a/src/Pretender.SourceGenerator/Parser/PretendParser.cs b/src/Pretender.SourceGenerator/Parser/PretendParser.cs index 672cfc1..b1ec1f8 100644 --- a/src/Pretender.SourceGenerator/Parser/PretendParser.cs +++ b/src/Pretender.SourceGenerator/Parser/PretendParser.cs @@ -1,24 +1,35 @@ using System.Collections.Immutable; using Microsoft.CodeAnalysis; +using Pretender.Settings; using Pretender.SourceGenerator.Emitter; +using Pretender.SourceGenerator.Fakes; using Pretender.SourceGenerator.Invocation; -using static Pretender.SourceGenerator.PretenderSourceGenerator; namespace Pretender.SourceGenerator.Parser { internal class PretendParser { + private static readonly List _knownFakes = + [ + new ILoggerFake(), + ]; - public PretendParser(PretendInvocation pretendInvocation, CompilationData compilationData) + private readonly KnownTypeSymbols _knownTypeSymbols; + private readonly PretenderSettings _settings; + + public PretendParser(PretendInvocation pretendInvocation, KnownTypeSymbols knownTypeSymbols, PretenderSettings settings) { PretendInvocation = pretendInvocation; + _knownTypeSymbols = knownTypeSymbols; + _settings = settings; } public PretendInvocation PretendInvocation { get; } public (PretendEmitter? Emitter, ImmutableArray? Diagnostics) Parse(CancellationToken cancellationToken) { - if (PretendInvocation.PretendType.IsSealed) + var pretendType = PretendInvocation.PretendType; + if (pretendType.IsSealed) { var sealedError = Diagnostic.Create( DiagnosticDescriptors.UnableToPretendSealedType, @@ -30,7 +41,17 @@ public PretendParser(PretendInvocation pretendInvocation, CompilationData compil // TODO: Do more error diagnostics - // TODO: Warn about well known good fakes + if (_settings.Behavior == PretendBehavior.PreferFakes) + { + foreach (var fake in _knownFakes) + { + cancellationToken.ThrowIfCancellationRequested(); + if (fake.TryConstruct((INamedTypeSymbol)pretendType, _knownTypeSymbols, cancellationToken, out var fakeType)) + { + // TODO: Do something + } + } + } // TODO: Do a larger amount of parsing diff --git a/src/Pretender.SourceGenerator/Parser/SetupParser.cs b/src/Pretender.SourceGenerator/Parser/SetupParser.cs index a5aed1c..632839c 100644 --- a/src/Pretender.SourceGenerator/Parser/SetupParser.cs +++ b/src/Pretender.SourceGenerator/Parser/SetupParser.cs @@ -2,30 +2,22 @@ using Microsoft.CodeAnalysis; using Pretender.SourceGenerator.Emitter; using Pretender.SourceGenerator.Invocation; -using static Pretender.SourceGenerator.PretenderSourceGenerator; namespace Pretender.SourceGenerator.Parser { internal class SetupParser { private readonly SetupInvocation _setupInvocation; - private readonly bool _isLanguageVersionSupported; private readonly KnownTypeSymbols _knownTypeSymbols; - public SetupParser(SetupInvocation setupInvocation, CompilationData compilationData) + public SetupParser(SetupInvocation setupInvocation, KnownTypeSymbols knownTypeSymbols) { _setupInvocation = setupInvocation; - _isLanguageVersionSupported = compilationData.LanguageVersionIsSupported; - _knownTypeSymbols = compilationData.TypeSymbols!; + _knownTypeSymbols = knownTypeSymbols; } public (SetupEmitter? Emitter, ImmutableArray? Diagnostics) Parse(CancellationToken cancellationToken) { - if (!_isLanguageVersionSupported) - { - return (null, ImmutableArray.Create(Diagnostic.Create(DiagnosticDescriptors.UnsupportedLanguageVersion, null))); - } - var operation = _setupInvocation.Operation; // Setup calls are expected to have a single argument, being the setup action argument diff --git a/src/Pretender.SourceGenerator/Parser/VerifyParser.cs b/src/Pretender.SourceGenerator/Parser/VerifyParser.cs index 3460bd1..dd18348 100644 --- a/src/Pretender.SourceGenerator/Parser/VerifyParser.cs +++ b/src/Pretender.SourceGenerator/Parser/VerifyParser.cs @@ -2,30 +2,22 @@ using Microsoft.CodeAnalysis; using Pretender.SourceGenerator.Emitter; using Pretender.SourceGenerator.Invocation; -using static Pretender.SourceGenerator.PretenderSourceGenerator; namespace Pretender.SourceGenerator.Parser { internal class VerifyParser { - private readonly bool _isLanguageVersionSupported; - private readonly KnownTypeSymbols _knownTypeSymbols; private readonly VerifyInvocation _verifyInvocation; + private readonly KnownTypeSymbols _knownTypeSymbols; - public VerifyParser(VerifyInvocation verifyInvocation, CompilationData compilationData) + public VerifyParser(VerifyInvocation verifyInvocation, KnownTypeSymbols knownTypeSymbols) { - _isLanguageVersionSupported = compilationData.LanguageVersionIsSupported; - _knownTypeSymbols = compilationData.TypeSymbols!; _verifyInvocation = verifyInvocation; + _knownTypeSymbols = knownTypeSymbols; } public (VerifyEmitter? VerifyEmitter, ImmutableArray? Diagnostics) Parse(CancellationToken cancellationToken) { - if (!_isLanguageVersionSupported) - { - return (null, ImmutableArray.Create(Diagnostic.Create(DiagnosticDescriptors.UnsupportedLanguageVersion, null))); - } - cancellationToken.ThrowIfCancellationRequested(); var operation = _verifyInvocation.Operation; diff --git a/src/Pretender.SourceGenerator/Pretender.SourceGenerator.csproj b/src/Pretender.SourceGenerator/Pretender.SourceGenerator.csproj index 1ca4e66..f0dec8b 100644 --- a/src/Pretender.SourceGenerator/Pretender.SourceGenerator.csproj +++ b/src/Pretender.SourceGenerator/Pretender.SourceGenerator.csproj @@ -17,4 +17,8 @@ + + + + diff --git a/src/Pretender.SourceGenerator/PretenderSettings.cs b/src/Pretender.SourceGenerator/PretenderSettings.cs new file mode 100644 index 0000000..e02acdb --- /dev/null +++ b/src/Pretender.SourceGenerator/PretenderSettings.cs @@ -0,0 +1,40 @@ +using Microsoft.CodeAnalysis; +using Pretender.Settings; + +namespace Pretender.SourceGenerator +{ + internal class PretenderSettings + { + public static PretenderSettings Default { get; } = new PretenderSettings( + PretendBehavior.PreferFakes + ); + + public static PretenderSettings FromAttribute(AttributeData attributeData) + { + PretendBehavior? behavior = null; + + foreach (var namedArg in attributeData.NamedArguments) + { + switch (namedArg.Key) + { + case nameof(Behavior): + behavior = (PretendBehavior)namedArg.Value.Value!; + break; + default: + throw new InvalidOperationException(); + } + } + + return new PretenderSettings( + behavior.GetValueOrDefault(PretendBehavior.PreferFakes) + ); + } + + public PretenderSettings(PretendBehavior behavior) + { + Behavior = behavior; + } + + public PretendBehavior Behavior { get; } + } +} diff --git a/src/Pretender.SourceGenerator/PretenderSourceGenerator.cs b/src/Pretender.SourceGenerator/PretenderSourceGenerator.cs index c326e43..e60adab 100644 --- a/src/Pretender.SourceGenerator/PretenderSourceGenerator.cs +++ b/src/Pretender.SourceGenerator/PretenderSourceGenerator.cs @@ -15,48 +15,53 @@ public class PretenderSourceGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { // TODO: Refactor our region use - // TODO: Create compilation data - IncrementalValueProvider compilationData = + IncrementalValueProvider knownTypeSymbols = context.CompilationProvider - .Select((compilation, _) => compilation.Options is CSharpCompilationOptions - ? new CompilationData((CSharpCompilation)compilation) - : null); + .Select((compilation, _) => new KnownTypeSymbols(compilation)); + + // TODO: Read settings off of + IncrementalValueProvider settings = context.SyntaxProvider.ForAttributeWithMetadataName( + "Pretender.PretenderSettingsAttribute", + predicate: static (node, _) => true, + transform: static (context, _) => context.Attributes[0]) + .Collect() + .Select(static (settings, _) => + { + if (settings.IsEmpty) + { + return PretenderSettings.Default; + } + + if (settings.Length > 1) + { + throw new InvalidOperationException("Only one instance of PretenderSettingsAttribute is expected on the assembly."); + } + + return PretenderSettings.FromAttribute(settings[0]); + }); #region Pretend - IncrementalValuesProvider<(PretendEmitter? Emitter, ImmutableArray? Diagnostics)> pretends = + IncrementalValuesProvider<(PretendEmitter? Emitter, ImmutableArray? Diagnostics)> pretendsWithDiagnostics = context.SyntaxProvider.CreateSyntaxProvider( predicate: (node, _) => PretendInvocation.IsCandidateSyntaxNode(node), transform: PretendInvocation.Create) .Where(static p => p != null) - .Combine(compilationData) + .Combine(knownTypeSymbols) + .Combine(settings) .Select(static (tuple, cancellationToken) => { - if (tuple.Right is not CompilationData compilationData) - { - return (null, null); - } - - // TODO: Create Parser - var parser = new PretendParser(tuple.Left!, compilationData); + var ((invocation, knownTypeSymbols), settings) = tuple; + var parser = new PretendParser(invocation!, knownTypeSymbols, settings); return parser.Parse(cancellationToken); }) .WithTrackingName("Pretend"); - context.RegisterSourceOutput(pretends, static (context, pretend) => - { - if (pretend.Diagnostics is ImmutableArray diagnostics) - { - foreach (var diagnostic in diagnostics) - { - context.ReportDiagnostic(diagnostic); - } - } + var pretends = ReportDiagnostics(context, pretendsWithDiagnostics); - if (pretend.Emitter is PretendEmitter emitter) - { - var compilationUnit = emitter.Emit(context.CancellationToken); - context.AddSource($"Pretender.Type.{emitter.PretendType.ToPretendName()}.g.cs", compilationUnit.GetText(Encoding.UTF8)); - } + context.RegisterSourceOutput(pretends, static (context, emitter) => + { + var compilationUnit = emitter.Emit(context.CancellationToken); + context.AddSource($"Pretender.Type.{emitter.PretendType.ToPretendName()}.g.cs", compilationUnit.GetText(Encoding.UTF8)); }); #endregion @@ -66,15 +71,10 @@ public void Initialize(IncrementalGeneratorInitializationContext context) predicate: static (node, _) => SetupInvocation.IsCandidateSyntaxNode(node), transform: SetupInvocation.Create) .Where(i => i is not null) - .Combine(compilationData) + .Combine(knownTypeSymbols) .Select(static (tuple, token) => { - if (tuple.Right is not CompilationData compilationData) - { - return (null, null); - } - - var parser = new SetupParser(tuple.Left!, compilationData); + var parser = new SetupParser(tuple.Left!, tuple.Right); return parser.Parse(token); }) @@ -134,41 +134,27 @@ public void Initialize(IncrementalGeneratorInitializationContext context) predicate: (node, _) => VerifyInvocation.IsCandidateSyntaxNode(node), transform: VerifyInvocation.Create) .Where(vi => vi is not null) - .Combine(compilationData) + .Combine(knownTypeSymbols) .Select((tuple, cancellationToken) => { - if (tuple.Right is not CompilationData compilationData) - { - return (null, null); - } - // Create new VerifySpec - var parser = new VerifyParser(tuple.Left!, compilationData); + var parser = new VerifyParser(tuple.Left!, tuple.Right); return parser.Parse(cancellationToken); }) .WithTrackingName("Verify"); - context.RegisterSourceOutput(verifyCallsWithDiagnostics.Collect(), (context, inputs) => + var verifyEmitters = ReportDiagnostics(context, verifyCallsWithDiagnostics); + + context.RegisterSourceOutput(verifyEmitters.Collect(), (context, inputs) => { var methods = new List(); for (var i = 0; i < inputs.Length; i++) { var input = inputs[i]; - if (input.Diagnostics is ImmutableArray diagnostics) - { - foreach (var diagnostic in diagnostics) - { - context.ReportDiagnostic(diagnostic); - } - } - if (input.Emitter is VerifyEmitter emitter) - { - // TODO: Emit VerifyMethod - var method = emitter.Emit(0, context.CancellationToken); - methods.Add(method); - } + var method = input.Emit(0, context.CancellationToken); + methods.Add(method); } if (methods.Count > 0) @@ -186,38 +172,25 @@ public void Initialize(IncrementalGeneratorInitializationContext context) transform: CreateInvocation.Create) .Where(i => i is not null)! .GroupWith(c => c.Location, CreateInvocationComparer.Instance) - .Combine(compilationData) + .Combine(knownTypeSymbols) .Select((tuple, token) => { - if (tuple.Right is not CompilationData compilationData) - { - return (null, null); - } - - var parser = new CreateParser(tuple.Left.Source, tuple.Left.Elements, tuple.Left.Index, compilationData); + var parser = new CreateParser(tuple.Left.Source, tuple.Left.Elements, tuple.Left.Index, tuple.Right); return parser.Parse(token); }) .WithTrackingName("Create"); - context.RegisterSourceOutput(createCalls, static (context, createCalls) => - { - if (createCalls.Diagnostics is ImmutableArray diagnostics) - { - foreach (var diagnostic in diagnostics) - { - context.ReportDiagnostic(diagnostic); - } - } + var createEmitters = ReportDiagnostics(context, createCalls); + context.RegisterSourceOutput(createEmitters, static (context, emitter) => + { // TODO: Don't actually need a list here var members = new List(); string? pretendName = null; - if (createCalls.Emitter is CreateEmitter emitter) - { - pretendName ??= emitter.Operation.TargetMethod.ReturnType.ToPretendName(); - members.Add(emitter.Emit(context.CancellationToken)); - } + + pretendName ??= emitter.Operation.TargetMethod.ReturnType.ToPretendName(); + members.Add(emitter.Emit(context.CancellationToken)); if (members.Any()) { @@ -239,23 +212,23 @@ public void Initialize(IncrementalGeneratorInitializationContext context) #endregion } - internal sealed class CompilationData + private static IncrementalValuesProvider ReportDiagnostics(IncrementalGeneratorInitializationContext context, IncrementalValuesProvider<(T? Emitter, ImmutableArray? Diagnostics)> source) { - public bool LanguageVersionIsSupported { get; } - public KnownTypeSymbols? TypeSymbols { get; } + var diagnostics = source + .Select((v, _) => v.Diagnostics) + .Where(d => d.HasValue && d.Value.Length > 0); - public CompilationData(CSharpCompilation compilation) + context.RegisterSourceOutput(diagnostics, (context, diagnostics) => { - // We don't have a CSharp12 value available yet. Polyfill the value here for forward compat, rather than use the LanguageVersion.Preview enum value. - // https://github.com/dotnet/roslyn/blob/168689931cb4e3150641ec2fb188a64ce4b3b790/src/Compilers/CSharp/Portable/LanguageVersion.cs#L218-L232 - const int LangVersion_CSharp12 = 1200; - LanguageVersionIsSupported = (int)compilation.LanguageVersion >= LangVersion_CSharp12; - - if (LanguageVersionIsSupported) + foreach (var diagnostic in diagnostics!.Value) { - TypeSymbols = new KnownTypeSymbols(compilation); + context.ReportDiagnostic(diagnostic); } - } + }); + + return source + .Select((v, _) => v.Emitter) + .Where(e => e != null)!; } } } diff --git a/src/Pretender/Matchers/MatcherListener.cs b/src/Pretender/Matchers/MatcherListener.cs index 103fde1..df18184 100644 --- a/src/Pretender/Matchers/MatcherListener.cs +++ b/src/Pretender/Matchers/MatcherListener.cs @@ -36,7 +36,7 @@ public static bool IsListening([MaybeNullWhen(false)] out MatcherListener listen return false; } - private List _matchers; + private List? _matchers; public void OnMatch(IMatcher matcher) { diff --git a/src/Pretender/PretendName.cs b/src/Pretender/PretendAttribute.cs similarity index 100% rename from src/Pretender/PretendName.cs rename to src/Pretender/PretendAttribute.cs diff --git a/src/Pretender/PretenderSettingsAttribute.cs b/src/Pretender/PretenderSettingsAttribute.cs new file mode 100644 index 0000000..7c1cd07 --- /dev/null +++ b/src/Pretender/PretenderSettingsAttribute.cs @@ -0,0 +1,11 @@ +using Pretender.Settings; + +namespace Pretender +{ + + [AttributeUsage(AttributeTargets.Assembly)] + public class PretenderSettingsAttribute : Attribute + { + public PretendBehavior Behavior { get; set; } + } +} diff --git a/src/Pretender/Settings/PretendBehavior.cs b/src/Pretender/Settings/PretendBehavior.cs new file mode 100644 index 0000000..3884da0 --- /dev/null +++ b/src/Pretender/Settings/PretendBehavior.cs @@ -0,0 +1,8 @@ +namespace Pretender.Settings +{ + public enum PretendBehavior + { + PreferFakes, + AlwaysPretend, + } +} diff --git a/test/SourceGeneratorTests/MainTests.cs b/test/SourceGeneratorTests/MainTests.cs index db1404d..06ad198 100644 --- a/test/SourceGeneratorTests/MainTests.cs +++ b/test/SourceGeneratorTests/MainTests.cs @@ -19,11 +19,13 @@ await RunAndComparePartialAsync($$""" [Fact] public async Task TaskOfTMethod() { - var (result, _) = await RunGeneratorAsync($$""" - #nullable disable + var (result, c) = await RunGeneratorAsync($$""" using System; using System.Threading.Tasks; using Pretender; + using Pretender.Settings; + + [assembly: PretenderSettings(Behavior = PretendBehavior.AlwaysPretend)] namespace TaskOfTMethodNamespace;