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 }
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(); } }
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); } }
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 }
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); }
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)); } }
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); } }
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); } }
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); } }
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); }
public void AddCrash(BrainTest test, Exception e) { Evaluate(passed: false); PrintLine("CRASH!", test, e.Message, ConsoleColor.Red); }
public void AddInvalidTest(BrainTest test, InvalidTestException e) { Evaluate(passed: false); PrintLine("invalid test", test, e.Message, ConsoleColor.Red); }
public void StartTest(BrainTest test) { PrintLine("RUN", test); }