コード例 #1
0
        public void IssueInMonoBehaviourUpdate()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetIssueInMonoBehaviourUpdate);
            var issue  = issues.First();

            Assert.True(issue.isPerfCriticalContext);
        }
コード例 #2
0
        public void LinqIssueIsReported()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAsset);

            Assert.AreEqual(1, issues.Count());

            var myIssue = issues.FirstOrDefault();

            Assert.NotNull(myIssue);
            Assert.NotNull(myIssue.descriptor);

            Assert.AreEqual(Rule.Severity.Default, myIssue.descriptor.severity);
            Assert.AreEqual(101049, myIssue.descriptor.id);
            Assert.True(myIssue.descriptor.type.Equals("System.Linq"));
            Assert.True(myIssue.descriptor.method.Equals("*"));

            Assert.True(myIssue.name.Equals("Enumerable.Count"));
            Assert.True(myIssue.filename.Equals(m_TempAsset.scriptName));
            Assert.True(myIssue.description.Equals("Enumerable.Count"));
            Assert.True(
                myIssue.GetCallingMethod().Equals(
                    "System.Int32 MyClass::Dummy(System.Collections.Generic.List`1<System.Int32>)"));
            Assert.AreEqual(9, myIssue.line);
            Assert.AreEqual(IssueCategory.Code, myIssue.category);
        }
コード例 #3
0
        public void IssueIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAsset);

            Assert.AreEqual(1, issues.Count());

            var myIssue = issues.FirstOrDefault();

            Assert.NotNull(myIssue);
            Assert.NotNull(myIssue.descriptor);

            Assert.AreEqual(Rule.Action.Default, myIssue.descriptor.action);
            Assert.AreEqual(101000, myIssue.descriptor.id);
            Assert.True(myIssue.descriptor.type.Equals("UnityEngine.Camera"));
            Assert.True(myIssue.descriptor.method.Equals("main"));

            Assert.True(myIssue.name.Equals("Camera.get_main"));
            Assert.True(myIssue.filename.Equals(m_TempAsset.scriptName));
            Assert.True(myIssue.description.Equals("UnityEngine.Camera.main"));
            Assert.True(myIssue.callingMethod.Equals("System.Void MyClass::Dummy()"));
            Assert.AreEqual(8, myIssue.line);
            Assert.AreEqual(IssueCategory.Code, myIssue.category);

            // check custom property
            Assert.AreEqual((int)CodeProperty.Num, myIssue.GetNumCustomProperties());
            Assert.True(myIssue.GetCustomProperty((int)CodeProperty.Assembly).Equals(AssemblyHelper.DefaultAssemblyName));
        }
コード例 #4
0
ファイル: RuleTests.cs プロジェクト: avram/ProjectAuditor
        public void ShouldNotReportMutedIssue()
        {
            var projectAuditor         = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectAuditorSettings = projectAuditor.config;
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAsset);

            Assert.AreEqual(1, issues.Count());

            var issue = issues.FirstOrDefault();

            projectAuditorSettings.ClearAllRules();

            var action = projectAuditorSettings.GetAction(issue.descriptor, issue.callingMethod);

            // expect default action specified in descriptor
            Assert.AreEqual(issue.descriptor.severity, action);

            // add rule with a filter.
            projectAuditorSettings.AddRule(new Rule
            {
                id       = issue.descriptor.id,
                severity = Rule.Severity.None,
                filter   = issue.callingMethod
            });

            action = projectAuditorSettings.GetAction(issue.descriptor, issue.callingMethod);

            // issue has been muted so it should not be reported
            Assert.AreEqual(Rule.Severity.None, action);
        }
コード例 #5
0
        public void BoxingFloatValueIsReported()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetBoxingFloat);

            Assert.AreEqual(1, issues.Count());

            var boxingFloat = issues.FirstOrDefault();

            // check issue
            Assert.NotNull(boxingFloat);
            Assert.True(boxingFloat.name.Equals("BoxingFloatTest.Dummy"));
            Assert.True(boxingFloat.filename.Equals(m_TempAssetBoxingFloat.scriptName));
            Assert.True(boxingFloat.description.Equals("Conversion from value type 'float' to ref type"));
            Assert.True(boxingFloat.callingMethod.Equals("System.Object BoxingFloatTest::Dummy()"));
            Assert.AreEqual(1, boxingFloat.line);
            Assert.AreEqual(IssueCategory.Code, boxingFloat.category);

            // check descriptor
            Assert.NotNull(boxingFloat.descriptor);
            Assert.AreEqual(Rule.Action.Default, boxingFloat.descriptor.action);
            Assert.AreEqual(102000, boxingFloat.descriptor.id);
            Assert.True(string.IsNullOrEmpty(boxingFloat.descriptor.type));
            Assert.True(string.IsNullOrEmpty(boxingFloat.descriptor.method));
            Assert.False(string.IsNullOrEmpty(boxingFloat.descriptor.description));
            Assert.True(boxingFloat.descriptor.description.Equals("Boxing Allocation"));
        }
