Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExcludeTags is a list of tags to exclude + StopOnParsingError option #441

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Pickles/Pickles.MSBuild/Pickles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Reflection;
using Autofac;
Expand Down Expand Up @@ -55,6 +56,8 @@ public class Pickles : Task

public string ExcludeTags { get; set; }

public string StopOnParsingError { get; set; }

public override bool Execute()
{
try
Expand Down Expand Up @@ -121,7 +124,17 @@ private void CaptureConfiguration(IConfiguration configuration, IFileSystem file

if (!string.IsNullOrEmpty(this.ExcludeTags))
{
configuration.ExcludeTags = this.ExcludeTags;
configuration.ExcludeTags = new List<string>(this.ExcludeTags.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries));
for (int i = 0; i < configuration.ExcludeTags.Count; i++)
{
if (configuration.ExcludeTags[i][0] != '@')
configuration.ExcludeTags[i] = configuration.ExcludeTags[i].Insert(0, "@");
}
}

if (!string.IsNullOrEmpty(this.StopOnParsingError))
{
configuration.StopOnParsingError = string.Equals(this.StopOnParsingError, "true", StringComparison.OrdinalIgnoreCase);
}

bool shouldEnableExperimentalFeatures;
Expand Down
4 changes: 3 additions & 1 deletion src/Pickles/Pickles.MSBuild/build/Pickles.MSBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
DocumentationFormat="$(Pickles_DocumentationFormat)"
Language="$(Pickles_Language)"
IncludeExperimentalFeatures="$(Pickles_IncludeExperimentalFeatures)"
EnableComments="$(Pickles_EnableComments)" />
EnableComments="$(Pickles_EnableComments)"
ExcludeTags="$(Pickles_ExcludeTags"
StopOnParsingError="$(Pickles_StopOnParsingError"/>
</Target>
</Project>
4 changes: 3 additions & 1 deletion src/Pickles/Pickles.ObjectModel/IConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public interface IConfiguration

bool ShouldIncludeExperimentalFeatures { get; }

string ExcludeTags { get; set; }
List<string> ExcludeTags { get; set; }

bool StopOnParsingError { get; set; }

void AddTestResultFile(FileInfoBase fileInfoBase);

Expand Down
16 changes: 15 additions & 1 deletion src/Pickles/Pickles.PowerShell/Pickle_Features.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#if __MonoCS__
#else
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Management.Automation;
using System.Reflection;
Expand Down Expand Up @@ -66,6 +67,9 @@ public class Pickle_Features : PSCmdlet
[Parameter(HelpMessage = CommandLineArgumentParser.HelpExcludeTags, Mandatory = false)]
public string ExcludeTags { get; set; }

[Parameter(HelpMessage = CommandLineArgumentParser.HelpStopOnParsingError, Mandatory = false)]
public string StopOnParsingError { get; set; }

protected override void ProcessRecord()
{
var builder = new ContainerBuilder();
Expand Down Expand Up @@ -128,7 +132,17 @@ private void ParseParameters(IConfiguration configuration, IFileSystem fileSyste

if (!string.IsNullOrEmpty(this.ExcludeTags))
{
configuration.ExcludeTags = this.ExcludeTags;
configuration.ExcludeTags = new List<string>(this.ExcludeTags.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries));
for (int i = 0; i < configuration.ExcludeTags.Count; i++)
{
if (configuration.ExcludeTags[i][0] != '@')
configuration.ExcludeTags[i] = configuration.ExcludeTags[i].Insert(0, "@");
}
}

if (!string.IsNullOrEmpty(this.StopOnParsingError))
{
configuration.StopOnParsingError = string.Equals(this.StopOnParsingError, "true", StringComparison.OrdinalIgnoreCase);
}

bool shouldEnableComments;
Expand Down
2 changes: 1 addition & 1 deletion src/Pickles/Pickles.Test/BaseFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected IContainer Container
{
var builder = new ContainerBuilder();

var configuration = new Configuration() { ExcludeTags = "exclude-tag" };
var configuration = new Configuration() { ExcludeTags = new List<string>(new []{"@exclude-tag"}) };
builder.RegisterAssemblyTypes(typeof(Runner).Assembly);
builder.Register<MockFileSystem>(_ => CreateMockFileSystem()).As<IFileSystem>().SingleInstance();
builder.RegisterModule<PicklesModule>();
Expand Down
5 changes: 3 additions & 2 deletions src/Pickles/Pickles.Test/WhenParsingCommandLineArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -601,14 +601,15 @@ public void ThenSetsLanguageToEnglishByDefault()
[Test]
public void ThenCanParseExcludeTagsSuccessfully()
{
var args = new[] { @"-excludeTags=exclude-tag" };
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");
Check.That(configuration.ExcludeTags.Count).IsEqualTo(1);
Check.That(configuration.ExcludeTags[0]).IsEqualTo("@exclude-tag");
}
}
}
10 changes: 7 additions & 3 deletions src/Pickles/Pickles.UserInterface/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
Expand All @@ -71,7 +72,7 @@
<CheckBox Template="{StaticResource ResourceKey=myCheckBox}" Grid.Column="3" Grid.Row="2" IsChecked="{Binding Path=IsOutputDirectoryValid}" IsEnabled="False" VerticalAlignment="Top"/>

<Label Content="Exclude Tags" Grid.Column="0" Grid.Row="3" VerticalAlignment="Top" />
<TextBox Text="{Binding ExcludeTags}" Grid.Column="1" Grid.Row="3" mahapps:TextBoxHelper.Watermark="Exclude scenarios that match this tag" VerticalAlignment="Top" />
<TextBox Text="{Binding ExcludeTags}" Grid.Column="1" Grid.Row="3" mahapps:TextBoxHelper.Watermark="Exclude scenarios that match at least one tag into tags" VerticalAlignment="Top" />

<mahapps:ToggleSwitch Header="Create Directory For Each Output Format" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" IsChecked="{Binding Path=CreateDirectoryForEachOutputFormat, Mode=TwoWay}" Margin="0,0,0,5" />

Expand Down Expand Up @@ -113,11 +114,14 @@
<ComboBox ItemsSource="{Binding LanguageValues}" Grid.Column="1" SelectedItem="{Binding SelectedLanguage}" Grid.Row="10" Grid.ColumnSpan="2" DisplayMemberPath="NativeName" VerticalAlignment="Top"/>
<CheckBox Template="{StaticResource ResourceKey=myCheckBox}" Grid.Column="3" Grid.Row="10" IsChecked="{Binding Path=IsLanguageValid}" IsEnabled="False" VerticalAlignment="Top"/>

<Label Content="Stop on parser error" Grid.Column="0" Grid.Row="11" VerticalAlignment="Top" />
<mahapps:ToggleSwitch Header="Stop on parser error" Grid.Row="11" Grid.Column="1" Grid.ColumnSpan="2" IsChecked="{Binding Path=StopOnParsingError, Mode=TwoWay}" Margin="0,0,0,5" />

<mahapps:ToggleSwitch Header="Enable Comments" Grid.Row="1" Grid.RowSpan="2" Grid.Column="5" Grid.ColumnSpan="1" IsChecked="{Binding Path=EnableComments, Mode=TwoWay}" Margin="5,0,0,5" />
<mahapps:ToggleSwitch Header="Include Experimental Features" Grid.RowSpan="2" Grid.Row="3" Grid.Column="5" Grid.ColumnSpan="1" IsChecked="{Binding Path=IncludeExperimentalFeatures, Mode=TwoWay}" Margin="5,0,0,5" />

<Button Command="{Binding GeneratePickles}" Content="Generate" Grid.Row="11" Grid.Column="4" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="24" Padding="15" Grid.ColumnSpan="2" Margin="0,0,20,20" />
<nlogViewer:NlogViewer x:Name="logCtrl" Grid.Column="0" Grid.ColumnSpan="6" Grid.Row="12
<Button Command="{Binding GeneratePickles}" Content="Generate" Grid.Row="12" Grid.Column="4" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="24" Padding="15" Grid.ColumnSpan="2" Margin="0,0,20,20" />
<nlogViewer:NlogViewer x:Name="logCtrl" Grid.Column="0" Grid.ColumnSpan="6" Grid.Row="13
" LevelWidth="auto" ExceptionWidth="auto" MessageWidth="auto" />
</Grid>
</mahapps:MetroWindow>
3 changes: 3 additions & 0 deletions src/Pickles/Pickles.UserInterface/Settings/MainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@ public class MainModel

[DataMember(Name = "excludeTags", IsRequired = false)]
public string ExcludeTags { get; set; }

[DataMember(Name = "stopOnParsingError", IsRequired = false)]
public bool StopOnParsingError { get; set; }
}
}
40 changes: 36 additions & 4 deletions src/Pickles/Pickles.UserInterface/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
using System.Globalization;
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;
using System.Windows.Input;

