Skip to content

Commit

Permalink
Merge pull request #3921 from unoplatform/dev/jela/wasm-analyzer
Browse files Browse the repository at this point in the history
fix(analyzers): Analyzers may not show the proper status using the reference API
  • Loading branch information
jeromelaban authored Sep 1, 2020
2 parents 79a3444 + c58565e commit bbe26b3
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 17 deletions.
306 changes: 297 additions & 9 deletions src/Uno.Analyzers.Tests/UnoNotImplementedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ namespace Uno.Analyzers.Tests
[TestClass]
public class UnoNotImplementedTests : DiagnosticVerifier
{
private static string UnoNotImplementedAtribute = @"
namespace Uno
{
[System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)]
public sealed class NotImplementedAttribute : Attribute
{
public NotImplementedAttribute() { }
public NotImplementedAttribute(params string[] platforms)
{
Platforms = platforms;
}
public string[]? Platforms { get; }
}
}";

protected override DiagnosticAnalyzer DiagnosticAnalyzer => new UnoNotImplementedAnalyzer();

public UnoNotImplementedTests() : base(LanguageNames.CSharp)
Expand All @@ -25,7 +42,7 @@ public void Nothing()
}

[TestMethod]
public void When_LambdaIsAsyncVoid()
public void When_EmptyNotImplemented()
{
var test = @"
using System;
Expand All @@ -37,12 +54,6 @@ public void When_LambdaIsAsyncVoid()
namespace Uno
{
[System.AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)]
public sealed class NotImplementedAttribute : Attribute
{
}
[NotImplemented]
public class TestClass { }
}
Expand All @@ -56,19 +67,296 @@ public TypeName()
var a = new Uno.TestClass();
}
}
}";
}
" + UnoNotImplementedAtribute;

var expected = new DiagnosticResult
{
Id = UnoNotImplementedAnalyzer.Rule.Id,
Severity = DiagnosticSeverity.Warning,
Message = string.Format(UnoNotImplementedAnalyzer.MessageFormat, "Uno.TestClass"),
Locations = new[] {
new DiagnosticResultLocation("Test0.cs", 21, 36)
}
};

VerifyDiagnostic(test, expected);
}

[TestMethod]
public void When_SinglePlatform_Included()
{
var test = @"
#define __WASM__
using System;
namespace Uno
{
[NotImplemented(""__WASM__"")]
public class TestClass { }
}
namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass();
}
}
}
" + UnoNotImplementedAtribute;

var expected = new DiagnosticResult
{
Id = UnoNotImplementedAnalyzer.Rule.Id,
Severity = DiagnosticSeverity.Warning,
Message = string.Format(UnoNotImplementedAnalyzer.MessageFormat, "Uno.TestClass"),
Locations = new[] {
new DiagnosticResultLocation("Test0.cs", 27, 36)
new DiagnosticResultLocation("Test0.cs", 18, 36)
}
};

VerifyDiagnostic(test, expected);
}

[TestMethod]
public void When_SinglePlatform_Excluded()
{
var test = @"
#define __WASM__
using System;
namespace Uno
{
[NotImplemented(""__SKIA__"")]
public class TestClass { }
}
namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass();
}
}
}
" + UnoNotImplementedAtribute;

VerifyDiagnostic(test);
}

[TestMethod]
public void When_TwoPlatforms_Excluded()
{
var test = @"
#define __WASM__
using System;
namespace Uno
{
[NotImplemented(""__SKIA__"", ""__IOS__"")]
public class TestClass { }
}
namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass();
}
}
}
" + UnoNotImplementedAtribute;

VerifyDiagnostic(test);
}

[TestMethod]
public void When_Generic_Excluded()
{
var test = @"
#define UNO_REFERENCE_API
using System;
namespace Uno
{
[NotImplemented(""__IOS__"")]
public class TestClass { }
}
namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass();
}
}
}
" + UnoNotImplementedAtribute;

VerifyDiagnostic(test);
}

[TestMethod]
public void When_Generic_Partial_Excluded()
{
var test = @"
#define UNO_REFERENCE_API
using System;
namespace Uno
{
[NotImplemented(""__SKIA__"", ""__IOS__"")]
public class TestClass { }
}
namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass();
}
}
}
" + UnoNotImplementedAtribute;

VerifyDiagnostic(test);
}

[TestMethod]
public void When_Generic_Included()
{
var test = @"
#define UNO_REFERENCE_API
using System;
namespace Uno
{
[NotImplemented(""__SKIA__"", ""__IOS__"", ""__WASM__"")]
public class TestClass { }
}
namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass();
}
}
}
" + UnoNotImplementedAtribute;

var expected = new DiagnosticResult
{
Id = UnoNotImplementedAnalyzer.Rule.Id,
Severity = DiagnosticSeverity.Warning,
Message = string.Format(UnoNotImplementedAnalyzer.MessageFormat, "Uno.TestClass"),
Locations = new[] {
new DiagnosticResultLocation("Test0.cs", 18, 36)
}
};

VerifyDiagnostic(test, expected);
}


[TestMethod]
public void When_Generic_Member_Included()
{
var test = @"
#define UNO_REFERENCE_API
using System;
namespace Uno
{
public class TestClass {
[NotImplemented(""__SKIA__"", ""__IOS__"", ""__WASM__"")]
public int Test { get; }
}
}
namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass().Test;
}
}
}
" + UnoNotImplementedAtribute;

var expected = new DiagnosticResult
{
Id = UnoNotImplementedAnalyzer.Rule.Id,
Severity = DiagnosticSeverity.Warning,
Message = string.Format(UnoNotImplementedAnalyzer.MessageFormat, "Uno.TestClass.Test"),
Locations = new[] {
new DiagnosticResultLocation("Test0.cs", 20, 36)
}
};

VerifyDiagnostic(test, expected);
}

[TestMethod]
public void When_Generic_Member_Partial_Excluded()
{
var test = @"
#define UNO_REFERENCE_API
using System;
namespace Uno
{
public class TestClass {
[NotImplemented(""__IOS__"", ""__WASM__"")]
public int Test { get; }
}
}
namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass().Test;
}
}
}
" + UnoNotImplementedAtribute;

VerifyDiagnostic(test);
}
}
}
Loading

0 comments on commit bbe26b3

Please sign in to comment.