Example #1
0
        /// <summary>
        /// Dispose of the application logging subsystem
        /// </summary>
        /// <param name="logfile">The logfile to dispose</param>
        public static void DisposeLogging(Logfiles logfile)
        {
            switch (logfile)
            {
            case Logfiles.Application:
                ApplicationLogfile.Dispose();
                ApplicationLogfile = null;
                break;

            case Logfiles.Installer:
                InstallLogfile.Dispose();
                InstallLogfile = null;
                break;

            case Logfiles.Uninstaller:
                UninstallLogfile.Dispose();
                UninstallLogfile = null;
                break;

            case Logfiles.Editor:
                EditorLogfile.Dispose();
                EditorLogfile = null;
                break;

            case Logfiles.PatchDesigner:
                PatcherLogfile.Dispose();
                PatcherLogfile = null;
                break;

            case Logfiles.Updater:
                UpdaterLogfile.Dispose();
                UpdaterLogfile = null;
                break;
            }
        }
Example #2
0
        /// <summary>
        /// Run a complete regression test based on the list of unit tests
        /// </summary>
        /// <returns>Returns false if a setup error occurred, true otherwise</returns>
        /// <remarks>The return value of the method does NOT related to the success of the Unit Tests</remarks>
        public bool RunRegressions()
        {
            //if from the editor, enable verbose logging (allows it to get debug log statements)
            bool tempVerboseLoggingSetting = ModpackSettings.VerboseLogging;

            if (!ModpackSettings.VerboseLogging)
            {
                Logging.Info("p.FromEditor=true and ModpackSettings.VerboseLogging=false, setting to true for duration of patch method");
                ModpackSettings.VerboseLogging = true;
            }

            //init the logfile for regressions
            if (File.Exists(RegressionLogfile.Filepath))
            {
                Logging.Warning("regression log file previously exists, deleting...");
                File.Delete(RegressionLogfile.Filepath);
            }

            if (!RegressionLogfile.Init())
            {
                Logging.Error("failed to initialize logfile");
                return(false);
            }

            //make sure the files to test against exist first
            //and the start file
            if (!File.Exists(Path.Combine(RegressionFolderPath, Startfile)))
            {
                Logging.Error("regressions start file does not exist!");
                Logging.Error(Path.Combine(RegressionFolderPath, Startfile));
                return(false);
            }
            for (int i = 1; i < UnitTests.Count + 1; i++)
            {
                string checkfile = Path.Combine(RegressionFolderPath, string.Format("{0}{1}{2}", CheckFilenamePrefix, i.ToString("D2"), RegressionExtension));
                if (!File.Exists(checkfile))
                {
                    Logging.Error("checkfile does not exist!");
                    Logging.Error(checkfile);
                    return(false);
                }
            }

            //make a new file to be the one to make changes to
            //path get extension gets the dot
            string filenameToTest     = "testfile" + RegressionExtension;
            string filenameToTestPath = Path.Combine(RegressionFolderPath, filenameToTest);

            if (File.Exists(filenameToTestPath))
            {
                File.Delete(filenameToTestPath);
            }
            File.Copy(Path.Combine(RegressionFolderPath, Startfile), filenameToTestPath);

            WriteToLogfiles("----- Unit tests start -----");

            bool breakOutEarly = false;

            foreach (UnitTest unitTest in UnitTests)
            {
                unitTest.Patch.CompletePath = filenameToTestPath;
                unitTest.Patch.File         = filenameToTestPath;
                unitTest.Patch.Type         = RegressionTypeString;
                WriteToLogfiles("Running test {0} of {1}: {2}", ++NumPassed, UnitTests.Count, unitTest.Description);
                unitTest.Patch.FromEditor = true;
                if (unitTest.Patch.FollowPath)
                {
                    //delete testfile
                    if (File.Exists(filenameToTestPath))
                    {
                        File.Delete(filenameToTestPath);
                    }
                    if (NumPassed >= 5)
                    {
                        File.Copy(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"check_04", RegressionExtension)), filenameToTestPath);
                        if (NumPassed == 6)
                        {
                            //backup currentPlayersPanel and copy over new one
                            if (File.Exists(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanelBackup", RegressionExtension))))
                            {
                                File.Delete(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanelBackup", RegressionExtension)));
                            }
                            File.Copy(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension)),
                                      Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanelBackup", RegressionExtension)));

                            if (File.Exists(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension))))
                            {
                                File.Delete(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension)));
                            }
                            File.Copy(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"check_05", RegressionExtension)),
                                      Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension)));
                        }
                        else if (NumPassed == 7)
                        {
                            if (File.Exists(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension))))
                            {
                                File.Delete(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension)));
                            }
                            File.Copy(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"check_06", RegressionExtension)),
                                      Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension)));
                        }
                    }
                    else
                    {
                        File.Copy(Path.Combine(RegressionFolderPath, Startfile), filenameToTestPath);
                    }
                }
                PatchUtils.RunPatch(unitTest.Patch);
                string checkfile = Path.Combine(RegressionFolderPath, string.Format("{0}{1}{2}", CheckFilenamePrefix, NumPassed.ToString("D2"), Path.GetExtension(Startfile)));
                WriteToLogfiles("Checking results against check file {0}...", Path.GetFileName(checkfile));
                string patchRun         = File.ReadAllText(filenameToTestPath);
                string patchTestAgainst = File.ReadAllText(checkfile);
                if (patchTestAgainst.Equals(patchRun))
                {
                    WriteToLogfiles("Success!");
                }
                else
                {
                    WriteToLogfiles("Failed!");
                    breakOutEarly = true;
                    break;
                }
            }

            if (breakOutEarly)
            {
                WriteToLogfiles("----- Unit tests finish (fail)-----");
            }
            else
            {
                WriteToLogfiles("----- Unit tests finish (pass)-----");
                //delete the test file, we don't need it. (it's the same text as the last check file anyways)
                if (File.Exists(filenameToTestPath))
                {
                    File.Delete(filenameToTestPath);
                }
                if (UnitTests[0].Patch.FollowPath)
                {
                    //delete not needed "escaped" files and put playersPanelBackup back
                    if (File.Exists(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension))))
                    {
                        File.Delete(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension)));
                    }
                    File.Copy(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanelBackup", RegressionExtension)),
                              Path.Combine(RegressionFolderPath, string.Format("{0}{1}", @"playersPanel", RegressionExtension)));
                    foreach (string file in new string[] { "battleLabelsTemplates_escaped", "battleLabels_escaped",
                                                           "damageLog_escaped", "playersPanel_escaped", "testfile_escaped", "playersPanelBackup" })
                    {
                        if (File.Exists(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", file, RegressionExtension))))
                        {
                            File.Delete(Path.Combine(RegressionFolderPath, string.Format("{0}{1}", file, RegressionExtension)));
                        }
                    }
                }
            }
            //dispose log file
            RegressionLogfile.Dispose();

            //set the verbose setting back
            Logging.Debug("temp logging setting={0}, ModpackSettings.VerboseLogging={1}, setting logging back to temp");
            ModpackSettings.VerboseLogging = tempVerboseLoggingSetting;
            return(true);
        }