using Autofac;

using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using NLog;
using PicklesDoc.Pickles.ObjectModel;
using PicklesDoc.Pickles.UserInterface.Mvvm;
using PicklesDoc.Pickles.UserInterface.Settings;
Expand All @@ -51,6 +53,8 @@ namespace PicklesDoc.Pickles.UserInterface.ViewModel
/// </summary>
public class MainViewModel : ViewModelBase
{
private static readonly Logger Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.Name);

private readonly MultiSelectableCollection<DocumentationFormat> documentationFormats;

private readonly TestResultsFormat[] testResultsFormats;
Expand Down Expand Up @@ -89,6 +93,8 @@ public class MainViewModel : ViewModelBase

private string excludeTags;

private bool stopOnParsingError;

private bool isRunning;

private bool isFeatureDirectoryValid;
Expand Down Expand Up @@ -217,6 +223,13 @@ public string ExcludeTags
set { this.Set(nameof(this.ExcludeTags), ref this.excludeTags, value); }
}

public bool StopOnParsingError
{
get { return this.stopOnParsingError; }

set { this.Set(nameof(this.StopOnParsingError), ref this.stopOnParsingError, value); }
}

public ICommand GeneratePickles
{
get { return this.generateCommand; }
Expand Down Expand Up @@ -333,7 +346,8 @@ public void SaveToSettings()
CreateDirectoryForEachOutputFormat = this.createDirectoryForEachOutputFormat,
IncludeExperimentalFeatures = this.includeExperimentalFeatures,
EnableComments = this.enableComments,
ExcludeTags = this.excludeTags
ExcludeTags = this.excludeTags,
StopOnParsingError = this.stopOnParsingError
};