コード例 #6
0
        public void BoxingIntValueIsReported()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceBoxingInt);

            Assert.AreEqual(1, issues.Count());

            var boxingInt = issues.FirstOrDefault();

            // check issue
            Assert.NotNull(boxingInt);
            Assert.True(boxingInt.name.Equals("BoxingIntTest.Start"));
            Assert.True(boxingInt.filename.Equals(m_ScriptResourceBoxingInt.scriptName));
            Assert.True(boxingInt.description.Equals("Conversion from value type 'Int32' to ref type"));
            Assert.True(boxingInt.callingMethod.Equals("System.Void BoxingIntTest::Start()"));
            Assert.AreEqual(1, boxingInt.line);
            Assert.AreEqual(IssueCategory.ApiCalls, boxingInt.category);

            // check descriptor
            Assert.NotNull(boxingInt.descriptor);
            Assert.AreEqual(Rule.Action.Default, boxingInt.descriptor.action);
            Assert.AreEqual(102000, boxingInt.descriptor.id);
            Assert.True(string.IsNullOrEmpty(boxingInt.descriptor.type));
            Assert.True(string.IsNullOrEmpty(boxingInt.descriptor.method));
            Assert.False(string.IsNullOrEmpty(boxingInt.descriptor.description));
            Assert.True(boxingInt.descriptor.description.Equals("Boxing Allocation"));
        }
コード例 #7
0
        public void IssueInSimpleClass()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetIssueInSimpleClass);
            var issue  = issues.First();

            Assert.False(issue.isPerfCriticalContext);
        }
コード例 #8
0
        public void IssueInMonoBehaviourIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceIssueInMonoBehaviour);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Void MyMonoBehaviour::Start()"));
        }
コード例 #9
0
        public void StringConcatIssueIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceStringConcat);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().description.Equals("System.String.Concat"));
        }
コード例 #10
0
        public void AddComponentIssueIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetAddComponent);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Void AddComponentToGameObject::Start()"));
        }
コード例 #11
0
        public void InstantiateIssueIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetInstantiate);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Void InstantiateObject::Start()"));
        }
コード例 #12
0
        public void IssueInVirtualMethodIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetIssueInVirtualMethod);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Void AbstractClass::Dummy()"));
        }
