-
Notifications
You must be signed in to change notification settings - Fork 164
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
Exclude Feature or Scenario by Tag #433
Changes from 4 commits
53287e6
f9b6df3
674ecba
8d1f094
43fccc4
061344e
183dff4
f804af3
c15dca1
fc22400
d1265e4
bd49c1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
*.DS_Store | ||
|
||
#Visual Studio files | ||
.vs | ||
*.[Oo]bj | ||
*.user | ||
*.aps | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -487,5 +487,19 @@ public void ThenSetsLanguageToEnglishByDefault() | |
|
||
Check.That(configuration.Language).IsEqualTo("en"); | ||
} | ||
|
||
[Test] | ||
public void ThenCanParseIgnoreTagSuccessfully() | ||
{ | ||
var ignoreTag = "ignore-tag"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy that you include tests on your own initiative. I'm also happy about the style. One detail I'd like you to change: I prefer Roy Osherhove's unit testing style of making values explicit and not using parameters. So instead of (for example) The reason is that the second style makes the test easier to read: I instantly know what value we are talking about, and I don't need to check the value of some variable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As you prefer, it's also ok for us |
||
var args = new[] { $@"-ignoreTag={ignoreTag}" }; | ||
|
||
var configuration = new Configuration(); | ||
var commandLineArgumentParser = new CommandLineArgumentParser(FileSystem); | ||
bool shouldContinue = commandLineArgumentParser.Parse(args, configuration, TextWriter.Null); | ||
|
||
Check.That(shouldContinue).IsTrue(); | ||
Check.That(configuration.IgnoreTag).IsEqualTo(ignoreTag); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ 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 HelpIgnoreTag = "tag used for ignore feature or scenario"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use this text: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, done |
||
|
||
public const string HelpTestResultsFile = | ||
"the path to the linked test results file (can be a semicolon-separated list of files)"; | ||
|
@@ -58,6 +59,7 @@ public class CommandLineArgumentParser | |
private bool versionRequested; | ||
private bool includeExperimentalFeatures; | ||
private string enableCommentsValue; | ||
private string ignoreTag; | ||
|
||
public CommandLineArgumentParser(IFileSystem fileSystem) | ||
{ | ||
|
@@ -75,7 +77,8 @@ public CommandLineArgumentParser(IFileSystem fileSystem) | |
{ "v|version", v => this.versionRequested = v != null }, | ||
{ "h|?|help", v => this.helpRequested = v != null }, | ||
{ "exp|include-experimental-features", HelpIncludeExperimentalFeatures, v => this.includeExperimentalFeatures = v != null }, | ||
{ "cmt|enableComments=", HelpEnableComments, v => this.enableCommentsValue = v } | ||
{ "cmt|enableComments=", HelpEnableComments, v => this.enableCommentsValue = v }, | ||
{ "it|ignoreTag=", HelpIgnoreTag, v => this.ignoreTag = v } | ||
}; | ||
} | ||
|
||
|
@@ -148,6 +151,11 @@ public bool Parse(string[] args, IConfiguration configuration, TextWriter stdout | |
configuration.EnableExperimentalFeatures(); | ||
} | ||
|
||
if (!string.IsNullOrEmpty(this.ignoreTag)) | ||
{ | ||
configuration.IgnoreTag = this.ignoreTag; | ||
} | ||
|
||
bool enableComments; | ||
|
||
if (bool.TryParse(this.enableCommentsValue, out enableComments) && enableComments == false) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,8 @@ private bool CollectFiles(DirectoryInfoBase directory, INode rootNode, Tree tree | |
foreach (FileInfoBase file in directory.GetFiles().Where(file => this.relevantFileDetector.IsRelevant(file))) | ||
{ | ||
INode node = this.featureNodeFactory.Create(rootNode.OriginalLocation, file); | ||
collectedNodes.Add(node); | ||
if(node != null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to create a unit test that shows the need for this check? |
||
collectedNodes.Add(node); | ||
} | ||
|
||
foreach (var node in OrderFileNodes(collectedNodes)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
using System.Xml.Linq; | ||
|
||
using PicklesDoc.Pickles.DocumentationBuilders.Html; | ||
using PicklesDoc.Pickles.DocumentationBuilders.Word.TableOfContentsAdder; | ||
using PicklesDoc.Pickles.Extensions; | ||
using PicklesDoc.Pickles.ObjectModel; | ||
|
||
|
@@ -57,12 +58,7 @@ public INode Create(FileSystemInfoBase root, FileSystemInfoBase location) | |
if (this.relevantFileDetector.IsFeatureFile(file)) | ||
{ | ||
Feature feature = this.featureParser.Parse(file.FullName); | ||
if (feature != null) | ||
{ | ||
return new FeatureNode(file, relativePathFromRoot, feature); | ||
} | ||
|
||
throw new InvalidOperationException("This feature file could not be read and will be excluded"); | ||
return feature != null ? new FeatureNode(file, relativePathFromRoot, feature) : null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you remove the invalidoperationexception? I know that a feature can be null if it's excluded by the tags, but malformed files will fail silently now ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you prefer a default value check for preserve the InvalidOperationException ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think I do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, i do that. If feature is excluded i return default value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, but default value check is not the solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right ... let's keep your version. |
||
} | ||
else if (this.relevantFileDetector.IsMarkdownFile(file)) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ | |
|
||
using System; | ||
using System.IO.Abstractions; | ||
|
||
using System.Linq; | ||
using PicklesDoc.Pickles.ObjectModel; | ||
|
||
using TextReader = System.IO.TextReader; | ||
|
@@ -74,8 +74,10 @@ public Feature Parse(TextReader featureFileReader) | |
new Gherkin.TokenMatcher(new CultureAwareDialectProvider(language))); | ||
|
||
Feature result = new Mapper(this.configuration, gherkinDocument.Feature.Language).MapToFeature(gherkinDocument); | ||
result = this.RemoveFeatureWithIgnoreTag(result); | ||
|
||
this.descriptionProcessor.Process(result); | ||
if (result != null) | ||
this.descriptionProcessor.Process(result); | ||
|
||
return result; | ||
} | ||
|
@@ -90,5 +92,18 @@ private string DetermineLanguage() | |
} | ||
return language; | ||
} | ||
|
||
private Feature RemoveFeatureWithIgnoreTag(Feature result) | ||
{ | ||
if (result.Tags.Any(t => t == $"@{configuration.IgnoreTag}")) | ||
return null; | ||
|
||
var wantedFeatures = result.FeatureElements.Where(fe => fe.Tags.All(t => t != $"@{configuration.IgnoreTag}")).ToList(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the tag exclusion case sensitive. Do we want that? I'm not sure ... what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want or want that, we can check the tag without sensitivity. |
||
|
||
result.FeatureElements.Clear(); | ||
result.FeatureElements.AddRange(wantedFeatures); | ||
|
||
return result; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of the intent of the API, I think that "ExcludeTags" is a better name for the property. Right now we support only one tag but I still want to call the property with the plural "Tags" to ensure forward compatibility.
Please rename the property to ExcludeTags (and adapt the rest of the code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done