Exemplo n.º 1
0
        public void RunTests(string[] tests)
        {
            Utils.DebugMessage("************* CONFIGURATION ***************");
            Utils.DebugMessage("TEST PLATFORM: " + Config.platform.ToString());
            Utils.DebugMessage("");
            Utils.DebugMessage("VERBOSE: " + Config.Verbose.ToString());
            Utils.DebugMessage("OUTPUT UNLIMITED: " + Config.Unlimited.ToString());
            Utils.DebugMessage("FAST MODE: " + Config.fast.ToString());
            Utils.DebugMessage("OVERWRITE TARGET CODE: " + Config.overwriteTarget.ToString());
            Utils.DebugMessage("PERFORMANCE TESTS: " + Config.performanceTests.ToString());
            Utils.DebugMessage("COMPILATION MODE: " + Config.compileMode.ToString());
            Utils.DebugMessage("*******************************************");
            Console.WriteLine();
            Console.WriteLine();
            foreach (string _s in tests)
            {
                //Removed final '/' if exists
                string s = _s.TrimEnd('/');
                Environment.CurrentDirectory = Utils.testPath;
                KeyValuePair <DirectoryInfo, TestResult> kvp = Tests.First(x => x.Key.Name == s);

                DirectoryInfo di  = kvp.Key;
                TestResult    res = kvp.Value;

                if (s.StartsWith("PT") && !Config.performanceTests)
                {
                    res.cmakeCode   = -10;
                    res.alternative = -10;
                    res.diffCode    = -10;
                    res.msbuildCode = -10;
                    res.output      = -10;
                    continue;
                }

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Running test " + di.Name);
                Console.ResetColor();

                try
                {
                    Environment.CurrentDirectory = Utils.alternativeDirectory;
                    //Run alternative
                    test.Alternative(di, res);
                    Environment.CurrentDirectory = Utils.testPath;
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR IN ALTERNATIVE: " + e.Message);
                    res.alternative = 1;
                }

                try
                {
                    //Diff files
                    Utils.diff(di, res);
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR IN DIFF: " + e.Message);
                    res.diffCode = 1;
                }
                if (Config.fast)
                {
                    res.output = res.msbuildCode = res.cmakeCode = -10;
                    continue;
                }

                if (res.alternative == 0)
                {
                    try
                    {
                        test.Make(di, res);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("ERROR IN MAKE: " + e.Message);
                        res.cmakeCode = -2;
                        res.cmakeCode = -2;
                    }
                }
                else
                {
                    res.output = res.msbuildCode = res.cmakeCode = -10;
                }


                if (kvp.Value.msbuildCode == 0)
                {
                    try
                    {
                        test.CompareOutputs(di, res);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("ERROR COMPARING OUTPUTS: " + e.Message);
                        res.output = 1;
                    }
                }
                else
                {
                    res.output = -10;
                }

                try
                {
                    if (res.msbuildCode == 0 && Config.overwriteTarget)
                    {
                        Utils.OverwriteTarget(di);
                    }

                    //if (res.alternative == 0)
                    //  Utils.CountLines(di, res);
                }
                catch (Exception e)
                {
                    Console.WriteLine("ERROR OVERWRITING FILES OR COUNTING LINES: " + e.Message);
                }
            }

            string[,] arr = new string[tests.Length + 1, 7];
            arr[0, 0]     = "NAME";
            arr[0, 1]     = "X-LATE";
            arr[0, 2]     = "DIFF";
            arr[0, 3]     = "CMAKE";
            arr[0, 4]     = "COMPILE"; // (" + Config.platform.ToString() + "|" + Config.compileMode.ToString() + ")";
            arr[0, 5]     = "OUTPUT";
            arr[0, 6]     = "TIME";
            int i = 1;

            foreach (string _s in tests)
            {
                string s = _s.TrimEnd('/');
                KeyValuePair <DirectoryInfo, TestResult> kvp = Tests.First(x => x.Key.Name == s);
                //KeyValuePair<DirectoryInfo, TestResult> kvp = SearchFirstWithName(s);
                arr[i, 0] = kvp.Value.name;
                arr[i, 1] = kvp.Value.alternative == 0 ? "#gSUCCESS" : (kvp.Value.alternative == -10 ? "#ySKIPPED" : "#rFAIL. Code: " + kvp.Value.alternative);
                arr[i, 2] = kvp.Value.diffCode == 0 ? "#gNo Differ" : (kvp.Value.diffCode == 1 ? "#rDiffer" : (kvp.Value.diffCode == -10 ? "#ySKIPPED" : "#rError. Code: " + kvp.Value.diffCode));
                arr[i, 3] = kvp.Value.cmakeCode == 0 ? "#gSUCCESS" : (kvp.Value.cmakeCode == -10 ? "#ySKIPPED" : "#rFAIL. Code: " + kvp.Value.cmakeCode);
                arr[i, 4] = kvp.Value.msbuildCode == 0 ? "#gSUCCEESS" : (kvp.Value.msbuildCode == -10 ? "#ySKIPPED" : "#rFAIL. Code: " + kvp.Value.msbuildCode);
                arr[i, 5] = kvp.Value.output == 0 ? "#gOK" : (kvp.Value.output == -10 ? "#ySKIPPED" : "#rFAIL");
                arr[i, 6] = (kvp.Value.msTimeSpan >= 0 ? (kvp.Value.msTimeSpan == 0 ? "#y" : "#r") : "#g") + kvp.Value.msTimeSpan.ToString() + " ms " + "(" + kvp.Value.relativeTime.ToString("N2") + "%)";

                i++;
            }
            ArrayPrinter.PrintToConsole(arr);
        }