From 3ab6cd680a99daafb7c341bb25c07e5f34bf46fc Mon Sep 17 00:00:00 2001 From: Wil75 Date: Fri, 17 Feb 2017 20:13:26 +0100 Subject: [PATCH 1/7] Feature/add ignore tag (#433) * add .vs to gitignore * add IgnoreTag Feature * add ignoreTag parameter in any Runner * Fix after test with real case * Implement requests * Fix whitespace * Add properties and handling to model and viewmodel * Insert a row and move all rows down. * Add label and textbox for exclude tags * Reorganize UI * Rename Test Explude Tag "ignore-tag" to "exclude-tag" and add test for no sensitivity --- .gitignore | 1 + src/Pickles/Pickles.MSBuild/Pickles.cs | 7 + .../Pickles.ObjectModel/IConfiguration.cs | 2 + .../Pickles.PowerShell/Pickle_Features.cs | 8 + src/Pickles/Pickles.Test/BaseFixture.cs | 5 +- .../LevelOneIgnoredFeature.feature | 12 ++ src/Pickles/Pickles.Test/Pickles.Test.csproj | 1 + .../WhenParsingCommandLineArguments.cs | 13 ++ .../Pickles.Test/WhenParsingFeatureFiles.cs | 130 ++++++++++++- .../Pickles.UserInterface/MainWindow.xaml | 180 +++++++++--------- .../Settings/MainModel.cs | 3 + .../ViewModel/MainViewModel.cs | 15 +- .../Pickles/CommandLineArgumentParser.cs | 10 +- src/Pickles/Pickles/Configuration.cs | 2 + src/Pickles/Pickles/ConfigurationReporter.cs | 1 + .../DirectoryCrawler/DirectoryTreeCrawler.cs | 3 +- .../DirectoryCrawler/FeatureNodeFactory.cs | 7 +- src/Pickles/Pickles/FeatureParser.cs | 19 +- 18 files changed, 318 insertions(+), 101 deletions(-) create mode 100644 src/Pickles/Pickles.Test/FakeFolderStructures/FeatureCrawlerTests/LevelOneIgnoredFeature.feature diff --git a/.gitignore b/.gitignore index 58c1435cb..b7f412460 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.DS_Store #Visual Studio files +.vs *.[Oo]bj *.user *.aps diff --git a/src/Pickles/Pickles.MSBuild/Pickles.cs b/src/Pickles/Pickles.MSBuild/Pickles.cs index 9ecf759c7..9d84e6db4 100644 --- a/src/Pickles/Pickles.MSBuild/Pickles.cs +++ b/src/Pickles/Pickles.MSBuild/Pickles.cs @@ -51,6 +51,8 @@ public class Pickles : Task public string EnableComments { get; set; } + public string ExcludeTags { get; set; } + public override bool Execute() { try @@ -113,6 +115,11 @@ private void CaptureConfiguration(IConfiguration configuration, IFileSystem file { configuration.DocumentationFormat = (DocumentationFormat)Enum.Parse(typeof(DocumentationFormat), this.DocumentationFormat, true); } + + if (!string.IsNullOrEmpty(this.ExcludeTags)) + { + configuration.ExcludeTags = this.ExcludeTags; + } bool shouldEnableExperimentalFeatures; diff --git a/src/Pickles/Pickles.ObjectModel/IConfiguration.cs b/src/Pickles/Pickles.ObjectModel/IConfiguration.cs index 0269aeabe..b5ddad121 100644 --- a/src/Pickles/Pickles.ObjectModel/IConfiguration.cs +++ b/src/Pickles/Pickles.ObjectModel/IConfiguration.cs @@ -47,6 +47,8 @@ public interface IConfiguration bool ShouldIncludeExperimentalFeatures { get; } + string ExcludeTags { get; set; } + void AddTestResultFile(FileInfoBase fileInfoBase); void AddTestResultFiles(IEnumerable fileInfoBases); diff --git a/src/Pickles/Pickles.PowerShell/Pickle_Features.cs b/src/Pickles/Pickles.PowerShell/Pickle_Features.cs index 0e015b223..3cff7f96c 100644 --- a/src/Pickles/Pickles.PowerShell/Pickle_Features.cs +++ b/src/Pickles/Pickles.PowerShell/Pickle_Features.cs @@ -61,6 +61,9 @@ public class Pickle_Features : PSCmdlet [Parameter(HelpMessage = CommandLineArgumentParser.HelpEnableComments, Mandatory = false)] public string EnableComments { get; set; } + [Parameter(HelpMessage = CommandLineArgumentParser.HelpExcludeTags, Mandatory = false)] + public string ExcludeTags { get; set; } + protected override void ProcessRecord() { var builder = new ContainerBuilder(); @@ -120,6 +123,11 @@ private void ParseParameters(IConfiguration configuration, IFileSystem fileSyste configuration.EnableExperimentalFeatures(); } + if (!string.IsNullOrEmpty(this.ExcludeTags)) + { + configuration.ExcludeTags = this.ExcludeTags; + } + bool shouldEnableComments; if (bool.TryParse(this.EnableComments, out shouldEnableComments)) diff --git a/src/Pickles/Pickles.Test/BaseFixture.cs b/src/Pickles/Pickles.Test/BaseFixture.cs index 0997f899d..0c2e229cc 100644 --- a/src/Pickles/Pickles.Test/BaseFixture.cs +++ b/src/Pickles/Pickles.Test/BaseFixture.cs @@ -43,9 +43,12 @@ protected IContainer Container if (this.container == null) { var builder = new ContainerBuilder(); + + var configuration = new Configuration() { ExcludeTags = "exclude-tag" }; builder.RegisterAssemblyTypes(typeof(Runner).Assembly); builder.Register(_ => CreateMockFileSystem()).As().SingleInstance(); builder.RegisterModule(); + builder.RegisterInstance(configuration).As().SingleInstance(); this.container = builder.Build(); } @@ -88,7 +91,7 @@ protected void AddFakeFolderStructures() this.AddFakeFolderAndFiles("AcceptanceTest", new[] { "AdvancedFeature.feature", "LevelOne.feature" }); this.AddFakeFolderAndFiles("EmptyFolderTests", new string[0]); - this.AddFakeFolderAndFiles("FeatureCrawlerTests", new[] { "index.md", "LevelOne.feature", "image.png" }); + this.AddFakeFolderAndFiles("FeatureCrawlerTests", new[] { "index.md", "LevelOne.feature", "image.png", "LevelOneIgnoredFeature.feature" }); this.AddFakeFolderAndFiles(@"FeatureCrawlerTests\SubLevelOne", new[] { "ignorethisfile.ignore", "LevelOneSublevelOne.feature", "LevelOneSublevelTwo.feature" }); this.AddFakeFolderAndFiles(@"FeatureCrawlerTests\SubLevelOne\SubLevelTwo", new[] { "LevelOneSublevelOneSubLevelTwo.feature" }); this.AddFakeFolderAndFiles(@"FeatureCrawlerTests\SubLevelOne\SubLevelTwo\IgnoreThisDirectory", new[] { "IgnoreThisFile.ignore" }); diff --git a/src/Pickles/Pickles.Test/FakeFolderStructures/FeatureCrawlerTests/LevelOneIgnoredFeature.feature b/src/Pickles/Pickles.Test/FakeFolderStructures/FeatureCrawlerTests/LevelOneIgnoredFeature.feature new file mode 100644 index 000000000..1629558ed --- /dev/null +++ b/src/Pickles/Pickles.Test/FakeFolderStructures/FeatureCrawlerTests/LevelOneIgnoredFeature.feature @@ -0,0 +1,12 @@ +@exclude-tag +Feature: Addition + In order to avoid silly mistakes + As a math idiot + I want to be told the sum of two numbers + +@mytag +Scenario: Add two numbers + Given I have entered 50 into the calculator + And I have entered 70 into the calculator + When I press add + Then the result should be 120 on the screen diff --git a/src/Pickles/Pickles.Test/Pickles.Test.csproj b/src/Pickles/Pickles.Test/Pickles.Test.csproj index 41615292d..2e0914038 100644 --- a/src/Pickles/Pickles.Test/Pickles.Test.csproj +++ b/src/Pickles/Pickles.Test/Pickles.Test.csproj @@ -216,6 +216,7 @@ a-b.feature.cs + ResXFileCodeGenerator diff --git a/src/Pickles/Pickles.Test/WhenParsingCommandLineArguments.cs b/src/Pickles/Pickles.Test/WhenParsingCommandLineArguments.cs index 82530823a..c533a3e9d 100644 --- a/src/Pickles/Pickles.Test/WhenParsingCommandLineArguments.cs +++ b/src/Pickles/Pickles.Test/WhenParsingCommandLineArguments.cs @@ -487,5 +487,18 @@ public void ThenSetsLanguageToEnglishByDefault() Check.That(configuration.Language).IsEqualTo("en"); } + + [Test] + public void ThenCanParseExcludeTagsSuccessfully() + { + var args = new[] { @"-excludeTags=exclude-tag" }; + + var configuration = new Configuration(); + var commandLineArgumentParser = new CommandLineArgumentParser(FileSystem); + bool shouldContinue = commandLineArgumentParser.Parse(args, configuration, TextWriter.Null); + + Check.That(shouldContinue).IsTrue(); + Check.That(configuration.ExcludeTags).IsEqualTo("exclude-tag"); + } } } diff --git a/src/Pickles/Pickles.Test/WhenParsingFeatureFiles.cs b/src/Pickles/Pickles.Test/WhenParsingFeatureFiles.cs index 9f00d0e52..49cdc2262 100644 --- a/src/Pickles/Pickles.Test/WhenParsingFeatureFiles.cs +++ b/src/Pickles/Pickles.Test/WhenParsingFeatureFiles.cs @@ -18,10 +18,10 @@ // // -------------------------------------------------------------------------------------------------------------------- -using System; using System.Linq; using Autofac; +using DocumentFormat.OpenXml.Bibliography; using NFluent; using NUnit.Framework; using PicklesDoc.Pickles.Extensions; @@ -395,5 +395,133 @@ Then I should see that this thing happens } + + [Test] + public void Then_can_parse_and_ignore_feature_with_tag_in_configuration_ignore_tag() + { + var featureText = + @"# ignore this comment +@feature-tag @exclude-tag +Feature: Test + In order to do something + As a user + I want to run this scenario + + @scenario-tag-1 @scenario-tag-2 + Scenario: A scenario + Given some feature + When it runs + Then I should see that this thing happens"; + + var parser = Container.Resolve(); + var feature = parser.Parse(new StringReader(featureText)); + Check.That(feature).IsNull(); + } + + [Test] + public void Then_can_parse_and_ignore_scenario_with_tag_in_configuration_ignore_tag() + { + var featureText = + @"# ignore this comment +@feature-tag +Feature: Test + In order to do something + As a user + I want to run this scenario + + @scenario-tag-1 @scenario-tag-2 + Scenario: A scenario + Given some feature + When it runs + Then I should see that this thing happens + + @scenario-tag-1 @scenario-tag-2 @exclude-tag + Scenario: B scenario + Given some feature + When it runs + Then I should see that this thing happens + + @scenario-tag-1 @scenario-tag-2 + Scenario: C scenario + Given some feature + When it runs + Then I should see that this thing happens"; + + var parser = Container.Resolve(); + var feature = parser.Parse(new StringReader(featureText)); + + Check.That(feature.FeatureElements.Count).IsEqualTo(2); + Check.That(feature.FeatureElements.FirstOrDefault(fe => fe.Name == "A scenario")).IsNotNull(); + Check.That(feature.FeatureElements.FirstOrDefault(fe => fe.Name == "B scenario")).IsNull(); + Check.That(feature.FeatureElements.FirstOrDefault(fe => fe.Name == "C scenario")).IsNotNull(); + } + + [Test] + public void Then_can_parse_and_ignore_scenario_with_tag_in_configuration_ignore_tag_and_keep_feature() + { + var featureText = + @"# ignore this comment +@feature-tag +Feature: Test + In order to do something + As a user + I want to run this scenario + + @scenario-tag-1 @scenario-tag-2 @Exclude-Tag + Scenario: A scenario + Given some feature + When it runs + Then I should see that this thing happens + + @scenario-tag-1 @scenario-tag-2 @exclude-tag + Scenario: B scenario + Given some feature + When it runs + Then I should see that this thing happens"; + + var parser = Container.Resolve(); + var feature = parser.Parse(new StringReader(featureText)); + + Check.That(feature).IsNotNull(); + Check.That(feature.FeatureElements).IsEmpty(); + } + + [Test] + public void Then_can_parse_and_ignore_with_with_tag_without_sensitivity() + { + + var featureText = + @"# ignore this comment +@feature-tag +Feature: Test + In order to do something + As a user + I want to run this scenario + + @scenario-tag-1 @scenario-tag-2 @Exclude-Tag + Scenario: A scenario + Given some feature + When it runs + Then I should see that this thing happens + + @scenario-tag-1 @scenario-tag-2 @exclude-tag + Scenario: B scenario + Given some feature + When it runs + Then I should see that this thing happens + + @scenario-tag-1 @scenario-tag-2 @ExClUdE-tAg + Scenario: C scenario + Given some feature + When it runs + Then I should see that this thing happens"; + + var parser = Container.Resolve(); + var feature = parser.Parse(new StringReader(featureText)); + + Check.That(feature).IsNotNull(); + Check.That(feature.FeatureElements).IsEmpty(); + } } } + \ No newline at end of file diff --git a/src/Pickles/Pickles.UserInterface/MainWindow.xaml b/src/Pickles/Pickles.UserInterface/MainWindow.xaml index 8dd4b36f8..09b0bd769 100644 --- a/src/Pickles/Pickles.UserInterface/MainWindow.xaml +++ b/src/Pickles/Pickles.UserInterface/MainWindow.xaml @@ -3,117 +3,121 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mahapps="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" xmlns:nlogViewer="clr-namespace:NlogViewer;assembly=NlogViewer" - Title="Pickles" Height="700" Width="800" Loaded="MetroWindow_Loaded" Closed="MetroWindow_Closed" DataContextChanged="MainWindow_OnDataContextChanged" + Title="Pickles" Height="700" Width="1000" Loaded="MetroWindow_Loaded" Closed="MetroWindow_Closed" DataContextChanged="MainWindow_OnDataContextChanged" DataContext="{Binding Main, Source={StaticResource Locator}}" Icon="Pickles.ico"> - - - - - - - - - - + + + + - #CC2F8200 + + + + + + + #CC2F8200 - + - + - - - - - + + + + +