public void SettingIssuesAreReported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            UnityEditor.PlayerSettings.stripEngineCode = false;
            UnityEngine.Time.fixedDeltaTime            = 0.02f;  // default value
            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.ProjectSettings);

            var fixedDeltaTimeIssue = issues.FirstOrDefault(i => i.descriptor.method.Equals("fixedDeltaTime"));

            Assert.NotNull(fixedDeltaTimeIssue);
            Assert.True(fixedDeltaTimeIssue.location.path.Equals("Project/Time"));

            UnityEngine.Time.fixedDeltaTime = 0.021f;

            projectReport = projectAuditor.Audit();
            issues        = projectReport.GetIssues(IssueCategory.ProjectSettings);
            Assert.Null(issues.FirstOrDefault(i => i.descriptor.method.Equals("fixedDeltaTime")));

            var playerSettingIssue =
                issues.FirstOrDefault(i => i.descriptor.method.Equals("stripEngineCode"));

            Assert.NotNull(playerSettingIssue);
            Assert.True(playerSettingIssue.location.path.Equals("Project/Player"));
        }
        public void SettingIssuesAreReported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            // disabling stripEngineCode will be reported as an issue
            PlayerSettings.stripEngineCode = false;

            // 0.02f is the default Time.fixedDeltaTime value and will be reported as an issue
            Time.fixedDeltaTime = 0.02f;

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.ProjectSettings);

            var fixedDeltaTimeIssue = issues.FirstOrDefault(i => i.descriptor.method.Equals("fixedDeltaTime"));

            Assert.NotNull(fixedDeltaTimeIssue);
            Assert.True(fixedDeltaTimeIssue.description.Equals("Time: Fixed Timestep"));
            Assert.True(fixedDeltaTimeIssue.location.Path.Equals("Project/Time"));

            // "fix" fixedDeltaTime so it's not reported anymore
            Time.fixedDeltaTime = 0.021f;

            projectReport = projectAuditor.Audit();
            issues        = projectReport.GetIssues(IssueCategory.ProjectSettings);
            Assert.Null(issues.FirstOrDefault(i => i.descriptor.method.Equals("fixedDeltaTime")));

            var playerSettingIssue =
                issues.FirstOrDefault(i => i.descriptor.method.Equals("stripEngineCode"));

            Assert.NotNull(playerSettingIssue);
            Assert.True(playerSettingIssue.description.Equals("Player: Engine Code Stripping"));
            Assert.True(playerSettingIssue.location.Path.Equals("Project/Player"));
        }
Example #3
0
        public void SettingIssuesIsNotReportedOnceFixed()
        {
            var savedFixedDeltaTime = Time.fixedDeltaTime;

            // 0.02f is the default Time.fixedDeltaTime value and will be reported as an issue
            Time.fixedDeltaTime = 0.02f;

            var projectAuditor      = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport       = projectAuditor.Audit();
            var issues              = projectReport.GetIssues(IssueCategory.ProjectSettings);
            var fixedDeltaTimeIssue = issues.FirstOrDefault(i => i.descriptor.method.Equals("fixedDeltaTime"));

            Assert.NotNull(fixedDeltaTimeIssue);
            Assert.True(fixedDeltaTimeIssue.description.Equals("Time: Fixed Timestep"));
            Assert.True(fixedDeltaTimeIssue.location.Path.Equals("Project/Time"));

            // "fix" fixedDeltaTime so it's not reported anymore
            Time.fixedDeltaTime = 0.021f;

            projectReport = projectAuditor.Audit();
            issues        = projectReport.GetIssues(IssueCategory.ProjectSettings);
            Assert.Null(issues.FirstOrDefault(i => i.descriptor.method.Equals("fixedDeltaTime")));

            // restore Time.fixedDeltaTime
            Time.fixedDeltaTime = savedFixedDeltaTime;
        }