this.mainModelSerializer.Write(mainModel);
Expand Down Expand Up @@ -370,6 +384,7 @@ public void LoadFromSettings()
this.IncludeExperimentalFeatures = mainModel.IncludeExperimentalFeatures;
this.EnableComments = mainModel.EnableComments;
this.ExcludeTags = mainModel.ExcludeTags;
this.StopOnParsingError = mainModel.StopOnParsingError;
}

private void DocumentationFormatsOnCollectionChanged(object sender, EventArgs notifyCollectionChangedEventArgs)
Expand Down Expand Up @@ -527,7 +542,17 @@ private void DoWork()

configuration.DocumentationFormat = documentationFormat;

configuration.ExcludeTags = this.ExcludeTags;
configuration.ExcludeTags = new List<string>(this.ExcludeTags.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries));
for (int i = 0; i < configuration.ExcludeTags.Count; i++)
{
if (configuration.ExcludeTags[i][0] != '@')
configuration.ExcludeTags[i] = configuration.ExcludeTags[i].Insert(0, "@");
}

if (this.StopOnParsingError)
{
configuration.StopOnParsingError = this.StopOnParsingError;
}

if (this.includeExperimentalFeatures)
{
Expand All @@ -547,8 +572,15 @@ private void DoWork()
configuration.DisableComments();
}

var runner = container.Resolve<Runner>();
runner.Run(container);
try
{
var runner = container.Resolve<Runner>();
runner.Run(container);
}
catch (Exception e)
{
Log.Error(e.Message);
}
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/Pickles/Pickles/CommandLineArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;
Expand All @@ -41,7 +42,8 @@ public class CommandLineArgumentParser
public const string HelpTestResultsFormat = "the format of the linked test results (nunit|nunit3|xunit|xunit2|mstest |cucumberjson|specrun|vstest)";
public const string HelpIncludeExperimentalFeatures = "whether to include experimental features";
public const string HelpEnableComments = "whether to enable comments in the output";
public const string HelpExcludeTags = "exclude scenarios that match this tag";
public const string HelpExcludeTags = "exclude scenarios that match at least one tag into tags. Tags can be space (' ') or colon (',') separated list of tags";
public const string HelpStopOnParsingError = "stop on error feature file. default is skipping (false)";

public const string HelpTestResultsFile =
"the path to the linked test results file (can be a semicolon-separated list of files)";
Expand All @@ -61,6 +63,7 @@ public class CommandLineArgumentParser
private bool includeExperimentalFeatures;
private string enableCommentsValue;
private string excludeTags;
private bool stopOnParsingError = false;

