diff --git a/src/tests/Common/XUnitWrapperGenerator/Descriptors.cs b/src/tests/Common/XUnitWrapperGenerator/Descriptors.cs index 130180659693b7..f3a96b07fd483b 100644 --- a/src/tests/Common/XUnitWrapperGenerator/Descriptors.cs +++ b/src/tests/Common/XUnitWrapperGenerator/Descriptors.cs @@ -27,4 +27,22 @@ public static class Descriptors "XUnitWrapperGenerator", DiagnosticSeverity.Warning, isEnabledByDefault: true); + + public static readonly DiagnosticDescriptor XUWG1003 = + new DiagnosticDescriptor( + "XUW1003", + "Test methods must be public", + "Test methods must be public. Add or change the visibility modifier of the test method to public.", + "XUnitWrapperGenerator", + DiagnosticSeverity.Error, + isEnabledByDefault: true); + + public static readonly DiagnosticDescriptor XUWG1004 = + new DiagnosticDescriptor( + "XUW1004", + "Test classes must be public", + "Test classes must be public. Add or change the visibility modifier of the test class to public.", + "XUnitWrapperGenerator", + DiagnosticSeverity.Error, + isEnabledByDefault: true); } diff --git a/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs b/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs index cb85e588e2b230..3c4828cc676b50 100644 --- a/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs +++ b/src/tests/Common/XUnitWrapperGenerator/XUnitWrapperGenerator.cs @@ -165,6 +165,49 @@ public void Initialize(IncrementalGeneratorInitializationContext context) context.ReportDiagnostic(Diagnostic.Create(Descriptors.XUWG1002, method.Locations[0])); }); + context.RegisterImplementationSourceOutput( + methodsInSource + .Combine(context.AnalyzerConfigOptionsProvider) + .Where(data => + { + var (_, configOptions) = data; + return configOptions.GlobalOptions.InMergedTestDirectory(); + }), + static (context, data) => + { + var (method, _) = data; + + bool found = false; + foreach (var attr in method.GetAttributesOnSelfAndContainingSymbols()) + { + switch (attr.AttributeClass?.ToDisplayString()) + { + case "Xunit.ConditionalFactAttribute": + case "Xunit.FactAttribute": + case "Xunit.ConditionalTheoryAttribute": + case "Xunit.TheoryAttribute": + found = true; + break; + } + } + if (!found) return; + + if (method.DeclaredAccessibility != Accessibility.Public) + { + context.ReportDiagnostic(Diagnostic.Create(Descriptors.XUWG1003, method.Locations[0])); + } + + INamedTypeSymbol containingType = method.ContainingType; + while (containingType != null) + { + if (containingType.DeclaredAccessibility != Accessibility.Public) + { + context.ReportDiagnostic(Diagnostic.Create(Descriptors.XUWG1004, method.Locations[0])); + } + containingType = containingType.ContainingType; + } + }); + context.RegisterImplementationSourceOutput( allTests .Combine(context.AnalyzerConfigOptionsProvider) diff --git a/src/tests/JIT/Regression/JitBlue/GitHub_11408/GitHub_11408.cs b/src/tests/JIT/Regression/JitBlue/GitHub_11408/GitHub_11408.cs index 30a71b8e584763..8f5198e505760b 100644 --- a/src/tests/JIT/Regression/JitBlue/GitHub_11408/GitHub_11408.cs +++ b/src/tests/JIT/Regression/JitBlue/GitHub_11408/GitHub_11408.cs @@ -5,7 +5,7 @@ using System.Runtime.CompilerServices; using Xunit; -class GitHub_11408 +public class GitHub_11408 { const int Pass = 100; const int Fail = -1; diff --git a/src/tests/JIT/jit64/regress/vsw/528315/simple-repro.cs b/src/tests/JIT/jit64/regress/vsw/528315/simple-repro.cs index 7b45c5ebf647a2..307ba121d7d37b 100644 --- a/src/tests/JIT/jit64/regress/vsw/528315/simple-repro.cs +++ b/src/tests/JIT/jit64/regress/vsw/528315/simple-repro.cs @@ -2,12 +2,12 @@ // The .NET Foundation licenses this file to you under the MIT license. using Xunit; -internal enum NodeType +public enum NodeType { True, False, Not, Other } -internal class Node +public class Node { public NodeType NodeType; public Node Child; @@ -15,7 +15,7 @@ internal class Node public Node(string s) { name = s; } } -internal class NodeFactory +public class NodeFactory { public Node Conditional(Node condition, Node trueBranch, Node falseBranch) {