Example #4
0
        public static IEnumerable <ProjectIssue> AnalyzeAndFindScriptIssues(ScriptResource scriptResource)
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport  = projectAuditor.Audit();

            return(ScriptAuditor.FindScriptIssues(projectReport, scriptResource.relativePath));
        }
Example #5
0
        public void ShouldNotReportMutedIssue()
        {
            var projectAuditor         = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectAuditorSettings = projectAuditor.config;
            var projectReport          = projectAuditor.Audit();
            var issues = ScriptAuditor.FindScriptIssues(projectReport, m_ScriptResource.relativePath);

            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.action, action);

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

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

            // issue has been muted so it should not be reported
            Assert.AreEqual(Rule.Action.None, action);
        }
Example #6
0
        public void RecursiveSearchMatch()
        {
            var config = ScriptableObject.CreateInstance <ProjectAuditorConfig>();

            config.AnalyzeEditorCode = false;

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor(config);

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.Code);
            var stringFilter  = new TextFilter
            {
                matchCase          = true,
                searchDependencies = false,
                searchText         = "WrapperClass"
            };
            var filteredIssues = issues.Where(i => stringFilter.Match(i));

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

            // try again looking into dependencies too
            stringFilter.searchDependencies = true;

            filteredIssues = issues.Where(i => stringFilter.Match(i));
            Assert.AreEqual(1, filteredIssues.Count());
        }
Example #7
0
        public void CaseSensitiveMatch()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            // disabling stripEngineCode will be reported as an issue
            PlayerSettings.stripEngineCode = false;

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.ProjectSettings);
            var stringFilter  = new TextFilter
            {
                matchCase          = true,
                searchDependencies = false,
                searchText         = "Engine Code Stripping"
            };
            var filteredIssues = issues.Where(i => stringFilter.Match(i));

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

            stringFilter.searchText = "engine code stripping";

            filteredIssues = issues.Where(i => stringFilter.Match(i));

            Assert.AreEqual(0, filteredIssues.Count());
        }
Example #8
0
        public void FilteredReportIsExported()
        {
            // disabling stripEngineCode will be reported as a ProjectSettings issue
            PlayerSettings.stripEngineCode = false;

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport  = projectAuditor.Audit();

            const string path = "ProjectAuditor_Report.csv";

            // let's assume we are only interested in exporting project settings
            projectReport.ExportToCSV(path, issue => issue.category == IssueCategory.ProjectSettings);
            Assert.True(File.Exists(path));

            using (var file = new StreamReader(path))
            {
                var line = file.ReadLine();
                Assert.True(line.Equals(ProjectReport.HeaderForCSV()));

                while (file.Peek() >= 0)
                {
                    line = file.ReadLine();
                    Assert.True(line.StartsWith(IssueCategory.ProjectSettings.ToString()));
                }
            }
        }
Example #9
0
        public static ProjectReport AnalyzeBuild()
        {
            // We must save the scene or the build will fail https://unity.slack.com/archives/C3F85MBDL/p1615991512002200
            EditorSceneManager.SaveScene(EditorSceneManager.GetActiveScene(), "Assets/UntitledScene.unity");

            var buildPath = FileUtil.GetUniqueTempPathInProject();

            Directory.CreateDirectory(buildPath);
            var buildPlayerOptions = new BuildPlayerOptions
            {
                scenes           = new string[] {},
                locationPathName = Path.Combine(buildPath, "test"),
                target           = EditorUserBuildSettings.activeBuildTarget,
                targetGroup      = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget),
                options          = BuildOptions.Development
            };
            var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);

            Assert.True(buildReport.summary.result == BuildResult.Succeeded);

            Directory.Delete(buildPath, true);

            AssetDatabase.DeleteAsset("Assets/UntitledScene.unity");

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport  = projectAuditor.Audit();

            return(projectReport);
        }
        public void ShaderVariantsAreReported()
        {
            var buildPath = FileUtil.GetUniqueTempPathInProject();

            Directory.CreateDirectory(buildPath);

            var buildPlayerOptions = new BuildPlayerOptions
            {
                scenes           = new string[] {},
                locationPathName = Path.Combine(buildPath, "test"),
                target           = EditorUserBuildSettings.activeBuildTarget,
                targetGroup      = BuildPipeline.GetBuildTargetGroup(EditorUserBuildSettings.activeBuildTarget),
                options          = BuildOptions.Development
            };
            var buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);

            Assert.True(buildReport.summary.result == UnityEditor.Build.Reporting.BuildResult.Succeeded);

            Directory.Delete(buildPath, true);

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport  = projectAuditor.Audit();
            var issues         = projectReport.GetIssues(IssueCategory.Shaders);

            issues = issues.Where(i => i.description.Equals("Custom/MyTestShader")).ToArray();

            Assert.Positive(issues.Length);
        }
