Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify base test class analyzer, allow to extend from ft base test class #4810

Merged
merged 1 commit into from
Feb 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public sealed class BaseTestClassAnalyzer : DiagnosticAnalyzer
private const string Category = "Test";
internal const string DiagnosticId = "MSML_ExtendBaseTestClass";

private const string Title = "Test classes should be derived from BaseTestClass";
private const string Format = "Test class '{0}' should extend BaseTestClass.";
private const string Title = "Test classes should be derived from BaseTestClass or FunctionalTestBaseClass";
private const string Format = "Test class '{0}' should extend BaseTestClass or FunctionalTestBaseClass.";
private const string Description =
"Test classes should be derived from BaseTestClass.";
"Test classes should be derived from BaseTestClass or FunctionalTestBaseClass.";

private static DiagnosticDescriptor Rule =
new DiagnosticDescriptor(DiagnosticId, Title, Format, Category,
Expand Down Expand Up @@ -51,13 +51,15 @@ private sealed class AnalyzerImpl
private readonly Compilation _compilation;
private readonly INamedTypeSymbol _factAttribute;
private readonly INamedTypeSymbol _baseTestClass;
private readonly INamedTypeSymbol _FTbaseTestClass;
private readonly ConcurrentDictionary<INamedTypeSymbol, bool> _knownTestAttributes = new ConcurrentDictionary<INamedTypeSymbol, bool>();

public AnalyzerImpl(Compilation compilation, INamedTypeSymbol factAttribute)
{
_compilation = compilation;
_factAttribute = factAttribute;
_baseTestClass = _compilation.GetTypeByMetadataName("Microsoft.ML.TestFramework.BaseTestClass");
_FTbaseTestClass = _compilation.GetTypeByMetadataName("Microsoft.ML.Functional.Tests.FunctionalTestBaseClass");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have two base test classes? I know you have investigated this before. Can you please help me understand why we can't have a single BaseTestClass and have FunctionalTestBaseClass derive from BaseTestClass? (From what I understand, the only difference for functional tests is that they only use public API)

Copy link
Contributor Author

@frank-dong-ms-zz frank-dong-ms-zz Feb 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please reference previous PR for this: #4346

Basically, we want FT to be able to dependent on public nuget package so we need to break FT from any direct or indirect project reference. TestFramework project itself has lots of project dependency and also been marked as BestFriend from some projects from source folder which allows TestFramework peoject to access some non public code. So, we extracted TestFrameworkCommon test project which only have public dependency. Previously FTs are inherited from BaseTestBaseline which has lots of BestFriend thing and can't be moved to TestFrameworkCommon project so after discuss we decide to write one base class for FT only with only public dependency.
So in short we have separate base class for FT because we don't want FT to take project dependency from our source code thus let FT able to run in NightlyBuild


In reply to: 376581212 [](ancestors = 376581212)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! That sounds good. In that case, please make sure the functionality between the two base classes are in sync. I recently added some code to extract the LogMessageKind attribute from the test and store it in the base class. I also changed the derived class to append to the logs correctly. Can you please make sure that the important parts from this PR are integrated into the the FunctionalTestBaseClass: #4710


In reply to: 376616140 [](ancestors = 376616140,376581212)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above mentioned work need not be part of this PR. I am approving this. Please use a different PR for that work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am approving this. You can do the above mentioned work in a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will open a separate PR if we need certain fix


In reply to: 376622761 [](ancestors = 376622761)

}

public void AnalyzeNamedType(SymbolAnalysisContext context)
Expand Down Expand Up @@ -87,12 +89,14 @@ public void AnalyzeNamedType(SymbolAnalysisContext context)

private bool ExtendsBaseTestClass(INamedTypeSymbol namedType)
{
if (_baseTestClass is null)
if (_baseTestClass is null &&
_FTbaseTestClass is null)
return false;

for (var current = namedType; current is object; current = current.BaseType)
{
if (Equals(current, _baseTestClass))
if (Equals(current, _baseTestClass) ||
Equals(current, _FTbaseTestClass))
return true;
}

Expand Down