Support Ignore exceptions
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2d58945d Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2d58945d Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2d58945d Branch: refs/heads/TINKERPOP-1827 Commit: 2d58945d7624214e8beab18ed5cc9e586ff83504 Parents: 670ec46 Author: Jorge Bay Gondra <jorgebaygon...@gmail.com> Authored: Fri Nov 17 12:59:46 2017 +0100 Committer: Jorge Bay Gondra <jorgebaygon...@gmail.com> Committed: Tue Nov 21 11:46:19 2017 +0100 ---------------------------------------------------------------------- .../Gherkin/CommonSteps.cs | 8 +- .../Gherkin/GherkinTestRunner.cs | 83 +++++++++++++------- .../Gherkin/IgnoreException.cs | 55 +++++++++++++ .../ModernGraphTypeInformation.cs | 9 +++ 4 files changed, 127 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d58945d/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs index 1c2c8fa..4b99fd8 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/CommonSteps.cs @@ -58,7 +58,8 @@ namespace Gremlin.Net.IntegrationTest.Gherkin {@"p\[(.+)\]", ToPath}, {@"l\[(.+)\]", ToList}, {@"s\[(.+)\]", ToSet}, - {@"m\[(.+)\]", ToMap} + {@"m\[(.+)\]", ToMap}, + {@"c\[(.+)\]", ToLambda} }.ToDictionary(kv => new Regex("^" + kv.Key + "$", RegexOptions.Compiled), kv => kv.Value); [Given("the (\\w+) graph")] @@ -198,6 +199,11 @@ namespace Gremlin.Net.IntegrationTest.Gherkin return jsonMap.ToDictionary(kv => kv.Key, kv => ParseMapValue(kv.Value, graphName)); } + private static object ToLambda(string stringLambda, string graphName) + { + throw new IgnoreException(IgnoreReason.LambdaNotSupported); + } + private static object ParseMapValue(JToken value, string graphName) { if (value.Type == JTokenType.Array) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d58945d/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs index 5527705..b03211c 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/GherkinTestRunner.cs @@ -40,8 +40,6 @@ namespace Gremlin.Net.IntegrationTest.Gherkin { public class GherkinTestRunner { - private readonly ITestOutputHelper _output; - private static class Keywords { public const string Given = "GIVEN"; @@ -64,6 +62,8 @@ namespace Gremlin.Net.IntegrationTest.Gherkin { StepBlock.When, typeof(WhenAttribute) }, { StepBlock.Then, typeof(ThenAttribute) } }; + + private readonly ITestOutputHelper _output; public GherkinTestRunner(ITestOutputHelper output) { @@ -73,7 +73,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin [Fact] public void RunGherkinBasedTests() { - Console.WriteLine("Starting Gherkin-based tests"); + WriteOutput("Starting Gherkin-based tests"); var stepDefinitionTypes = GetStepDefinitionTypes(); var results = new List<ResultFeature>(); foreach (var feature in GetFeatures()) @@ -104,6 +104,8 @@ namespace Gremlin.Net.IntegrationTest.Gherkin if (result != null) { failedSteps.Add(step, result); + // Stop processing scenario + break; } } } @@ -115,35 +117,26 @@ namespace Gremlin.Net.IntegrationTest.Gherkin private void WriteOutput(string line) { +#if DEBUG _output.WriteLine(line); +#else + Console.WriteLine(line); +#endif } private void OutputResults(List<ResultFeature> results) { - var totalScenarios = results.Sum(f => f.Scenarios.Count); - var totalFailedScenarios = results.Sum(f => f.Scenarios.Count(s => s.Value.Count > 0)); - Console.WriteLine("Gherkin tests summary"); - Console.WriteLine($"Total scenarios: {totalScenarios}. " + - $"Passed: {totalScenarios-totalFailedScenarios}. Failed: {totalFailedScenarios}."); - if (totalFailedScenarios == 0) - { - return; - } + WriteOutput("Gherkin tests result"); var identifier = 0; - var failures = new List<Exception>(); + var failures = new List<Tuple<string, Exception>>(); + var totalScenarios = 0; + var totalFailed = 0; + var totalIgnored = 0; foreach (var resultFeature in results) { - var failedScenarios = resultFeature.Scenarios.Where(s => s.Value.Count > 0).ToArray(); - if (failedScenarios.Length > 0) - { - WriteOutput($"Feature: {resultFeature.Feature.Name}"); - } - else - { - continue; - } - foreach (var resultScenario in failedScenarios) + foreach (var resultScenario in resultFeature.Scenarios) { + totalScenarios++; WriteOutput($" Scenario: {resultScenario.Key.Name}"); foreach (var step in resultScenario.Key.Steps) { @@ -154,16 +147,44 @@ namespace Gremlin.Net.IntegrationTest.Gherkin } else { - WriteOutput($" {++identifier}) {step.Keyword} {step.Text} (failed)"); - failures.Add(failure); + if (failure is IgnoreException) + { + totalIgnored++; + WriteOutput($" {++identifier}) {step.Keyword} {step.Text} (ignored)"); + } + else + { + totalFailed++; + WriteOutput($" {++identifier}) {step.Keyword} {step.Text} (failed)"); + } + failures.Add(Tuple.Create(resultScenario.Key.Name, failure)); } } } } - WriteOutput("Failures:"); + if (totalFailed > 0) + { + WriteOutput("Failures" + (totalIgnored > 0 ? " and skipped scenarios" : "") + ":"); + } + else if (totalIgnored > 0) + { + WriteOutput("Skipped scenarios:"); + } for (var index = 0; index < failures.Count; index++) { - WriteOutput($"{index+1}) {failures[index]}"); + var failure = failures[index]; + var message = failure.Item2 is IgnoreException + ? ": " + failure.Item2.Message + : ": Failed\n" + failure.Item2; + WriteOutput($"{index+1}) {failure.Item1}{message}"); + } + WriteOutput("-----------------"); + WriteOutput($"Total scenarios: {totalScenarios}." + + $" Passed: {totalScenarios-totalFailed-totalIgnored}." + + $" Failed: {totalFailed}. Skipped: {totalIgnored}."); + if (totalFailed == 0) + { + return; } throw new Exception($"Gherkin test failed, see summary above for more detail"); } @@ -332,6 +353,14 @@ namespace Gremlin.Net.IntegrationTest.Gherkin "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/AddVertex.feature", "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/ValueMap.feature", "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Select.feature", + "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Project.feature", + "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Path.feature", + "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Map.feature", + "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Match.feature", + "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Max.feature", + "/Users/jorge/workspace/tinkerpop/gremlin-test/features/map/Mean.feature", + + "/Users/jorge/workspace/tinkerpop/gremlin-test/features/sideEffect/Sack.feature", }; // var files = new [] {"/Users/jorge/workspace/temp/count.feature"}; // var files = Directory.GetFiles(path, "*.feature", SearchOption.AllDirectories); http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d58945d/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs new file mode 100644 index 0000000..ae236c7 --- /dev/null +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/IgnoreException.cs @@ -0,0 +1,55 @@ +#region License + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#endregion + +using System; + +namespace Gremlin.Net.IntegrationTest.Gherkin +{ + /// <summary> + /// Represents a test exception that should be ignored, given a reason (ie: feature not supported in the .NET GLV) + /// </summary> + public class IgnoreException : Exception + { + public IgnoreException(IgnoreReason reason) : base(GetMessage(reason)) + { + + } + + private static string GetMessage(IgnoreReason reason) + { + string reasonSuffix = null; + switch (reason) + { + case IgnoreReason.LambdaNotSupported: + reasonSuffix = " because lambdas are not supported in Gremlin.NET"; + break; + } + return $"Scenario ignored" + reasonSuffix; + } + } + + public enum IgnoreReason + { + LambdaNotSupported + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d58945d/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs ---------------------------------------------------------------------- diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs index f96b9bf..abc3f2b 100644 --- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs +++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Gherkin/TraversalEvaluation/ModernGraphTypeInformation.cs @@ -64,6 +64,7 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation case nameof(GraphTraversal<object,object>.Optional): case nameof(GraphTraversal<object,object>.Sum): case nameof(GraphTraversal<object,object>.Coalesce): + case nameof(GraphTraversal<object,object>.Match): // Maintain the same type return method.DeclaringType.GetGenericArguments()[1]; case nameof(GraphTraversal<object,object>.ValueMap): @@ -73,6 +74,14 @@ namespace Gremlin.Net.IntegrationTest.Gherkin.TraversalEvaluation case nameof(GraphTraversal<object,object>.Unfold): case nameof(GraphTraversal<object,object>.Choose): case nameof(GraphTraversal<object,object>.Union): + case nameof(GraphTraversal<object,object>.Project): + case nameof(GraphTraversal<object,object>.Sack): + case nameof(GraphTraversal<object,object>.Map): + case nameof(GraphTraversal<object,object>.Max): + case nameof(GraphTraversal<object,object>.Min): + case nameof(GraphTraversal<object,object>.Mean): + case nameof(GraphTraversal<object,object>.Cap): + case nameof(GraphTraversal<object,object>.Constant): // default to object for this methods return typeof(object); }