Example #11
0
        public void CustomAuditorIssueIsReported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var report         = projectAuditor.Audit();
            var issues         = report.GetIssues(IssueCategory.Code);

            Assert.NotNull(issues.FirstOrDefault(i => i.description.Equals("This is a test issue")));
        }
Example #12
0
        public void EditorDefaultResourcesShaderIsNotReported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport  = projectAuditor.Audit();
            var issues         = projectReport.GetIssues(IssueCategory.Shaders).Where(i => i.relativePath.Contains("Editor Default Resources")).ToArray();

            Assert.Zero(issues.Length);
        }
        private void Analyze()
        {
            m_ProjectReport = new ProjectReport();

            m_ProjectAuditor.Audit(m_ProjectReport);

            RefreshDisplay();
        }
Example #14
0
        public void PlayerLogDoesNotContainShaderCompilationLog()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport  = projectAuditor.Audit();
            var shadersAuditor = projectAuditor.GetAuditor <ShadersAuditor>();
            var result         = shadersAuditor.ParsePlayerLog(m_PlayerLogWithNoCompilationResource.relativePath, new ProjectIssue[0]);

            Assert.False(result);
        }
Example #15
0
        private void Analyze()
        {
            m_ProjectReport = m_ProjectAuditor.Audit(new ProgressBarDisplay());

            m_ValidReport = true;

            m_IssueTables.Clear();

            RefreshDisplay();
        }
        public void BuildIsRequired()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.Shaders);

            Assert.Positive(issues.Length);
            Assert.True(issues.First().description.Equals("Build the project and run Project Auditor analysis"));
        }
Example #17
0
        public void ShaderVariantsRequireBuild()
        {
            ShadersAuditor.CleanupBuildData();
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.ShaderVariants);

            Assert.Positive(issues.Length);
            Assert.True(issues.First().description.Equals("Build the project to view the Shader Variants"));
        }
Example #18
0
        public void MetaDataIsReported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.MetaData);
            var matchingIssue = issues.FirstOrDefault(i => i.description.Equals("Unity Version"));

            Assert.NotNull(matchingIssue);
            Assert.True(matchingIssue.GetCustomProperty(0).Equals(Application.unityVersion));
        }
Example #19
0
        public void ShaderVariantsRequireBuild()
        {
            ShadersAuditor.CleanupBuildData();
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.ShaderVariants);

            Assert.Zero(issues.Length);
            Assert.False(ShadersAuditor.BuildDataAvailable());
        }
Example #20
0
        public void EditorShaderIsNotReported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.Shaders);

            issues = issues.Where(i => i.description.Equals("Custom/MyEditorShader")).ToArray();

            Assert.Zero(issues.Length);
        }
Example #21
0
        public void CanSaveAndLoadReport()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();

            projectReport.Save(k_ReportPath);

            var loadedReport = ProjectReport.Load(k_ReportPath);

            Assert.AreEqual(projectReport.NumTotalIssues, loadedReport.NumTotalIssues);
        }
