Пример #1
0
        public static void Main()
        {
            using (var streamReader = new StreamReader(@"arrays.fuspec", System.Text.Encoding.Default))
            {
                try
                {
                    var specs = FuspecParser.Read(streamReader);
                    if (specs.Any())
                    {
                        foreach (var fus in specs)
                        {
                            fus.Print();
                        }
                    }
                    else
                    {
                        Console.WriteLine("No tests!");
                    }
                }
                catch (FuspecParserException e)
                {
                    var error = e.Errors.FirstOrDefault();
                    Console.WriteLine("Error in line: {0}", error.LineNumber);
                    Console.WriteLine(error.ErrorType.ToString());

                    throw;
                }
            }
        }
Пример #2
0
        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);
        }