public void RunTestDescribe(TestDescribe describe, RunContext runContext) { SetupExecutionPolicy(); describe.SetOutcome(TestOutcome.None); runContext.TestFiles.Add(describe.Parent.Path, describe.Parent); RunTests(runContext, describe.Name, null); }
protected static bool DiscoverPesterTests(string source, TestDescribeCollection tests, IMessageLogger logger) { if (!File.Exists(source)) { return(false); } //SendMessage(TestMessageLevel.Informational, string.Format(Resources.SearchingForTestsFormat, source), logger); Token[] tokens; ParseError[] errors; ScriptBlockAst ast = Parser.ParseFile(source, out tokens, out errors); //if (errors.Any()) //{ // foreach (var error in errors) // { // SendMessage(TestMessageLevel.Error, string.Format(Resources.ParserErrorFormat, error.Message), logger); // } // return; //} IEnumerable <Ast> testSuites = ast.FindAll( m => (m is CommandAst) && string.Equals("describe", ((CommandAst)m).GetCommandName(), StringComparison.OrdinalIgnoreCase), true); foreach (Ast describeAst in testSuites) { string describeName = GetFunctionName(logger, describeAst, "describe"); Dictionary <string, TestContext> contextByName = new Dictionary <string, TestContext>(); //IEnumerable<string> tags = GetDescribeTags(logger, describeAst); IEnumerable <Ast> its = describeAst.FindAll(m => (m as CommandAst)?.GetCommandName()?.Equals("it", StringComparison.OrdinalIgnoreCase) == true, true); foreach (Ast test in its) { CommandAst itAst = (CommandAst)test; string itName = GetFunctionName(logger, test, "it"); string contextName = GetParentContextName(logger, test); if (!contextByName.TryGetValue(contextName, out TestContext context)) { context = new TestContext { Name = contextName, Path = source }; contextByName.Add(contextName, context); } // Didn't find the name for the test. Skip it. if (string.IsNullOrEmpty(itName)) { SendMessage(TestMessageLevel.Informational, "Test name was empty. Skipping test.", logger); continue; } TestIt it = new TestIt { Name = itName, Ast = itAst, Path = source, LineNr = itAst.Extent.StartLineNumber }; context.Its.Add(it); } if (contextByName.Count > 0) { TestDescribe describe = new TestDescribe { Name = describeName, Ast = describeAst, Path = source, LineNr = describeAst.Extent.StartLineNumber }; foreach (TestContext context in contextByName.Values) { describe.Contexts.Add(context); } tests.Add(describe); } } return(true); }