Example #22
0
        public void ShaderWithErrorIsReported()
        {
            var projectAuditor    = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport     = projectAuditor.Audit();
            var issues            = projectReport.GetIssues(IssueCategory.Shaders);
            var shadersWithErrors = issues.Where(i => i.severity == Rule.Severity.Error);

            Assert.Positive(shadersWithErrors.Count());
            var shaderIssue = issues.FirstOrDefault(i => i.relativePath.Equals(m_ShaderWithErrorResource.relativePath));

            Assert.NotNull(shaderIssue);
        }
Example #23
0
        public void EditorCodeIssueIsNotReported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            Assert.False(projectAuditor.config.AnalyzeEditorCode);

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.Code);
            var codeIssue     = issues.FirstOrDefault(i => i.relativePath.Equals(m_ScriptResource.relativePath));

            Assert.Null(codeIssue);
        }
Example #24
0
        public void ReportIsExportedAndFormatted()
        {
            // disabling stripEngineCode will be reported as a ProjectSettings issue
            PlayerSettings.stripEngineCode = false;

            var config = ScriptableObject.CreateInstance <ProjectAuditorConfig>();

            config.AnalyzeEditorCode = false;

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor(config);

            var projectReport = projectAuditor.Audit();

            const string path = "ProjectAuditor_Report.csv";

            projectReport.ExportToCSV(path);
            Assert.True(File.Exists(path));

            var settingsIssue = projectReport.GetIssues(IssueCategory.ProjectSettings)
                                .First(i => i.descriptor.method.Equals("stripEngineCode"));
            var scriptIssue = projectReport.GetIssues(IssueCategory.Code)
                              .First(i => i.relativePath.Equals(m_TempAsset.relativePath));

            var settingsIssueFound = false;
            var scriptIssueFound   = false;

            using (var file = new StreamReader(path))
            {
                var line = file.ReadLine();
                Assert.True(line.Equals(ProjectReport.HeaderForCSV()));

                var expectedSettingsIssueLine = ProjectReport.FormatIssueForCSV(settingsIssue);
                var expectedScriptIssueLine   = ProjectReport.FormatIssueForCSV(scriptIssue);
                while (file.Peek() >= 0)
                {
                    line = file.ReadLine();
                    if (line.Equals(expectedSettingsIssueLine))
                    {
                        settingsIssueFound = true;
                    }
                    if (line.Equals(expectedScriptIssueLine))
                    {
                        scriptIssueFound = true;
                    }
                }
            }

            Assert.True(settingsIssueFound);
            Assert.True(scriptIssueFound);
        }
