private void CkeckTypesAndValues(FunRuntime runtime, FuspecTestCase fus) { TypeAndValuesException outputInputException = new TypeAndValuesException(); // Check OutputInputsErrors outputInputException.AddErrorMessage(CompareInOutTypeAndGetMessageErrorOrNull(fus.InputVarList, runtime.Inputs)); outputInputException.AddErrorMessage(CompareInOutTypeAndGetMessageErrorOrNull(fus.OutputVarList, runtime.Outputs)); //check SetCheckErrors var numberOfKit = 0; foreach (var checkOrSetKit in fus.SetChecks) { numberOfKit++; if (checkOrSetKit is SetData) { outputInputException.AddErrorMessage(CompareSetCheckTypesAndGetMessageOrNull(numberOfKit, checkOrSetKit.ValuesKit, runtime.Inputs)); } else { outputInputException.AddErrorMessage(CompareSetCheckTypesAndGetMessageOrNull(numberOfKit, checkOrSetKit.ValuesKit, runtime.Outputs)); } } // if find some output/input errors if (outputInputException.Messages.Any()) { throw outputInputException; } }
public Statistic RunTests(string directoryPath) { // var allFoundFiles = Directory.GetFiles(directoryPath, "arithmetic.fuspec", SearchOption.AllDirectories); var allFoundFiles = Directory.GetFiles(directoryPath, "*.fuspec", SearchOption.AllDirectories); var statistic = new Statistic(allFoundFiles.Length); foreach (var file in allFoundFiles) { _consoleWriter.PrintTestingFileName(file); using (var streamReader = new StreamReader(file, System.Text.Encoding.Default)) { IEnumerable <FuspecTestCase> specs = new FuspecTestCase[0]; try { specs = FuspecParser.Read(streamReader); foreach (var fus in specs) { _testCaseResult = new TestCaseResult(file, fus); _consoleWriter.PrintFuspecName(fus.Name); if (!fus.IsTestExecuted) { _consoleWriter.PrintTODOTest(); } else { try { var runtime = Funny.Hardcore.Build(fus.Script); CkeckTypesAndValues(runtime, fus); RunOneTest(runtime, fus); _consoleWriter.PrintOkTest(); } catch (Exception e) { _testCaseResult.SetError(e); _consoleWriter.PrintError(e); } } statistic.AddTestToStatistic(_testCaseResult); } if (!specs.Any()) { _consoleWriter.PrintNoTests(); } } catch (FuspecParserException e) { statistic.AddFileReadingError(file, e); _consoleWriter.PrintError(e); } } } return(statistic); }
private void RunOneTest(FunRuntime runtime, FuspecTestCase fus) { TypeAndValuesException outputInputException = new TypeAndValuesException(); var numberOfKit = 0; var setKit = new SetData(); if (!runtime.Inputs.Any()) { runtime.Calc(); } foreach (var checkOrSetKit in fus.SetChecks) { numberOfKit++; if (checkOrSetKit is SetData) { setKit = (SetData)checkOrSetKit; runtime.Calc(setKit.ValuesKit.Select(v => (v.Name, v.Value)).ToArray()); } /* if (checkOrSetKit is CheckData checkKit) * { * CalculationResult results; * if (!runtime.Inputs.Any()) * results = runtime.Calculate(); * else * results = runtime.Calculate(setKit.ValuesKit); * * foreach (var res in results.Results) * { * //c��������� ���������� �������� � �heck * } * }*/ } if (outputInputException.Messages.Any()) { throw outputInputException; } }
public static void Print(this FuspecTestCase fuspecTestCase) { Console.WriteLine("----------------------"); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("| Name of test: "); Console.ResetColor(); Console.WriteLine("{0}", fuspecTestCase.Name); Console.Write("| Tags: "); if (fuspecTestCase.Tags.Length == 0) { Console.WriteLine("No tags"); } else { foreach (var tag in fuspecTestCase.Tags) { Console.WriteLine(tag + " "); } } if (fuspecTestCase.InputVarList.Length != 0) { PrintElement("| Type for input parameters: ", fuspecTestCase.InputVarList); } if (fuspecTestCase.OutputVarList.Length != 0) { PrintElement("| Type for output parameters: ", fuspecTestCase.OutputVarList); } Console.WriteLine("| Body script:"); Console.WriteLine(fuspecTestCase.Script); if (fuspecTestCase.SetChecks.Length != 0) { Console.WriteLine("| Sets of values "); int i = 0; foreach (var setCheckKit in fuspecTestCase.SetChecks) { i++; Console.Write("\t"); if (setCheckKit is SetData) { Console.Write(" set: "); } else { Console.Write(" check: "); } if (setCheckKit.ValuesKit.Any()) { foreach (var kit in setCheckKit.ValuesKit) { Console.Write(kit.Name + ":" + kit.Value + "(" + kit.Type + "), "); } } else { Console.Write("None"); } Console.WriteLine(); } } }
public TestCaseResult(string fileName, FuspecTestCase fus) { FileName = fileName; Fus = fus; _error = null; }