Skip to content

Commit

Permalink
Update solution to run on non-windows platform
Browse files Browse the repository at this point in the history
* Update tests to launch on non-windows platform

Update filesystem abstraction nuget package System.IO
Make related changes to tests: 
use IDirectoryInfo instead of DirectoryInfoBase, 
IFileSystemInfo instead of FileSystemInfoBase,
IFileInfo instead of FileInfoBase


Update DocumentFormat.OpenXML package, but still have xml-related error on MacOS during unit tests 
Use filesystem to build paths 
Do not use Windows-specific filepaths like "c:\file"
Use Environment.NewLine instead of \r\n

Update NFluent to compare strings thinking less of different line endings on different platforms

#609

* Update cucumber json report format to match official json schema

Produce test result value according to
https://github.com/cucumber/cucumber-json-schema

Update existing cucumber tests to run on non-windows platform
#609

* Add feature uri to cucumer json report

Add feature base uri parameter to command line

* Add feature and step id, hidden field to Cucumber json report

* Make Pickles.CommandLine packable as dotnet tool

Update csproj to not use deprecated fields
  • Loading branch information
Andrey Leskov authored Sep 22, 2021
1 parent 9a33c3f commit 83fb8f3
Show file tree
Hide file tree
Showing 80 changed files with 1,463 additions and 442 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ node_modules/
#include output docs
!docs/Output/
src/Pickles/.vs/config/applicationhost.config

nupkg*/
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
<ProjectReference Include="..\Pickles\Pickles.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NFluent" Version="2.2.0" />
<PackageReference Include="NFluent" Version="2.7.2" />
<PackageReference Include="NUnit" Version="3.13.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="2.1.0.178" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="13.2.47" />
</ItemGroup>
</Project>

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/Pickles/Pickles.CommandLine/CommandLineArgumentParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class CommandLineArgumentParser
private string enableCommentsValue;
private string excludeTags;
private string hideTags;
private string featureBaseUri;

public CommandLineArgumentParser(IFileSystem fileSystem)
{
Expand All @@ -65,7 +66,9 @@ public CommandLineArgumentParser(IFileSystem fileSystem)
{ "exp|include-experimental-features", CommandLineArgumentHelpTexts.HelpIncludeExperimentalFeatures, v => this.includeExperimentalFeatures = v != null },
{ "cmt|enableComments=", CommandLineArgumentHelpTexts.HelpEnableComments, v => this.enableCommentsValue = v },
{ "et|excludeTags=", CommandLineArgumentHelpTexts.HelpExcludeTags, v => this.excludeTags = v },
{ "ht|hideTags=", CommandLineArgumentHelpTexts.HelpHideTags, v => this.hideTags = v }
{ "ht|hideTags=", CommandLineArgumentHelpTexts.HelpHideTags, v => this.hideTags = v },
{ "fbu|feature-base-uri=", CommandLineArgumentHelpTexts.HelpFeatureBaseUri, v => this.featureBaseUri = v },

};
}

Expand Down Expand Up @@ -154,6 +157,18 @@ public bool Parse(string[] args, IConfiguration configuration, TextWriter stdout
configuration.DisableComments();
}

if (!string.IsNullOrEmpty(this.featureBaseUri))
{
if (Uri.TryCreate(this.featureBaseUri, UriKind.RelativeOrAbsolute, out var uri))
{
configuration.FeatureBaseUri = uri;
}
else
{
stdout.WriteLine("Failed to parse features base uri");
}
}

return true;
}

Expand Down
10 changes: 7 additions & 3 deletions src/Pickles/Pickles.CommandLine/Pickles.CommandLine.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProductVersion>8.0.30703</ProductVersion>
<OutputType>Exe</OutputType>
Expand Down Expand Up @@ -34,9 +34,9 @@
<Version>0.1.0.0</Version>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Authors>PicklesDoc and contributors</Authors>
<PackageIconUrl>https://cdn.rawgit.com/picklesdoc/pickles/master/pickles.png</PackageIconUrl>
<IconUrl>https://cdn.rawgit.com/picklesdoc/pickles/master/pickles.png</IconUrl>
<PackageId>Pickles.CommandLine</PackageId>
<PackageLicenseUrl>http://apache.org/licenses/LICENSE-2.0.html</PackageLicenseUrl>
<PackageLicense>http://apache.org/licenses/LICENSE-2.0.html</PackageLicense>
<PackageProjectUrl>http://www.picklesdoc.com/</PackageProjectUrl>
<PackageReleaseNotes>https://github.com/picklesdoc/pickles/blob/master/CHANGELOG.md</PackageReleaseNotes>
<PackageTags>SpecificationByExample BDD SpecFlow Gherkin Cucumber SpecByEx LivingDocumentation Documentation</PackageTags>
Expand All @@ -45,6 +45,10 @@
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<RepositoryUrl>https://github.com/picklesdoc/pickles</RepositoryUrl>
<PackAsTool>true</PackAsTool>
<ToolCommandName>pickles</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>



