Skip to content

Commit

Permalink
remove unused SpecRun support from TestProjectGenerator (#206)
Browse files Browse the repository at this point in the history
* remove unused SpecRun support from TestProjectGenerator

* remove further specrun stuff
  • Loading branch information
gasparnagy authored Jul 12, 2024
1 parent d7e3161 commit 194e995
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 82 deletions.
1 change: 0 additions & 1 deletion Tests/Reqnroll.Specs/Support/Hooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void BeforeScenario()
ConfigurationFormat = ConfigurationFormat.Json
});

_currentVersionDriver.NuGetVersion = NuGetPackageVersion.Version;
_currentVersionDriver.ReqnrollNuGetVersion = NuGetPackageVersion.Version;
_scenarioContext.ScenarioContainer.RegisterTypeAs<OutputConnector, IOutputWriter>();

Expand Down
1 change: 0 additions & 1 deletion Tests/Reqnroll.SystemTests/SystemTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ protected virtual void TestInitialize()
_testRunConfiguration.UnitTestProvider = UnitTestProvider.MSTest;

_currentVersionDriver = _testContainer.GetService<CurrentVersionDriver>();
_currentVersionDriver.NuGetVersion = NuGetPackageVersion.Version;
_currentVersionDriver.ReqnrollNuGetVersion = NuGetPackageVersion.Version;

_folderCleaner = _testContainer.GetService<FolderCleaner>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class GenerateSolutionParams

public ConfigurationFormat ConfigurationFormat { get; set; }

public string SpecrunNuGetVersion { get; set; }