コード例 #13
0
        public void IssueInGenericClassIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetIssueInGenericClass);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Void GenericClass`1::Dummy()"));
        }
コード例 #14
0
        public void IssueInOverrideMethodIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceIssueInOverrideMethod);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Void DerivedClass::Dummy()"));
        }
コード例 #15
0
        public void IssueInPlayerCodeIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceInPlayerCode);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Void MyClassWithPlayerOnlyCode::Dummy()"));
        }
コード例 #16
0
        public void IssueInPluginIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceInPlugin);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Void MyPlugin::Dummy()"));
        }
コード例 #17
0
        public void IssueInDelegateIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceIssueInDelegate);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Int32 ClassWithDelegate/<>c::<Dummy>b__1_0()"));
        }
コード例 #18
0
        public void IssueInCoroutineIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceIssueInCoroutine);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().callingMethod.Equals("System.Boolean MyMonoBehaviourWithCoroutine/<MyCoroutine>d__1::MoveNext()"));
        }
コード例 #19
0
        public void IssueInNestedClassIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetIssueInNestedClass);

            Assert.AreEqual(1, issues.Count());

            Assert.True(issues.First().GetCallingMethod().Equals("System.Void MyClassWithNested/NestedClass::Dummy()"));
        }
コード例 #20
0
        public void IssueInNamespaceIsFound()
        {
            var allScriptIssues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetAnyApiInNamespace);
            var issue           = allScriptIssues.FirstOrDefault(i => i.description.Equals("Enumerable.Sum"));

            Assert.NotNull(issue);

            Assert.True(issue.descriptor.description.Equals("System.Linq.*"));
        }
コード例 #21
0
        public void ShaderWarmupIssueIsCritical()
        {
            var issues =
                ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(
                    m_TempAssetShaderWarmupIssueIsCritical);
            var issue = issues.First();

            Assert.True(issue.isPerfCriticalContext);
        }
コード例 #22
0
        public void IssueInClassMethodCalledFromMonoBehaviourUpdate()
        {
            var issues =
                ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(
                    m_ScriptResourceIssueInClassMethodCalledFromMonoBehaviourUpdate);
            var issue = issues.First();

            Assert.True(issue.isPerfCriticalContext);
        }
コード例 #23
0
        public void IssueInDelegateIsFound()
        {
            var allScriptIssues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetIssueInDelegate);
            var issue           = allScriptIssues.FirstOrDefault(i => i.name.Equals("Camera.get_main"));

            Assert.NotNull(issue);

            Assert.True(issue.callingMethod.Equals("System.Int32 ClassWithDelegate/<>c::<Dummy>b__1_0()"));
        }
コード例 #24
0
        public void IssueInClassInheritedFromMonoBehaviour()
        {
            var issues =
                ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(
                    m_TempAssetIssueInClassInheritedFromMonoBehaviour);
            var issue = issues.First();

            Assert.True(issue.isPerfCriticalContext);
        }
コード例 #25
0
        public void DerivedClassMethodIssueIsFound()
        {
            var filteredIssues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetDerivedClassMethod);

            Assert.AreEqual(1, filteredIssues.Count());

            var myIssue = filteredIssues.FirstOrDefault();

            Assert.NotNull(myIssue);
            Assert.NotNull(myIssue.descriptor);
            Assert.True(myIssue.description.Equals("UnityEngine.Component.tag"));
        }
コード例 #26
0
        public void ObjectAllocationIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceObjectAllocation);

            Assert.AreEqual(1, issues.Count());

            var allocationIssue = issues.FirstOrDefault();

            Assert.NotNull(allocationIssue);
            Assert.True(allocationIssue.description.Equals("'ObjectAllocation' object allocation"));
            Assert.AreEqual(IssueCategory.ApiCalls, allocationIssue.category);
        }
コード例 #27
0
        public void MultidimensionalArrayAllocationIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_TempAssetMultidimensionalArrayAllocation);

            Assert.AreEqual(1, issues.Count());

            var allocationIssue = issues.FirstOrDefault();

            Assert.NotNull(allocationIssue);
            Assert.True(allocationIssue.description.Equals("'Int32[0...,0...]' object allocation"));
            Assert.AreEqual(IssueCategory.Code, allocationIssue.category);
        }
コード例 #28
0
        public void ArrayAllocationIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResourceArrayAllocation);

            Assert.AreEqual(1, issues.Count());

            var allocationIssue = issues.FirstOrDefault();

            Assert.NotNull(allocationIssue);
            Assert.True(allocationIssue.description.Equals("'Int32' array allocation"));
            Assert.AreEqual(IssueCategory.Code, allocationIssue.category);
        }
コード例 #29
0
        public void MonoBehaviourWithEmptyMagicMethodIsReported()
        {
            var scriptIssues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_MonoBehaviourWithEmptyMagicMethod);

            Assert.AreEqual(1, scriptIssues.Count());

            var issue = scriptIssues.FirstOrDefault();

            Assert.NotNull(issue);
            Assert.NotNull(issue.descriptor);

            Assert.AreEqual(Rule.Severity.Default, issue.descriptor.severity);
            Assert.AreEqual(EmptyMethodAnalyzer.GetDescriptor().id, issue.descriptor.id);
            Assert.True(string.IsNullOrEmpty(issue.descriptor.type));
            Assert.True(string.IsNullOrEmpty(issue.descriptor.method));

            Assert.True(issue.name.Equals("MonoBehaviourWithEmptyMagicMethod.Update"));
            Assert.True(issue.filename.Equals(m_MonoBehaviourWithEmptyMagicMethod.scriptName));
            Assert.True(issue.description.Equals("System.Void MonoBehaviourWithEmptyMagicMethod::Update()"));
            Assert.True(issue.GetCallingMethod().Equals("System.Void MonoBehaviourWithEmptyMagicMethod::Update()"));
            Assert.AreEqual(1, issue.line);
            Assert.AreEqual(IssueCategory.Code, issue.category);
        }
コード例 #30
0
        public void IssueIsFound()
        {
            var issues = ScriptIssueTestHelper.AnalyzeAndFindScriptIssues(m_ScriptResource);

            Assert.AreEqual(1, issues.Count());

            var myIssue = issues.FirstOrDefault();

            Assert.NotNull(myIssue);
            Assert.NotNull(myIssue.descriptor);

            Assert.AreEqual(Rule.Action.Default, myIssue.descriptor.action);
            Assert.AreEqual(101000, myIssue.descriptor.id);
            Assert.True(myIssue.descriptor.type.Equals("UnityEngine.Camera"));
            Assert.True(myIssue.descriptor.method.Equals("main"));

            Assert.True(myIssue.name.Equals("Camera.get_main"));
            Assert.True(myIssue.filename.Equals(m_ScriptResource.scriptName));
            Assert.True(myIssue.description.Equals("UnityEngine.Camera.main"));
            Assert.True(myIssue.callingMethod.Equals("System.Void MyClass::Dummy()"));
            Assert.AreEqual(8, myIssue.line);
            Assert.AreEqual(IssueCategory.ApiCalls, myIssue.category);
        }