<specFlow>

<unitTestProvider name="NUnit" />

</specFlow>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /></startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StepDefinitions.cs" company="PicklesDoc">
// Copyright 2017 Dmitry Grekov
// Copyright 2012-present PicklesDoc team and community contributors
Expand Down Expand Up @@ -29,9 +29,12 @@
using PicklesDoc.Pickles.DataStructures;
using PicklesDoc.Pickles;
using System.IO;
using System.IO.Abstractions;
using PicklesDoc.Pickles.DirectoryCrawler;
using Autofac;
using NFluent;
using PicklesDoc.Pickles.DocumentationBuilders.Html;
using PicklesDoc.Pickles.Extensions;

namespace Pickles.DocumentationBuilders.Cucumber.UnitTests.AutomationLayer
{
Expand All @@ -41,22 +44,47 @@ public sealed class StepDefinitions : BaseFixture /* God object antipattern */
{
private Tree nodes;

[Given(@"I have this feature description placed in a folder '(.*)' in a file '(.*)'")]
public void GivenIHaveThisFeatureDescriptionPlacedInAFolder(string featureFolder, string featureFile, string multilineText)
{
var directoryInfo = FileSystem.DirectoryInfo.FromDirectoryName(featureFolder);
directoryInfo.Create();
var fileName = FileSystem.Path.Combine(featureFolder,featureFile);
var fileInfo = FileSystem.FileInfo.FromFileName(fileName);
using var writer = fileInfo.CreateText();
{
writer.Write(multilineText);
writer.Close();
}

var relevantFileDetector = new RelevantFileDetector();
var featureNodeFactory = new FeatureNodeFactory(relevantFileDetector,
new FileSystemBasedFeatureParser(new FeatureParser(Configuration), FileSystem),
new HtmlMarkdownFormatter(new MarkdownProvider()),
FileSystem);

var crawler = new DirectoryTreeCrawler(relevantFileDetector,
featureNodeFactory,
FileSystem);
this.nodes =
crawler.Crawl(FileSystem.DirectoryInfo.FromDirectoryName(FileSystem.Directory.GetCurrentDirectory()),
new ParsingReport());
}
[Given("I have this feature description")]
public void IHaveThisFeatureDescription(string featureDescription)
{
var configuration = this.Configuration;
FeatureParser parser = new FeatureParser(configuration);
FeatureParser parser = new FeatureParser(Configuration);

var feature = parser.Parse(new StringReader(featureDescription));

this.nodes = new Tree(new FeatureNode(this.FileSystem.DirectoryInfo.FromDirectoryName(@"c:\output\"), string.Empty, feature));
this.nodes = new Tree(new FeatureNode(this.FileSystem.DirectoryInfo.FromDirectoryName(@"output"), string.Empty, feature));
}

[When(@"I generate the documentation")]
public void WhenIGenerateTheJsonDocumentation()
{
var configuration = this.Configuration;
configuration.OutputFolder = this.FileSystem.DirectoryInfo.FromDirectoryName(@"c:\output\");
configuration.OutputFolder = this.FileSystem.GetOrCreateDirectory("output");
var jsonDocumentationBuilder = this.Container.Resolve<CucumberDocumentationBuilder>();

jsonDocumentationBuilder.Build(this.nodes);
Expand All @@ -65,12 +93,15 @@ public void WhenIGenerateTheJsonDocumentation()
[Then("the JSON file should contain")]
public void ThenTheResultShouldBe(string expectedResult)
{
var actualResult = this.FileSystem.File.ReadAllText(@"c:\output\cucumberResult.json");
var actualResult = this.FileSystem.File.ReadAllText(FileSystem.Path.Combine("output","cucumberResult.json"));

//standardize newlines across various environments
actualResult = actualResult.Replace("\r\n", "\n");
expectedResult = expectedResult.Replace("\r\n", "\n");
Check.That(actualResult).Contains(expectedResult);
}

[Given(@"feature base uri is provided from configuration as '(.*)'")]
public void GivenFeatureBaseUriIsProvidedFromConfigurationAs(string uriString)
{
Configuration.FeatureBaseUri = new Uri(uriString, UriKind.RelativeOrAbsolute);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CucumberDocumentationBuilderTests.cs" company="PicklesDoc">
// Copyright 2011 Jeffrey Cameron
// Copyright 2012-present PicklesDoc team and community contributors
//
//
// Licensed 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.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.IO;
using System.IO.Abstractions;
using System.IO.Abstractions.TestingHelpers;
using System.Reflection;
using NUnit.Framework;
using PicklesDoc.Pickles.DataStructures;
using PicklesDoc.Pickles.DirectoryCrawler;

namespace PicklesDoc.Pickles.DocumentationBuilders.Cucumber.UnitTests
{
[TestFixture]
public class CucumberDocumentationBuilderTests
{
[Test]
public void GIVEN_MacOS_test_When_create_document_Then_there_is_no_error()
{
var featureDescription =
@"Feature: Clearing Screen
In order to restart a new set of calculations
As a math idiot
I want to be able to clear the screen
@workflow @slow
Scenario: Clear the screen
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press C
Then the screen should be empty
";

var fileSystem = new FileSystem();
fileSystem.Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
var IFileSystemInfo = fileSystem.DirectoryInfo.FromDirectoryName(@"./");
var configuration = new Configuration
{
OutputFolder = IFileSystemInfo
};
var builder = new CucumberDocumentationBuilder(configuration, fileSystem);
FeatureParser parser = new FeatureParser(configuration);
var feature = parser.Parse(new StringReader(featureDescription));
var tree = new Tree(new FeatureNode(IFileSystemInfo, string.Empty, feature));
builder.Build(tree);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
Feature: Setting uri for aFeature in a folder

@cucumber
Scenario: A simple feature in a folder without base uri set
Given I have this feature description placed in a folder 'FeatureTest' in a file 'SettingUriForAFeature.feature'
"""
Feature: Clearing Screen
Scenario: Clear the screen
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press C
Then the screen should be empty
"""
When I generate the documentation
Then the JSON file should contain
"""
"uri": "FeatureTest/SettingUriForAFeature.feature"
"""

@cucumber
Scenario: A simple feature in a folder with file base uri

Given I have this feature description placed in a folder 'FeatureTest' in a file 'SettingUriForAFeature.feature'
"""
Feature: Clearing Screen
Scenario: Clear the screen
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press C
Then the screen should be empty
"""
And feature base uri is provided from configuration as 'test'
When I generate the documentation
Then the JSON file should contain
"""
"uri": "test/FeatureTest/SettingUriForAFeature.feature"
"""
@cucumber
Scenario: A simple feature in a folder with folder base uri
Given I have this feature description placed in a folder 'FeatureTest' in a file 'SettingUriForAFeature.feature'
"""
Feature: Clearing Screen
Scenario: Clear the screen
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press C
Then the screen should be empty
"""
And feature base uri is provided from configuration as 'root/test/'
When I generate the documentation
Then the JSON file should contain
"""
"uri": "root/test/FeatureTest/SettingUriForAFeature.feature"
"""

@cucumber
Scenario: A simple feature in a folder with an absolute base uri
Given I have this feature description placed in a folder 'FeatureTest' in a file 'SettingUriForAFeature.feature'
"""
Feature: Clearing Screen
Scenario: Clear the screen
Given I have entered 50 into the calculator
And I have entered 70 into the calculator
When I press C
Then the screen should be empty
"""
And feature base uri is provided from configuration as 'http://root/test/'
When I generate the documentation
Then the JSON file should contain
"""
"uri": "http://root/test/FeatureTest/SettingUriForAFeature.feature"
"""
Loading

0 comments on commit 83fb8f3

Please sign in to comment.