public int FeatureCount { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
using System.CommandLine.Invocation;
using System.IO;
using System.Text.RegularExpressions;
using Reqnroll.TestProjectGenerator;
using Reqnroll.TestProjectGenerator.Conventions;
using Reqnroll.TestProjectGenerator.Data;
using Reqnroll.TestProjectGenerator.Driver;

namespace Reqnroll.TestProjectGenerator.Cli
{
partial class Program
class Program
{
private const string DefaultReqnrollNuGetVersion = "3.4.3";
private const UnitTestProvider DefaultUnitTestProvider = UnitTestProvider.SpecRun;
private const UnitTestProvider DefaultUnitTestProvider = UnitTestProvider.MSTest;
private const TargetFramework DefaultTargetFramework = TargetFramework.Netcoreapp31;
private const ProjectFormat DefaultProjectFormat = ProjectFormat.New;
private const ConfigurationFormat DefaultConfigurationFormat = ConfigurationFormat.Json;
private const string DefaultSpecRunNuGetVersion = "3.4.19";

static int Main(string[] args)
{
Expand Down Expand Up @@ -55,10 +53,6 @@ static int Main(string[] args)
"--configuration-format",
() => DefaultConfigurationFormat,
$"The format of the generated Reqnroll configuration file. Default: '{DefaultConfigurationFormat}'."),
new Option<string>(
"--specrun-nuget-version",
() => DefaultSpecRunNuGetVersion,
$"The SpecRun NuGet version referenced in the generated project (if SpecRun is used as unit test provider). Default: '{DefaultSpecRunNuGetVersion}'."),
new Option<int>(
"--feature-count",
() => 1,
Expand All @@ -73,13 +67,13 @@ static int Main(string[] args)
{
var services = ConfigureServices();
services.AddSingleton(s => new SolutionConfiguration
services.AddSingleton(_ => new SolutionConfiguration
{
OutDir = generateSolutionParams.OutDir,
SolutionName = generateSolutionParams.SlnName
});
services.AddSingleton(s => new TestRunConfiguration
services.AddSingleton(_ => new TestRunConfiguration
{
ProgrammingLanguage = ProgrammingLanguage.CSharp,
UnitTestProvider = generateSolutionParams.UnitTestProvider,
Expand All @@ -88,19 +82,19 @@ static int Main(string[] args)
TargetFramework = generateSolutionParams.TargetFramework,
});
Func<string, Version> getRunnerReqnrollVersion = (string reqnrollNuGetVersion) =>
Version GetReqnrollVersion(string reqnrollNuGetVersion)
{
var m = new Regex("^(\\d+)\\.(\\d+)").Match(reqnrollNuGetVersion);
return new Version(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value), 0);
};
services.AddSingleton(s => new CurrentVersionDriver
}
services.AddSingleton(_ => new CurrentVersionDriver
{
ReqnrollNuGetVersion = generateSolutionParams.ReqnrollNuGetVersion.ToString(),
ReqnrollVersion = getRunnerReqnrollVersion(generateSolutionParams.ReqnrollNuGetVersion),
NuGetVersion = generateSolutionParams.SpecrunNuGetVersion.ToString()
ReqnrollVersion = GetReqnrollVersion(generateSolutionParams.ReqnrollNuGetVersion),
});
services.AddSingleton<GenerateSolutionParams>(s => generateSolutionParams);
services.AddSingleton(_ => generateSolutionParams);
var serviceProvider = services.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public AppConfigGeneratorTests()
[Fact]
public void FileNameIsAppConfig()
{
var configuration = new Configuration {UnitTestProvider = Reqnroll.TestProjectGenerator.UnitTestProvider.SpecRun};
var configuration = new Configuration();
var projectFile = _appConfigGenerator.Generate(configuration);
projectFile.Path.Should().Be("app.config");
}

[Fact]
public void BuildActionIsNone()
{
var configuration = new Configuration { UnitTestProvider = Reqnroll.TestProjectGenerator.UnitTestProvider.SpecRun };
var configuration = new Configuration();
var projectFile = _appConfigGenerator.Generate(configuration);
projectFile.BuildAction.Should().Be("None");
}
Expand All @@ -36,7 +36,7 @@ public void BuildActionIsNone()
[Fact]
public void SingleAdditionalStepAssembly()
{
var configuration = new Configuration { UnitTestProvider = Reqnroll.TestProjectGenerator.UnitTestProvider.SpecRun };
var configuration = new Configuration();
configuration.BindingAssemblies.Add(new BindingAssembly("AdditionalStepAssembly"));

var projectFile = _appConfigGenerator.Generate(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ public JsonConfigGeneratorTests()
[Fact]
public void FileNameIsAppConfig()
{
var configuration = new Configuration { UnitTestProvider = Reqnroll.TestProjectGenerator.UnitTestProvider.SpecRun };
var configuration = new Configuration();
var projectFile = _jsonConfigGenerator.Generate(configuration);
projectFile.Path.Should().Be("reqnroll.json");
}

[Fact]
public void BuildActionIsNone()
{
var configuration = new Configuration { UnitTestProvider = Reqnroll.TestProjectGenerator.UnitTestProvider.SpecRun };
var configuration = new Configuration();
var projectFile = _jsonConfigGenerator.Generate(configuration);
projectFile.BuildAction.Should().Be("None");
}

[Fact]
public void SingleAdditionalStepAssembly()
{
var configuration = new Configuration { UnitTestProvider = Reqnroll.TestProjectGenerator.UnitTestProvider.SpecRun };
var configuration = new Configuration();
configuration.BindingAssemblies.Add(new BindingAssembly("AdditionalStepAssembly"));

var projectFile = _jsonConfigGenerator.Generate(configuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public CurrentVersionDriver()

public string ReqnrollNuGetVersion { get; set; }

public string NuGetVersion { get; set; }

public string MajorMinorPatchVersion { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ private UnitTestProvider GetUnitTestProvider(string providerName)
{
switch (providerName.ToLower())
{
case "specrun+nunit": return UnitTestProvider.SpecRunWithNUnit;
case "specrun+nunit.2": return UnitTestProvider.SpecRunWithNUnit2;
case "specrun+mstest": return UnitTestProvider.SpecRunWithMsTest;
case "specrun": return UnitTestProvider.SpecRun;
case "mstest": return UnitTestProvider.MSTest;
case "xunit": return UnitTestProvider.xUnit;
case "nunit": return UnitTestProvider.NUnit3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ public SolutionDriver(
new("Reqnroll Unstable", "https://www.myget.org/F/reqnroll-unstable/api/v3/index.json")
};

if (testRunConfiguration.UnitTestProvider == UnitTestProvider.SpecRun)
{
NuGetSources.Add(new NuGetSource("Reqnroll CI", "https://www.myget.org/F/reqnroll/api/v3/index.json"));
NuGetSources.Add(new NuGetSource("Reqnroll Unstable", "https://www.myget.org/F/reqnroll-unstable/api/v3/index.json"));
}
if (testRunConfiguration.TargetFramework == TargetFramework.Net50 && testRunConfiguration.UnitTestProvider == UnitTestProvider.NUnit3)
{
//NUnit is not supporting .NET 5 in the latest release (3.12.0), so add the myget feed for the pre-release versions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ public static string ToName(this UnitTestProvider unitTestProvider)
{
switch (unitTestProvider)
{
case UnitTestProvider.SpecRunWithNUnit: return "SpecRun+NUnit";
case UnitTestProvider.SpecRunWithNUnit2: return "SpecRun+NUnit.2";
case UnitTestProvider.SpecRunWithMsTest: return "SpecRun+MsTest";
case UnitTestProvider.MSTest: return "MSTest";
case UnitTestProvider.NUnit2: return "NUnit2";
case UnitTestProvider.NUnit3: return "NUnit";
case UnitTestProvider.xUnit: return "XUnit";
case UnitTestProvider.SpecRun: return "SpecRun";
default: throw new ArgumentOutOfRangeException(nameof(unitTestProvider), unitTestProvider, "value is not known");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,6 @@ private void EnsureProjectExists()

switch (Configuration.UnitTestProvider)
{
case UnitTestProvider.SpecRun:
case UnitTestProvider.SpecRunWithMsTest:
case UnitTestProvider.SpecRunWithNUnit:
throw new NotSupportedException("Testing with SpecRun is not supported!");
case UnitTestProvider.MSTest:
ConfigureMSTest();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,10 @@ private TestExecutionResult CalculateUnitTestProviderSpecificTestExecutionResult
case UnitTestProvider.xUnit: return CalculateXUnitTestExecutionResult(testExecutionResult, trx);
case UnitTestProvider.MSTest: return CalculateMsTestTestExecutionResult(testExecutionResult);
case UnitTestProvider.NUnit3: return CalculateNUnitTestExecutionResult(testExecutionResult);
case UnitTestProvider.SpecRun: return CalculateSpecRunTestExecutionResult(testExecutionResult);
default: throw new NotSupportedException($"The specified unit test provider is not supported: {testRunConfiguration.UnitTestProvider}");
}
}

private TestExecutionResult CalculateSpecRunTestExecutionResult(TestExecutionResult testExecutionResult)
{
bool FilterIgnored(TestResult testResult) => testResult.StdOut.Contains("-> Ignored");

bool FilterPending(TestResult testResult) => testResult.StdOut.Contains("TechTalk.SpecRun.PendingTestException")
|| testResult.StdOut.Contains("No matching step definition found for the step.");

var testResultsWithOutput = testExecutionResult.TestResults.Where(tr => !(tr?.StdOut is null)).ToArray();

testExecutionResult.Ignored = testResultsWithOutput.Where(FilterIgnored).Count();
testExecutionResult.Pending = testResultsWithOutput.Where(FilterPending).Count();

return testExecutionResult;
}

private TestExecutionResult CalculateNUnitTestExecutionResult(TestExecutionResult testExecutionResult)
{
testExecutionResult.Ignored = GetNUnitIgnoredCount(testExecutionResult);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
namespace Reqnroll.TestProjectGenerator
namespace Reqnroll.TestProjectGenerator;

public enum UnitTestProvider
{
public enum UnitTestProvider
{
SpecRun,
SpecRunWithNUnit,
SpecRunWithNUnit2,
SpecRunWithMsTest,
MSTest,
xUnit,
NUnit3,
NUnit2

}
MSTest,
xUnit,
NUnit3,
NUnit2
}
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,6 @@ public string GenerateVerbosityParameter(string verbosity)

public string GenerateAdditionalPackagesFoldersParameters()
{
if (_testRunConfiguration.UnitTestProvider != UnitTestProvider.SpecRun)
{
if (_testRunConfiguration.ProjectFormat == ProjectFormat.Old)
{
return $" --test-adapter-path \"{_testProjectFolders.PathToNuGetPackages}\"";
}
}

return null;
}
}
Expand Down

0 comments on commit 194e995

Please sign in to comment.