Example #25
0
        public void ReportIsExportedAndFormatted()
        {
            // disabling stripEngineCode will be reported as a ProjectSettings issue
            PlayerSettings.stripEngineCode = false;

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();

            const string path = "ProjectAuditor_Report.csv";

            projectReport.Export(path);
            Assert.True(File.Exists(path));

            var settingsIssue = projectReport.GetIssues(IssueCategory.ProjectSettings)
                                .First(i => i.descriptor.method.Equals("stripEngineCode"));
            var scriptIssue = projectReport.GetIssues(IssueCategory.ApiCalls)
                              .First(i => i.relativePath.Equals(m_ScriptResource.relativePath));

            var settingsIssueFound = false;
            var scriptIssueFound   = false;

            using (var file = new StreamReader(path))
            {
                var line = file.ReadLine();
                Assert.True(line.Equals("Issue,Message,Area,Path"));

                var expectedSettingsIssueLine = string.Format("{0},{1},{2},{3}", settingsIssue.descriptor.description,
                                                              settingsIssue.description,
                                                              settingsIssue.descriptor.area, settingsIssue.relativePath);
                var expectedScriptIssueLine = string.Format("{0},{1},{2},{3}:{4}", scriptIssue.descriptor.description,
                                                            scriptIssue.description,
                                                            scriptIssue.descriptor.area, scriptIssue.relativePath, scriptIssue.line);
                while (file.Peek() >= 0)
                {
                    line = file.ReadLine();
                    if (line.Equals(expectedSettingsIssueLine))
                    {
                        settingsIssueFound = true;
                    }
                    if (line.Equals(expectedScriptIssueLine))
                    {
                        scriptIssueFound = true;
                    }
                }
            }

            Assert.True(settingsIssueFound);
            Assert.True(scriptIssueFound);
        }
        public void EditorCodeIssueIsReported()
        {
            var config = ScriptableObject.CreateInstance <ProjectAuditorConfig>();

            config.AnalyzeEditorCode = true;

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor(config);
            var projectReport  = projectAuditor.Audit();

            var issues    = projectReport.GetIssues(IssueCategory.Code);
            var codeIssue = issues.FirstOrDefault(i => i.relativePath.Equals(m_TempAsset.relativePath));

            Assert.NotNull(codeIssue);
        }
        void AnalyzeAndExport(IssueCategory category, string path)
        {
            var config = ScriptableObject.CreateInstance <ProjectAuditorConfig>();

            config.AnalyzeEditorCode = false;

            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor(config);
            var projectReport  = projectAuditor.Audit();
            var layout         = projectAuditor.GetLayout(category);

            projectReport.ExportToCSV(path, layout);

            Assert.True(File.Exists(path));
        }
Example #28
0
        public void FilenameMatch()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.Code);
            var stringFilter  = new TextFilter
            {
                matchCase          = false,
                searchDependencies = false,
                searchText         = "FilterTests.cs"
            };
            var filteredIssues = issues.Where(i => stringFilter.Match(i));

            Assert.AreEqual(1, filteredIssues.Count());
        }
Example #29
0
        public void ShaderIsReported()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();
            var projectReport  = projectAuditor.Audit();
            var issues         = projectReport.GetIssues(IssueCategory.Shaders);
            var shaderIssue    = issues.FirstOrDefault(i => i.description.Equals("Custom/MyTestShader"));

            Assert.NotNull(shaderIssue);

            // check custom property
            Assert.AreEqual((int)ShaderProperty.Num, shaderIssue.GetNumCustomProperties());
            Assert.True(shaderIssue.GetCustomProperty((int)ShaderProperty.NumVariants).Equals("N/A"));
            Assert.True(shaderIssue.GetCustomProperty((int)ShaderProperty.NumPasses).Equals("4"));
            Assert.True(shaderIssue.GetCustomProperty((int)ShaderProperty.NumKeywords).Equals("22"));
            Assert.True(shaderIssue.GetCustomProperty((int)ShaderProperty.RenderQueue).Equals("2000"));
            Assert.True(shaderIssue.GetCustomProperty((int)ShaderProperty.Instancing).Equals("Yes"));
        }
Example #30
0
        public void AreaNameIsValid()
        {
            var projectAuditor = new Unity.ProjectAuditor.Editor.ProjectAuditor();

            // disabling stripUnusedMeshComponents will be reported as an issue
            PlayerSettings.stripUnusedMeshComponents = false;

            var projectReport = projectAuditor.Audit();
            var issues        = projectReport.GetIssues(IssueCategory.ProjectSettings);

            var strippingIssue = issues.FirstOrDefault(i => i.descriptor.method.Equals("stripUnusedMeshComponents"));

            Assert.NotNull(strippingIssue);
            Assert.True(strippingIssue.descriptor.area.Contains(Area.BuildSize.ToString()));
            Assert.True(strippingIssue.descriptor.area.Contains(Area.LoadTimes.ToString()));
            Assert.True(strippingIssue.descriptor.area.Contains(Area.GPU.ToString()));
            Assert.True(strippingIssue.descriptor.area.Equals("BuildSize|LoadTimes|GPU"));
        }