public CommandLineArgumentParser(IFileSystem fileSystem)
{
Expand All @@ -79,7 +82,8 @@ public CommandLineArgumentParser(IFileSystem fileSystem)
{ "h|?|help", v => this.helpRequested = v != null },
{ "exp|include-experimental-features", HelpIncludeExperimentalFeatures, v => this.includeExperimentalFeatures = v != null },
{ "cmt|enableComments=", HelpEnableComments, v => this.enableCommentsValue = v },
{ "et|excludeTags=", HelpExcludeTags, v => this.excludeTags = v }
{ "et|excludeTags=", HelpExcludeTags, v => this.excludeTags = v },
{ "st|stopOnParsingError=", HelpStopOnParsingError, v => this.stopOnParsingError = string.Equals(v,"true", StringComparison.OrdinalIgnoreCase) }
};
}

Expand Down Expand Up @@ -153,9 +157,16 @@ public bool Parse(string[] args, IConfiguration configuration, TextWriter stdout

if (!string.IsNullOrEmpty(this.excludeTags))
{
configuration.ExcludeTags = this.excludeTags;
configuration.ExcludeTags = new List<string>(this.excludeTags.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries));
for (int i = 0; i < configuration.ExcludeTags.Count; i++)
{
if (configuration.ExcludeTags[i][0] != '@')
configuration.ExcludeTags[i] = configuration.ExcludeTags[i].Insert(0, "@");
}
}

configuration.StopOnParsingError = this.stopOnParsingError;

bool enableComments;

if (bool.TryParse(this.enableCommentsValue, out enableComments) && enableComments == false)
Expand Down
5 changes: 4 additions & 1 deletion src/Pickles/Pickles/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ public void AddTestResultFiles(IEnumerable<FileInfoBase> fileInfoBases)
}
}

public string ExcludeTags { get; set; }
public List<string> ExcludeTags { get; set; } = new List<string>();

public bool StopOnParsingError { get; set; } = false;


private void AddTestResultFileIfItExists(FileInfoBase fileInfoBase)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Pickles/Pickles/ConfigurationReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void ReportOn(IConfiguration configuration, Action<string> writeToLog)
writeToLog($"Language : {configuration.Language}");
writeToLog($"Incorporate Test Results? : {(configuration.HasTestResults ? "Yes" : "No")}");
writeToLog($"Include Experimental Features? : {(configuration.ShouldIncludeExperimentalFeatures ? "Yes" : "No")}");
writeToLog($"Exclude Tag : {configuration.ExcludeTags}");
writeToLog($"Exclude Tag : {string.Join(" ", configuration.ExcludeTags) }");

if (configuration.HasTestResults)
{
Expand Down
15 changes: 11 additions & 4 deletions src/Pickles/Pickles/FeatureParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using System;
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;
using NLog;
using PicklesDoc.Pickles.ObjectModel;

using TextReader = System.IO.TextReader;
Expand All @@ -29,6 +31,8 @@ namespace PicklesDoc.Pickles
{
public class FeatureParser
{
private static readonly Logger Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType.Name);

private readonly IFileSystem fileSystem;

private readonly IConfiguration configuration;
Expand All @@ -54,8 +58,11 @@ public Feature Parse(string filename)
{
string message =
$"There was an error parsing the feature file here: {this.fileSystem.Path.GetFullPath(filename)}" + Environment.NewLine +
$"Errormessage was:'{e.Message}'";
throw new FeatureParseException(message, e);
$"Error message was:'{e.Message}'";
if (this.configuration.StopOnParsingError)
throw new FeatureParseException(message, e);
else
Log.Error(message);
}

reader.Close();
Expand Down Expand Up @@ -95,10 +102,10 @@ private string DetermineLanguage()

private Feature RemoveFeatureWithExcludeTags(Feature result)
{
if (result.Tags.Any(t => t.Equals($"@{configuration.ExcludeTags}", StringComparison.InvariantCultureIgnoreCase)))
if (result.Tags.Any(t => this.configuration.ExcludeTags.Any(s => s.Equals(t, StringComparison.InvariantCultureIgnoreCase))))
return null;

var wantedFeatures = result.FeatureElements.Where(fe => fe.Tags.All(t => !t.Equals($"@{configuration.ExcludeTags}", StringComparison.InvariantCultureIgnoreCase))).ToList();
var wantedFeatures = result.FeatureElements.Where(fe => fe.Tags.All(t => !this.configuration.ExcludeTags.Any(s => s.Equals(t, StringComparison.InvariantCultureIgnoreCase)))).ToList();

result.FeatureElements.Clear();
result.FeatureElements.AddRange(wantedFeatures);
Expand Down