Exemplo n.º 1
0
        private string FindBrainFile(BrainTest test)
        {
            string brainFileName = test.BrainFileName;

            if (Path.IsPathRooted(brainFileName))
            {
                if (!File.Exists(brainFileName))
                {
                    throw new InvalidTestException("Brain file not found: " + brainFileName);
                }

                return(brainFileName);
            }

            string defaultPath = Path.GetFullPath(Path.Combine(DefaultBrainFilePath, brainFileName));

            if (File.Exists(defaultPath))
            {
                return(defaultPath);
            }

            // try also relative path
            if (File.Exists(Path.GetFullPath(brainFileName)))
            {
                return(Path.GetFullPath(brainFileName));
            }

            throw new InvalidTestException("Brain file not found: " + defaultPath);  // complain about the default path
        }
Exemplo n.º 2
0
        private static void RunTest(BrainTest test, MyProjectRunner projectRunner)
        {
            var brainScan = new BrainScan(projectRunner);
            var step      = new StepChecker();

            try
            {
                while (true)
                {
                    projectRunner.RunAndPause(GetIterationStepCount(test, projectRunner.SimulationStep));

                    step.AssertIncreased(projectRunner.SimulationStep);

                    if ((projectRunner.SimulationStep >= test.MaxStepCount) || ShouldStop(test, brainScan))
                    {
                        break;
                    }
                }

                test.Check(brainScan);
            }
            finally
            {
                //MyLog.WARNING.WriteLine("  simulation step: {0}", projectRunner.SimulationStep);  // TODO(Premek): pass simulation step to the reporter

                projectRunner.Reset();
            }
        }
Exemplo n.º 3
0
        private void EvaluateTest(BrainTest test, MyProjectRunner projectRunner)
        {
            try
            {
                OpenProject(test, projectRunner);

                ValidateTest(test);

                m_reporter.StartTest(test);

                RunTest(test, m_projectRunner);

                m_reporter.AddPass(test);
            }
            catch (InvalidTestException e)
            {
                m_reporter.AddInvalidTest(test, e);
            }
            catch (BrassertFailedException e)
            {
                m_reporter.AddFail(test, e);
            }
            catch (XunitException e) // TODO: handle specificly AssertActualExpectedException
            {
                m_reporter.AddFail(test, e);
            }
            catch (Exception e)
            {
                m_reporter.AddCrash(test, e);
            }
        }
Exemplo n.º 4
0
        private static uint GetIterationStepCount(BrainTest test, uint simulationStep)
        {
            int inspectInterval = test.InspectInterval;

            if (inspectInterval < 1)
            {
                throw new InvalidTestException("Invalid inspect interval: " + inspectInterval);
            }

            return((uint)Math.Min(inspectInterval, test.MaxStepCount - simulationStep));   // limit to remaining steps
        }
Exemplo n.º 5
0
        private void PrintLine(string what, BrainTest test, string message = "", ConsoleColor color = 0)
        {
            if (color != 0)
            {
                Console.ForegroundColor = color;
            }

            Console.Write(" {0, -10} ", what);
            Console.ResetColor();

            Console.WriteLine("{0}{1}", test.Name, string.IsNullOrEmpty(message) ? "" : ": " + message);
        }
Exemplo n.º 6
0
        private void OpenProject(BrainTest test, MyProjectRunner projectRunner)
        {
            var brainUnitNodeTest = test as BrainUnitNodeTest;

            if (brainUnitNodeTest != null)  // TODO: solve using polymorphism
            {
                brainUnitNodeTest.Initialize(projectRunner);
            }
            else
            {
                projectRunner.OpenProject(FindBrainFile(test));
            }
        }
Exemplo n.º 7
0
        public void AddPass(BrainTest test)
        {
            Evaluate(passed: !test.ExpectedToFail);

            if (test.ExpectedToFail)
            {
                PrintLine(" Unexpected OK!", test, "Expected to fail!", ConsoleColor.Red);
            }
            else
            {
                PrintLine("      OK", test);
            }
        }
Exemplo n.º 8
0
        public void AddFail(BrainTest test, Exception e)
        {
            Evaluate(passed: test.ExpectedToFail);

            if (test.ExpectedToFail)
            {
                PrintLine("      XF", test, "(Expected to fail.)", ConsoleColor.DarkGray);
            }
            else
            {
                PrintLine("    FAIL", test, e.Message, ConsoleColor.Red);
            }
        }
Exemplo n.º 9
0
        private void ValidateTest(BrainTest test)
        {
            if (string.IsNullOrEmpty(test.BrainFileName))
            {
                throw new InvalidTestException("Missing brain file name in the test.");
            }

            FindBrainFile(test);  // ignore result for now

            if (test.MaxStepCount < 1)
            {
                throw new InvalidTestException("Invalid MaxStepCount: " + test.MaxStepCount);
            }
        }
Exemplo n.º 10
0
        private static bool ShouldStop(BrainTest test, IBrainScan brainScan)
        {
            try
            {
                if (test.ShouldStop(brainScan))
                {
                    return(true);
                }
            }
            // assert failues in ShouldStop mean "don't stop yet" (allow to use same asserts as in Check())
            catch (XunitException) { }
            catch (BrassertFailedException) { }

            return(false);
        }
Exemplo n.º 11
0
 public void AddCrash(BrainTest test, Exception e)
 {
     Evaluate(passed: false);
     PrintLine("CRASH!", test, e.Message, ConsoleColor.Red);
 }
Exemplo n.º 12
0
 public void AddInvalidTest(BrainTest test, InvalidTestException e)
 {
     Evaluate(passed: false);
     PrintLine("invalid test", test, e.Message, ConsoleColor.Red);
 }
Exemplo n.º 13
0
 public void StartTest(BrainTest test)
 {
     PrintLine("RUN", test);
 }