Пример #1
0
        public async Task GeneratesEnableModuleAttributesForAllModules()
        {
            StringBuilder builder = new();

            foreach (DurianModule module in ModuleIdentity.GetAllModules().AsEnums())
            {
                builder
                .Append("[assembly: Durian.Generator.EnableModule(Durian.Info.")
                .Append(nameof(DurianModule))
                .Append('.')
                .Append(module.ToString())
                .AppendLine(")]");
            }

            CSharpSyntaxTree expected = (CSharpSyntaxTree)CSharpSyntaxTree.ParseText(builder.ToString());

            CSharpCompilation      compilation = RoslynUtilities.CreateBaseCompilation();
            DisabledModuleAnalyzer analyzer    = new();
            await analyzer.RunAnalyzer(compilation);

            SingletonGeneratorTestResult result = GeneratorTest.RunGenerator("", analyzer);

            Assert.True(result.IsGenerated);
            Assert.NotNull(result.SyntaxTree);
            Assert.True(result.SyntaxTree !.IsEquivalentTo(expected));
        }
Пример #2
0
        public async Task Succcess_When_ReferencesDurianCore()
        {
            CSharpCompilation           compilation = RoslynUtilities.CreateBaseCompilation();
            DependencyAnalyzer          analyzer    = new();
            ImmutableArray <Diagnostic> diagnostics = await analyzer.RunAnalyzer(compilation);

            Assert.Empty(diagnostics);
        }
Пример #3
0
        public async Task ModulesAreEnabledByDefault()
        {
            CSharpCompilation      compilation = RoslynUtilities.CreateBaseCompilation();
            DisabledModuleAnalyzer analyzer    = new();
            await analyzer.RunAnalyzer(compilation);

            Assert.True(ModuleIdentity.GetAllModules().AsEnums().All(module => DisabledModuleAnalyzer.IsEnabled(module)));
        }
Пример #4
0
        public async Task DisablesModule_When_HasDisableModuleAttribute()
        {
            string            input       = "[assembly: Durian.DisableModule(Durian.Info.DurianModule.DefaultParam)]";
            CSharpCompilation compilation = RoslynUtilities.CreateBaseCompilation();

            compilation = compilation.AddSyntaxTrees(CSharpSyntaxTree.ParseText(input));
            DisabledModuleAnalyzer analyzer = new();
            await analyzer.RunAnalyzer(compilation);

            Assert.False(DisabledModuleAnalyzer.IsEnabled(DurianModule.DefaultParam));
        }
Пример #5
0
        public async Task Success_When_ReferencesMainPackage()
        {
            CSharpCompilation compilation = RoslynUtilities.CreateBaseCompilation();
            string            dir         = Path.GetDirectoryName(typeof(DependencyTests).Assembly.Location) !;
            string            mainPath    = Path.Combine(dir, "Durian.dll");

            compilation = compilation.AddReferences(MetadataReference.CreateFromFile(mainPath));

            DependencyAnalyzer          analyzer    = new();
            ImmutableArray <Diagnostic> diagnostics = await analyzer.RunAnalyzer(compilation);

            Assert.Empty(diagnostics);
        }
Пример #6
0
        public async Task Error_When_ReferencesMainDurianPackageAndAnyDurianAnalyzerPackage()
        {
            CSharpCompilation compilation  = RoslynUtilities.CreateBaseCompilation();
            string            dir          = Path.GetDirectoryName(typeof(DependencyTests).Assembly.Location) !;
            string            mainPath     = Path.Combine(dir, "Durian.dll");
            string            analyzerPath = Path.Combine(dir, "Durian.Core.Analyzer.dll");

            compilation = compilation.AddReferences(MetadataReference.CreateFromFile(mainPath), MetadataReference.CreateFromFile(analyzerPath));

            DependencyAnalyzer analyzer = new();

            Assert.True(await analyzer.ProducesDiagnostic(compilation, DurianDiagnostics.DUR0007_DoNotReferencePackageIfManagerIsPresent));
        }
Пример #7
0
        public async Task Warning_When_HasMultipleAnalyzerPackages_And_NoManager()
        {
            CSharpCompilation compilation = RoslynUtilities.CreateBaseCompilation();
            string            dir         = Path.GetDirectoryName(typeof(DependencyTests).Assembly.Location) !;

            compilation = compilation.AddReferences(
                MetadataReference.CreateFromFile(Path.Combine(dir, "Durian.Core.Analyzer.dll")),
                MetadataReference.CreateFromFile(Path.Combine(dir, "Durian.InterfaceTargets.dll"))
                );

            DependencyAnalyzer analyzer = new();

            Assert.True(await analyzer.ProducesDiagnostic(compilation, DurianDiagnostics.DUR0008_MultipleAnalyzers));
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CompilationFixture"/> class.
 /// </summary>
 public CompilationFixture()
 {
     Compilation = RoslynUtilities.CreateBaseCompilation();
 }
Пример #9
0
 public void HasErrorsReturnsFalseByDefault()
 {
     Data.CompilationData data = new(RoslynUtilities.CreateBaseCompilation());
     Assert.False(data.HasErrors);
 }
Пример #10
0
 public void CompilationIsNotNullAfterConstructor()
 {
     Data.CompilationData data = new(RoslynUtilities.CreateBaseCompilation());
     Assert.True(data.Compilation is not null);
 }