コード例 #1
0
ファイル: TestRunner.cs プロジェクト: sschocke/BrainSimulator
        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();
            }
        }
コード例 #2
0
ファイル: TestRunner.cs プロジェクト: sschocke/BrainSimulator
        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
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
ファイル: TestRunner.cs プロジェクト: Soucha/BrainSimulator
        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;
        }
コード例 #6
0
ファイル: TestRunner.cs プロジェクト: Soucha/BrainSimulator
        private void RunTest(BrainTest test, MyProjectRunner projectRunner)
        {
            projectRunner.OpenProject(FindBrainFile(test));
            projectRunner.DumpNodes();

            var brainScan = new BrainScan(projectRunner);

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

                    if (ShouldStop(test, brainScan))
                        break;
                }
                while (projectRunner.SimulationStep < test.MaxStepCount);

                test.Check(brainScan);
            }
            finally
            {
                projectRunner.Reset();
            }
        }
コード例 #7
0
ファイル: TestReporter.cs プロジェクト: Soucha/BrainSimulator
 public void AddFail(BrainTest test, Exception e)
 {
     Evaluate(passed: false);
     PrintLine("    FAIL", test, e.Message, ConsoleColor.Red);
 }
コード例 #8
0
ファイル: TestRunner.cs プロジェクト: sschocke/BrainSimulator
        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);
        }
コード例 #9
0
ファイル: TestRunner.cs プロジェクト: sschocke/BrainSimulator
 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));
     }
 }
コード例 #10
0
ファイル: TestRunner.cs プロジェクト: sschocke/BrainSimulator
        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
        }
コード例 #11
0
ファイル: TestRunner.cs プロジェクト: sschocke/BrainSimulator
        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);
            }
        }
コード例 #12
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);
        }
コード例 #13
0
 public void StartTest(BrainTest test)
 {
     PrintLine("RUN", test);
 }
コード例 #14
0
 public void AddInvalidTest(BrainTest test, InvalidTestException e)
 {
     Evaluate(passed: false);
     PrintLine("invalid test", test, e.Message, ConsoleColor.Red);
 }
コード例 #15
0
 public void AddCrash(BrainTest test, Exception e)
 {
     Evaluate(passed: false);
     PrintLine("CRASH!", test, e.Message, ConsoleColor.Red);
 }
コード例 #16
0
ファイル: TestReporter.cs プロジェクト: Soucha/BrainSimulator
 private static string GetTestName(BrainTest test)
 {
     return test.GetType().ToString();
 }
コード例 #17
0
ファイル: TestReporter.cs プロジェクト: Soucha/BrainSimulator
 public void AddPass(BrainTest test)
 {
     Evaluate(passed: true);
     PrintLine("      OK", test);
 }