Skip to content

Commit

Permalink
Added method to specify vague subdirectory matching
Browse files Browse the repository at this point in the history
  • Loading branch information
gubpalma committed Mar 28, 2024
1 parent 161cb83 commit 38e8637
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 27 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ You can install the `specflow-to-markdown` tool via the following .NET command
dotnet tool install -g Gman.SpecFlowToMarkdown
```
### Running the tool
The tool takes three arguments:
The tool takes five arguments:
```
specflow-to-markdown <PATH_TO_TEST_ASSEMBLY> <PATH_TO_TEST_RESULTS_FILE> <PATH_TO_OUTPUT_FILE>
specflow-to-markdown <PATH_TO_TEST_ASSEMBLY> <TEST_ASSEMBLY_FILE> <PATH_TO_TEST_RESULTS_FILE> <TEST_RESULTS_FILE> <PATH_TO_OUTPUT_FILE>
```
- `PATH_TO_TEST_ASSEMBLY` - this will be the location of the built .NET DLL containing the SpecFlow tests.
- `TEST_ASSEMBLY_FILE` - this will be the name of the assembly file. Supports wildcards.
- `PATH_TO_TEST_RESULTS_FILE` - this will be the location of the (JSON) test execution results file.
- `TEST_RESULTS_FILE` - this will be the name of the results file. Supports wildcards.
- `PATH_TO_OUTPUT_FILE` - this will be the path to the generated output file where the markdown should be generated; includes the full file name. The file _does not have to be a markdown_ (`.md`) file.
4 changes: 2 additions & 2 deletions src/6.0/SpecFlowToMarkdown.Application/SpecFlowApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public void Perform(string[] args)

var specFlowAssembly =
_assemblyScanner
.Perform(arguments.TestAssemblyPath);
.Perform(arguments);

var testResults =
_testExecutionParser
.Parse(arguments.TestResultsPath);
.Parse(arguments);

var markdown =
_markdownRenderer
Expand Down
14 changes: 10 additions & 4 deletions src/6.0/SpecFlowToMarkdown.Domain/ProgramArguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
{
public class ProgramArguments
{
public string TestAssemblyPath { get; set; }
public string TestAssemblyFolder { get; set; }

public string TestResultsPath { get; set; }
public string TestAssemblyFile { get; set; }

public string TestResultsFolder { get; set; }

public string TestResultsFile { get; set; }

public string OutputFilePath { get; set; }

public override string ToString()
{
return
$"TestAssemblyPath: '{TestAssemblyPath}'\r\n" +
$"TestResultsPath: '{TestResultsPath}'\r\n" +
$"TestAssemblyFolder: '{TestAssemblyFolder}'\r\n" +
$"TestAssemblyFile: '{TestAssemblyFile}'\r\n" +
$"TestResultsFolder: '{TestResultsFolder}'\r\n" +
$"TestResultsFile: '{TestResultsFile}'\r\n" +
$"OutputFilePath: '{OutputFilePath}'";
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
using Mono.Cecil;
using SpecFlowToMarkdown.Domain;
using SpecFlowToMarkdown.Domain.TestAssembly;
using SpecFlowToMarkdown.Infrastructure.AssemblyLoad.Extractors;
using SpecFlowToMarkdown.Infrastructure.Io;

namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad
{
public class AssemblyScanner : IAssemblyScanner
{
private readonly IFeatureExtractor _featureExtractor;
private readonly IFileFinder _fileFinder;

public AssemblyScanner(IFeatureExtractor featureExtractor)
public AssemblyScanner(
IFeatureExtractor featureExtractor,
IFileFinder fileFinder
)
{
_featureExtractor = featureExtractor;
_fileFinder = fileFinder;
}

public SpecFlowAssembly Perform(string assemblyPath)
public SpecFlowAssembly Perform(ProgramArguments arguments)
{
var foundFilePath =
_fileFinder
.GetFirstFound(
arguments.TestAssemblyFolder,
arguments.TestAssemblyFile
);

var assembly =
AssemblyDefinition
.ReadAssembly(assemblyPath);
.ReadAssembly(foundFilePath);

var result =
_featureExtractor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using SpecFlowToMarkdown.Domain.TestAssembly;
using SpecFlowToMarkdown.Domain;
using SpecFlowToMarkdown.Domain.TestAssembly;

namespace SpecFlowToMarkdown.Infrastructure.AssemblyLoad
{
public interface IAssemblyScanner
{
public SpecFlowAssembly Perform(string assemblyPath);
public SpecFlowAssembly Perform(ProgramArguments arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<ProjectReference Include="..\SpecFlowToMarkdown.Domain\SpecFlowToMarkdown.Domain.csproj"/>
<ProjectReference Include="..\SpecFlowToMarkdown.Infrastructure.Io\SpecFlowToMarkdown.Infrastructure.Io.csproj" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions src/6.0/SpecFlowToMarkdown.Infrastructure.Io/FileFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;

namespace SpecFlowToMarkdown.Infrastructure.Io
{
public class FileFinder : IFileFinder
{
private readonly ILogger<FileFinder> _logger;

public FileFinder(ILogger<FileFinder> logger)
{
_logger = logger;
}

public string GetFirstFound(string pathName, string fileName)
{
var foundFilePath =
Directory
.EnumerateFiles(
pathName,
fileName,
SearchOption.AllDirectories
)
.FirstOrDefault();

if (foundFilePath == null)
throw new Exception($"Could not find file matching path {pathName} and file {fileName}");

_logger
.LogInformation($"Found file path at {foundFilePath}");

return foundFilePath;
}
}
}
7 changes: 7 additions & 0 deletions src/6.0/SpecFlowToMarkdown.Infrastructure.Io/IFileFinder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SpecFlowToMarkdown.Infrastructure.Io
{
public interface IFileFinder
{
string GetFirstFound(string pathName, string fileName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,37 @@ public ProgramArgumentsParser(ILogger<ProgramArgumentsParser> logger)

public ProgramArguments Parse(string[] args)
{
if (args.Length < 3)
throw new Exception("Expected 3 arguments");
if (args.Length < 5)
throw new Exception("Expected 5 arguments");

var assemblyPath = args[0];
var executionResultsPath = args[1];
var outputPath = args[2];
var testAssemblyFolder = args[0];
var testAssemblyFile = args[1];
var testResultsFolder = args[2];
var testResultsFile = args[3];
var outputPath = args[4];

if (string.IsNullOrEmpty(assemblyPath))
if (string.IsNullOrEmpty(testAssemblyFolder))
throw new Exception("Assembly path argument invalid");

if (string.IsNullOrEmpty(executionResultsPath))
if (string.IsNullOrEmpty(testAssemblyFile))
throw new Exception("Assembly file argument invalid");

if (string.IsNullOrEmpty(testResultsFolder))
throw new Exception("Results path argument invalid");

if (string.IsNullOrEmpty(testResultsFile))
throw new Exception("Results file argument invalid");

if (string.IsNullOrEmpty(outputPath))
throw new Exception("Output path argument invalid");

var result = new ProgramArguments
{
TestAssemblyPath = args[0],
TestResultsPath = args[1],
OutputFilePath = args[2]
TestAssemblyFolder = testAssemblyFolder,
TestAssemblyFile = testAssemblyFile,
TestResultsFolder = testResultsFolder,
TestResultsFile = testResultsFile,
OutputFilePath = outputPath
};

_logger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using SpecFlowToMarkdown.Domain.Result;
using SpecFlowToMarkdown.Domain;
using SpecFlowToMarkdown.Domain.Result;

namespace SpecFlowToMarkdown.Infrastructure.Parsing.Results
{
public interface ITestExecutionParser
{
public TestExecution Parse(string executionResultsPath);
public TestExecution Parse(ProgramArguments arguments);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
using System.IO;
using Newtonsoft.Json;
using SpecFlowToMarkdown.Domain;
using SpecFlowToMarkdown.Domain.Result;
using SpecFlowToMarkdown.Infrastructure.Io;

namespace SpecFlowToMarkdown.Infrastructure.Parsing.Results
{
public class JsonTestExecutionParser : ITestExecutionParser
{
public TestExecution Parse(string executionResultsPath)
private readonly IFileFinder _fileFinder;

public JsonTestExecutionParser(IFileFinder fileFinder)
{
_fileFinder = fileFinder;
}

public TestExecution Parse(ProgramArguments arguments)
{
var foundFilePath =
_fileFinder
.GetFirstFound(
arguments.TestResultsFolder,
arguments.TestResultsFile
);

var jsonString =
File
.ReadAllText(executionResultsPath);
.ReadAllText(foundFilePath);

var result =
JsonConvert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<ProjectReference Include="..\SpecFlowToMarkdown.Domain\SpecFlowToMarkdown.Domain.csproj"/>
<ProjectReference Include="..\SpecFlowToMarkdown.Infrastructure.Io\SpecFlowToMarkdown.Infrastructure.Io.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/6.0/SpecFlowToMarkdown.Tool/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static IServiceCollection AddServices()
.AddSingleton<IFeatureExtractor, FeatureExtractor>()
.AddSingleton<IScenarioExtractor, ScenarioExtractor>()
.AddSingleton<IFileWriter, FileWriter>()
.AddSingleton<IFileFinder, FileFinder>()
.AddSingleton<IAnchorGenerator, AnchorGenerator>()
.AddSingleton<IResultSummariser, ResultSummariser>()
.AddSingleton<IMarkdownRenderer, MarkdownRenderer>()
Expand Down

0 comments on commit 38e8637

Please sign in to comment.