public async Task VerifyNoDiagnosticConditionalDebugLogException() { const string test = @" using UnityEngine; using System; namespace BestPracticeChecker.Test { class Something { Exception b = new Exception(); void DoSomething() { Debug.LogException(b); } } }"; var expected = new DiagnosticResult("BP0002", DiagnosticSeverity.Warning) .WithLocation(13, 13) .WithMessage(DiagnosticStrings.GetString("ConditionalDebugMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task GetComponentInMethodInUpdate() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something : MonoBehaviour { void Update() { DoSomething(); } void DoSomething() { var hinges = gameObject.GetComponents(typeof(HingeJoint)) as HingeJoint[]; } } }"; var expected = new DiagnosticResult("BP0001", DiagnosticSeverity.Warning) .WithLocation(15, 17) .WithMessage(DiagnosticStrings.GetString("IllegalMethodInUpdateMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task GameObjectFindHighlightedInAwake() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something : MonoBehaviour { public GameObject prefab; public GameObject prefab2; Something() { prefab = new GameObject(); prefab2 = new GameObject(""Prefab2""); } void Awake() { prefab = GameObject.Find(""Prefab2""); } } }"; var expected = new DiagnosticResult("BP0022", DiagnosticSeverity.Warning) .WithLocation(19, 22) .WithMessage(DiagnosticStrings.GetString("ObjectFindAndTypeMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public Task AccessViaClassMethodInUpdateShouldReport() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something : MonoBehaviour { Camera m_MainCamera; void Update() { m_MainCamera = Something2.GetCamera(); } } static class Something2 { public static Camera GetCamera() { return Camera.main; } } }"; var expected = new DiagnosticResult("BP0023", DiagnosticSeverity.Warning) .WithLocation(19, 11) .WithMessage(DiagnosticStrings.GetString("CameraMainInUpdateMessageFormat").ToString()); return(VerifyCSharpDiagnosticAsync(test, expected)); }
public async Task StringEqualsOperationHighlighted() { const string test = @" namespace BestPracticeChecker.Test { class Something { void DoSomething(string a, string b) { if(a == b) return; } } }"; var expected = new DiagnosticResult("BP0006", DiagnosticSeverity.Warning) .WithLocation(8, 15) .WithMessage(DiagnosticStrings.GetString("CompareStringWithOrdinalMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task StringStartsWithHighlighted() { const string test = @" using System; namespace BestPracticeChecker.Test { class Something { void DoSomething(string a) { String b = ""c""; b.StartsWith(a); } } }"; var expected = new DiagnosticResult("BP0007", DiagnosticSeverity.Warning) .WithLocation(11, 13) .WithMessage(DiagnosticStrings.GetString("InefficientStringApiMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task AllocApiBoxcastHighlighted() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something { void DoSomeCast(Vector3 pos, Vector3 n, Vector3 dir) { Physics.BoxCast(pos, n, dir, Quaternion.LookRotation(dir)); } } }"; var expected = new DiagnosticResult("BP0020", DiagnosticSeverity.Warning) .WithLocation(10, 13) .WithMessage(DiagnosticStrings.GetString("NonAllocatingPhysicEngineMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task ArgumentTag() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something : MonoBehaviour { void Start(string a) { var respawn = GameObject.FindWithTag(a); } } }"; var expected = new DiagnosticResult("BP0004", DiagnosticSeverity.Warning) .WithLocation(10, 41) .WithMessage(DiagnosticStrings.GetString("ConstTagsMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task StringCompareHighlighted() { const string test = @" using System; namespace BestPracticeChecker.Test { class Something { void DoSomething(string a, string b) { int c = String.Compare(a,b); } } }"; var expected = new DiagnosticResult("BP0006", DiagnosticSeverity.Warning) .WithLocation(10, 20) .WithMessage(DiagnosticStrings.GetString("CompareStringWithOrdinalMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task VerifyNoDiagnosticConditionalDebugLogStruct() { var methods = new List <String>() { "Debug.Log(message);", "Debug.LogAssertion(message);", "Debug.LogError(message);", "Debug.LogWarning(message);", "Debug.LogAssertionFormat(message);", "Debug.LogErrorFormat(message);", "Debug.LogWarningFormat(message);" }; var tests = methods.Select(m => $@" using UnityEngine; namespace BestPracticeChecker.Test {{ struct Something {{ string message {{get; set;}} void DoSomething(string message) {{ this.message = message; {m} }} }} }}"); var expected = new DiagnosticResult("BP0002", DiagnosticSeverity.Warning) .WithLocation(13, 13) .WithMessage(DiagnosticStrings.GetString("ConditionalDebugMessageFormat").ToString()); foreach (var test in tests) { await VerifyCSharpDiagnosticAsync(test, expected); } }
public async Task AllocApiRaycastHighlighted() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something { void DoSomeCast(Vector3 point1,Vector3 point2,float r, int layerMask, QueryTriggerInteraction queryTriggerInteraction) { Physics.OverlapCapsule(point1, point2, r, layerMask, queryTriggerInteraction); } } }"; var expected = new DiagnosticResult("BP0020", DiagnosticSeverity.Warning) .WithLocation(11, 13) .WithMessage(DiagnosticStrings.GetString("NonAllocatingPhysicEngineMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task AllocApiCapsuleCastHighlighted() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something { void DoSomeCast(Vector3 point1,Vector3 point2,float r, Vector3 dir, float castDistance) { Physics.CapsuleCast(point1, point2, r, dir, castDistance); } } }"; var expected = new DiagnosticResult("BP0020", DiagnosticSeverity.Warning) .WithLocation(11, 13) .WithMessage(DiagnosticStrings.GetString("NonAllocatingPhysicEngineMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task AllocRaycast2DHighlighted() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something { void DoSomeCast(Vector2 origin, Vector2 direction,float distance, int layerMask, float minDepth, float maxDepth) { Physics2D.Raycast(origin, direction, distance, layerMask, minDepth, maxDepth); } } }"; var expected = new DiagnosticResult("BP0020", DiagnosticSeverity.Warning) .WithLocation(11, 13) .WithMessage(DiagnosticStrings.GetString("NonAllocatingPhysicEngineMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task AllocSphereCast() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something { void DoSomeCast(Vector3 origin,float r,Vector3 direction, out RaycastHit hitInfo,float maxDistance, int layerMask, QueryTriggerInteraction queryTriggerInteraction) { Physics.SphereCast(origin, r, direction,out hitInfo, maxDistance, layerMask, queryTriggerInteraction); } } }"; var expected = new DiagnosticResult("BP0020", DiagnosticSeverity.Warning) .WithLocation(11, 13) .WithMessage(DiagnosticStrings.GetString("NonAllocatingPhysicEngineMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task StringReferenceShouldReport() { const string test = @" using System; using UnityEngine; namespace BestPracticeChecker.Test { class Something : MonoBehaviour { void DoSomething(string a) { StartCoroutine(""DoSomething"", a); } } }"; var expected = new DiagnosticResult("BP0003", DiagnosticSeverity.Warning) .WithLocation(11, 13) .WithMessage(DiagnosticStrings.GetString("StringReferencesMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task ObjectFindObjectOfTypeHighlightedInStart() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something : MonoBehaviour { void Start() { Camera cam = (Camera)Object.FindObjectOfType(typeof(Camera)); } } }"; var expected = new DiagnosticResult("BP0022", DiagnosticSeverity.Warning) .WithLocation(11, 34) .WithMessage(DiagnosticStrings.GetString("ObjectFindAndTypeMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }
public async Task BigClassShouldReport() { const string test = @" using UnityEngine; namespace BestPracticeChecker.Test { class Something { void DoSomeCast(Vector2 origin, Vector2 size, float angle, Vector2 direction, RaycastHit2D[] results,float distance, int layerMask, float maxDepth, float minDepth) { Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); Physics2D.BoxCastNonAlloc(origin, size, angle, direction, results, distance, layerMask, maxDepth, minDepth); } } }"; var expected = new DiagnosticResult("BP0008", DiagnosticSeverity.Warning) .WithLocation(7, 5) .WithMessage(DiagnosticStrings.GetString("SmallClassesMessageFormat").ToString()); await VerifyCSharpDiagnosticAsync(test, expected); }