Exemple #1
0
        public void TestScriptExecution(string fileName, long expectedFileLength)
        {
            /*
             * Get the mods listed above and put them into the OMODFramework.Test/files/obmm-scripting folder. They
             * will be copied to the output folder post build. I don't want to download those mods in the CI so this
             * test can only be run locally.
             */

            //TODO: make this run on the CI without having to download the mods (use data+plugin files index)

            var file = Path.Combine("files", "obmm-scripting", fileName);

            if (!File.Exists(file))
            {
                return;
            }

            var fi = new FileInfo(file);
            var actualFileLength = fi.Length;

            Assert.Equal(expectedFileLength, actualFileLength);

            var resultsFile = Path.Combine("files", "obmm-scripting", fileName + "-Results.txt");

            Assert.True(File.Exists(resultsFile));

            using var omod = new OMOD(file);

            var externalScriptFunctions = new ExternalScriptFunctionsForTesting(resultsFile, fileName);
            var settings = new OMODScriptSettings(externalScriptFunctions)
            {
                DryRun             = true,
                UseBitmapOverloads = false
            };

            var srd = OMODScriptRunner.RunScript(omod, settings);

            VerifyFiles(externalScriptFunctions.DataFiles, srd.DataFiles);
            VerifyFiles(externalScriptFunctions.PluginFiles, srd.PluginFiles);
        }
        public void TestCSharpScript(string fileName, long expectedFileLength, uint scriptCRC)
        {
            var file = Path.Combine("files", "csharp-scripting", fileName);

            if (!File.Exists(file))
            {
                return;
            }

            var fi = new FileInfo(file);
            var actualFileLength = fi.Length;

            Assert.Equal(expectedFileLength, actualFileLength);

            using var omod = new OMOD(file);

            var script = omod.GetScript();
            var crc    = Crc32Algorithm.Compute(Encoding.UTF8.GetBytes(script));

            Assert.Equal(scriptCRC, crc);

            //TODO: set this variable back to false once done testing locally
            const bool runScript = false;

            if (!runScript)
            {
                return;
            }
#pragma warning disable 162
            if (TestUtils.IsCI)
            {
                throw new Exception($"Someone forgot to change the runScript variable back to false before commiting!");
            }
            var scriptFunctions = new ExternalScriptFunctionsForTesting();
            var srd             = OMODScriptRunner.RunScript(omod, new OMODScriptSettings(scriptFunctions));

            Directory.Delete(srd.DataFolder);
            Directory.Delete(srd.PluginsFolder);
#pragma warning restore 162
        }