diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7439f1bb9..9bd17bc64 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -50,10 +50,10 @@ jobs: # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl - - name: Setup .NET Core 3.1.404 + - name: Setup .NET Core 5.0.101 uses: actions/setup-dotnet@v1 with: - dotnet-version: '3.1.404' + dotnet-version: '5.0.101' - name: Build OpenCover x64 run: | diff --git a/build/opencover.build b/build/opencover.build index d8edcf3d5..0e0380294 100644 --- a/build/opencover.build +++ b/build/opencover.build @@ -150,7 +150,13 @@ - + + + + + + + diff --git a/main/OpenCover.Simple.Target.Core.5.0.Embedded/OpenCover.Simple.Target.Core.5.0.Embedded.csproj b/main/OpenCover.Simple.Target.Core.5.0.Embedded/OpenCover.Simple.Target.Core.5.0.Embedded.csproj new file mode 100644 index 000000000..a36bfb908 --- /dev/null +++ b/main/OpenCover.Simple.Target.Core.5.0.Embedded/OpenCover.Simple.Target.Core.5.0.Embedded.csproj @@ -0,0 +1,23 @@ + + + + Exe + net5.0 + OpenCover.Simple.Target.Core._5._0.Embedded + + + + embedded + true + + + + embedded + true + + + + + + + diff --git a/main/OpenCover.Simple.Target.Core.5.0.Portable/OpenCover.Simple.Target.Core.5.0.Portable.csproj b/main/OpenCover.Simple.Target.Core.5.0.Portable/OpenCover.Simple.Target.Core.5.0.Portable.csproj new file mode 100644 index 000000000..410a0779d --- /dev/null +++ b/main/OpenCover.Simple.Target.Core.5.0.Portable/OpenCover.Simple.Target.Core.5.0.Portable.csproj @@ -0,0 +1,13 @@ + + + + Exe + net5.0 + OpenCover.Simple.Target.Core._5._0.Portable + + + + + + + diff --git a/main/OpenCover.Simple.Target.Core.5.0/OpenCover.Simple.Target.Core.5.0.csproj b/main/OpenCover.Simple.Target.Core.5.0/OpenCover.Simple.Target.Core.5.0.csproj new file mode 100644 index 000000000..93f4ae148 --- /dev/null +++ b/main/OpenCover.Simple.Target.Core.5.0/OpenCover.Simple.Target.Core.5.0.csproj @@ -0,0 +1,23 @@ + + + + Exe + net5.0 + OpenCover.Simple.Target.Core._5._0 + + + + full + true + + + + full + true + + + + + + + diff --git a/main/OpenCover.Simple.Target.Core/Program.cs b/main/OpenCover.Simple.Target.Core/Program.cs index 529996a98..9af089172 100644 --- a/main/OpenCover.Simple.Target.Core/Program.cs +++ b/main/OpenCover.Simple.Target.Core/Program.cs @@ -23,7 +23,7 @@ static void Main(string[] args) // The factorial function itself var factorial = Fix(F); - for (int j = 0; j < 1000; j++) + for (int j = 0; j < 100; j++) { for (var i = 0; i < 12; i++) { diff --git a/main/OpenCover.Specs/DotNetCore.feature b/main/OpenCover.Specs/DotNetCore.feature index f26bbc4e5..4eb0ce037 100644 --- a/main/OpenCover.Specs/DotNetCore.feature +++ b/main/OpenCover.Specs/DotNetCore.feature @@ -38,3 +38,38 @@ Scenario: Get coverage of a .net core 3.1 application using oldstyle, with debug When I execute OpenCover against the target application using the switch '-oldstyle' Then I should have a results.xml file with a coverage greater than or equal to '100'% +Scenario: Get coverage of a .net core 5.0 application + Given I can find the OpenCover application + And I can find the target .net core '5.0' application 'OpenCover.Simple.Target.Core.5.0' + When I execute OpenCover against the target application using the switch '' + Then I should have a results.xml file with a coverage greater than or equal to '100'% + +Scenario: Get coverage of a .net core 5.0 application using oldstyle + Given I can find the OpenCover application + And I can find the target .net core '5.0' application 'OpenCover.Simple.Target.Core.5.0' + When I execute OpenCover against the target application using the switch '-oldstyle' + Then I should have a results.xml file with a coverage greater than or equal to '100'% + +Scenario: Get coverage of a .net core 5.0 application, with debugType = portable + Given I can find the OpenCover application + And I can find the target .net core '5.0' application 'OpenCover.Simple.Target.Core.5.0.Portable' + When I execute OpenCover against the target application using the switch '' + Then I should have a results.xml file with a coverage greater than or equal to '100'% + +Scenario: Get coverage of a .net core 5.0 application using oldstyle, with debugType = portable + Given I can find the OpenCover application + And I can find the target .net core '5.0' application 'OpenCover.Simple.Target.Core.5.0.Portable' + When I execute OpenCover against the target application using the switch '-oldstyle' + Then I should have a results.xml file with a coverage greater than or equal to '100'% + +Scenario: Get coverage of a .net core 5.0 application, with debugType = embedded + Given I can find the OpenCover application + And I can find the target .net core '5.0' application 'OpenCover.Simple.Target.Core.5.0.Embedded' + When I execute OpenCover against the target application using the switch '' + Then I should have a results.xml file with a coverage greater than or equal to '100'% + +Scenario: Get coverage of a .net core 5.0 application using oldstyle, with debugType = embedded + Given I can find the OpenCover application + And I can find the target .net core '5.0' application 'OpenCover.Simple.Target.Core.5.0.Embedded' + When I execute OpenCover against the target application using the switch '-oldstyle' + Then I should have a results.xml file with a coverage greater than or equal to '100'% diff --git a/main/OpenCover.Specs/DotNetCore.feature.cs b/main/OpenCover.Specs/DotNetCore.feature.cs index db794b5b8..c4ae2eada 100644 --- a/main/OpenCover.Specs/DotNetCore.feature.cs +++ b/main/OpenCover.Specs/DotNetCore.feature.cs @@ -342,6 +342,274 @@ public virtual void GetCoverageOfA_NetCore3_1ApplicationUsingOldstyleWithDebugTy #line hidden #line 39 testRunner.Then("I should have a results.xml file with a coverage greater than or equal to \'100\'%", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Get coverage of a .net core 5.0 application")] + public virtual void GetCoverageOfA_NetCore5_0Application() + { + string[] tagsOfScenario = ((string[])(null)); + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get coverage of a .net core 5.0 application", null, tagsOfScenario, argumentsOfScenario); +#line 41 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 42 + testRunner.Given("I can find the OpenCover application", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 43 + testRunner.And("I can find the target .net core \'5.0\' application \'OpenCover.Simple.Target.Core.5" + + ".0\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 44 + testRunner.When("I execute OpenCover against the target application using the switch \'\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 45 + testRunner.Then("I should have a results.xml file with a coverage greater than or equal to \'100\'%", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Get coverage of a .net core 5.0 application using oldstyle")] + public virtual void GetCoverageOfA_NetCore5_0ApplicationUsingOldstyle() + { + string[] tagsOfScenario = ((string[])(null)); + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get coverage of a .net core 5.0 application using oldstyle", null, tagsOfScenario, argumentsOfScenario); +#line 47 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 48 + testRunner.Given("I can find the OpenCover application", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 49 + testRunner.And("I can find the target .net core \'5.0\' application \'OpenCover.Simple.Target.Core.5" + + ".0\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 50 + testRunner.When("I execute OpenCover against the target application using the switch \'-oldstyle\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 51 + testRunner.Then("I should have a results.xml file with a coverage greater than or equal to \'100\'%", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Get coverage of a .net core 5.0 application, with debugType = portable")] + public virtual void GetCoverageOfA_NetCore5_0ApplicationWithDebugTypePortable() + { + string[] tagsOfScenario = ((string[])(null)); + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get coverage of a .net core 5.0 application, with debugType = portable", null, tagsOfScenario, argumentsOfScenario); +#line 53 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 54 + testRunner.Given("I can find the OpenCover application", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 55 + testRunner.And("I can find the target .net core \'5.0\' application \'OpenCover.Simple.Target.Core.5" + + ".0.Portable\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 56 + testRunner.When("I execute OpenCover against the target application using the switch \'\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 57 + testRunner.Then("I should have a results.xml file with a coverage greater than or equal to \'100\'%", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Get coverage of a .net core 5.0 application using oldstyle, with debugType = port" + + "able")] + public virtual void GetCoverageOfA_NetCore5_0ApplicationUsingOldstyleWithDebugTypePortable() + { + string[] tagsOfScenario = ((string[])(null)); + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get coverage of a .net core 5.0 application using oldstyle, with debugType = port" + + "able", null, tagsOfScenario, argumentsOfScenario); +#line 59 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 60 + testRunner.Given("I can find the OpenCover application", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 61 + testRunner.And("I can find the target .net core \'5.0\' application \'OpenCover.Simple.Target.Core.5" + + ".0.Portable\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 62 + testRunner.When("I execute OpenCover against the target application using the switch \'-oldstyle\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 63 + testRunner.Then("I should have a results.xml file with a coverage greater than or equal to \'100\'%", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Get coverage of a .net core 5.0 application, with debugType = embedded")] + public virtual void GetCoverageOfA_NetCore5_0ApplicationWithDebugTypeEmbedded() + { + string[] tagsOfScenario = ((string[])(null)); + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get coverage of a .net core 5.0 application, with debugType = embedded", null, tagsOfScenario, argumentsOfScenario); +#line 65 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 66 + testRunner.Given("I can find the OpenCover application", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 67 + testRunner.And("I can find the target .net core \'5.0\' application \'OpenCover.Simple.Target.Core.5" + + ".0.Embedded\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 68 + testRunner.When("I execute OpenCover against the target application using the switch \'\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 69 + testRunner.Then("I should have a results.xml file with a coverage greater than or equal to \'100\'%", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); +#line hidden + } + this.ScenarioCleanup(); + } + + [NUnit.Framework.TestAttribute()] + [NUnit.Framework.DescriptionAttribute("Get coverage of a .net core 5.0 application using oldstyle, with debugType = embe" + + "dded")] + public virtual void GetCoverageOfA_NetCore5_0ApplicationUsingOldstyleWithDebugTypeEmbedded() + { + string[] tagsOfScenario = ((string[])(null)); + System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); + TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Get coverage of a .net core 5.0 application using oldstyle, with debugType = embe" + + "dded", null, tagsOfScenario, argumentsOfScenario); +#line 71 +this.ScenarioInitialize(scenarioInfo); +#line hidden + bool isScenarioIgnored = default(bool); + bool isFeatureIgnored = default(bool); + if ((tagsOfScenario != null)) + { + isScenarioIgnored = tagsOfScenario.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((this._featureTags != null)) + { + isFeatureIgnored = this._featureTags.Where(__entry => __entry != null).Where(__entry => String.Equals(__entry, "ignore", StringComparison.CurrentCultureIgnoreCase)).Any(); + } + if ((isScenarioIgnored || isFeatureIgnored)) + { + testRunner.SkipScenario(); + } + else + { + this.ScenarioStart(); +#line 72 + testRunner.Given("I can find the OpenCover application", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Given "); +#line hidden +#line 73 + testRunner.And("I can find the target .net core \'5.0\' application \'OpenCover.Simple.Target.Core.5" + + ".0.Embedded\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "And "); +#line hidden +#line 74 + testRunner.When("I execute OpenCover against the target application using the switch \'-oldstyle\'", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "When "); +#line hidden +#line 75 + testRunner.Then("I should have a results.xml file with a coverage greater than or equal to \'100\'%", ((string)(null)), ((TechTalk.SpecFlow.Table)(null)), "Then "); #line hidden } this.ScenarioCleanup(); diff --git a/main/OpenCover.Specs/Steps/DotNetCoreSteps.cs b/main/OpenCover.Specs/Steps/DotNetCoreSteps.cs index 6cc8debb0..a6305d396 100644 --- a/main/OpenCover.Specs/Steps/DotNetCoreSteps.cs +++ b/main/OpenCover.Specs/Steps/DotNetCoreSteps.cs @@ -1,89 +1,94 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Linq; -using NUnit.Framework; -using TechTalk.SpecFlow; - -namespace OpenCover.Specs.Steps -{ - [Binding] - public class DotNetCoreSteps +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using NUnit.Framework; +using TechTalk.SpecFlow; + +namespace OpenCover.Specs.Steps +{ + [Binding] + public class DotNetCoreSteps { private readonly ScenarioContext _scenarioContext; public DotNetCoreSteps(ScenarioContext scenarioContext) { _scenarioContext = scenarioContext; - } - - [Given(@"I can find the OpenCover application")] - public void GivenICanFindTheOpenCoverApplication() - { -#if DEBUG - var targetFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(DotNetCoreSteps).Assembly.Location) ?? ".", @"..\..\..\bin\Debug")); -#else - var targetFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(DotNetCoreSteps).Assembly.Location) ?? ".", @"..\..\..\bin\Release")); -#endif - Assert.IsTrue(File.Exists(Path.Combine(targetFolder, "OpenCover.Console.exe"))); - - _scenarioContext["TargetFolder"] = targetFolder; - } - - [Given(@"I can find the target \.net core '(.*)' application '(.*)'")] - public void GivenICanFindTheTarget_NetCoreApplication(string version, string application) - { -#if DEBUG - var targetPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(DotNetCoreSteps).Assembly.Location) ?? ".", $@"..\..\..\{application}\bin\Debug\netcoreapp{version}")); -#else - var targetPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(DotNetCoreSteps).Assembly.Location) ?? ".", $@"..\..\..\{application}\bin\Release\netcoreapp{version}")); -#endif - var targetApp = Directory.EnumerateFiles(targetPath, $"{application}.dll", SearchOption.AllDirectories).FirstOrDefault(); - - Console.WriteLine($"Found target application in '{targetApp}'"); - - Assert.IsTrue(File.Exists(targetApp)); - - _scenarioContext["TargetApp"] = targetApp; - } - - [When(@"I execute OpenCover against the target application using the switch '(.*)'")] - public void WhenIExecuteOpenCoverAgainstTheTargetApplicationUsingTheSwitch(string additionalSwitch) - { - var dotnetexe = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"dotnet\dotnet.exe"); - var targetApp = (string)_scenarioContext["TargetApp"]; - var targetFolder = (string)_scenarioContext["TargetFolder"]; - var outputXml = Path.Combine(Path.GetDirectoryName(targetApp) ?? ".", "results.xml"); - if (File.Exists(outputXml)) - File.Delete(outputXml); - - var info = new ProcessStartInfo - { - FileName = Path.Combine(targetFolder, "OpenCover.Console.exe"), - Arguments = $"{additionalSwitch ?? ""} -register:user \"-target:{dotnetexe}\" \"-targetargs:{targetApp}\" \"-output:{outputXml}\"", - WorkingDirectory = targetFolder, - UseShellExecute = false, - RedirectStandardOutput = true - }; - - //Console.WriteLine($"{info.FileName} {info.Arguments}"); - - var process = Process.Start(info); - Assert.NotNull(process); - var console = process.StandardOutput.ReadToEnd(); - process.WaitForExit(); - - Assert.True(File.Exists(outputXml)); - - _scenarioContext["OutputXml"] = outputXml; - } - - [Then(@"I should have a results\.xml file with a coverage greater than or equal to '(.*)'%")] - public void ThenIShouldHaveAResults_XmlFileWithACoverageGreaterThanOrEqualTo(int coveragePercentage) - { - var xml = File.ReadAllText((string) _scenarioContext["OutputXml"]); - var coverage = Utils.GetTotalCoverage(xml) ?? "-1"; - Assert.GreaterOrEqual(decimal.Parse(coverage), coveragePercentage); - } - } -} + } + + [Given(@"I can find the OpenCover application")] + public void GivenICanFindTheOpenCoverApplication() + { +#if DEBUG + var targetFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(DotNetCoreSteps).Assembly.Location) ?? ".", @"..\..\..\bin\Debug")); +#else + var targetFolder = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(typeof(DotNetCoreSteps).Assembly.Location) ?? ".", @"..\..\..\bin\Release")); +#endif + Assert.IsTrue(File.Exists(Path.Combine(targetFolder, "OpenCover.Console.exe"))); + + _scenarioContext["TargetFolder"] = targetFolder; + } + + [Given(@"I can find the target \.net core '(.*)' application '(.*)'")] + public void GivenICanFindTheTarget_NetCoreApplication(string version, string application) + { + var assemblyLocation = Path.GetDirectoryName(typeof(DotNetCoreSteps).Assembly.Location); +#if DEBUG + var targetPath = Path.GetFullPath(Path.Combine(assemblyLocation ?? ".", $@"..\..\..\{application}\bin\Debug\netcoreapp{version}")); + if (!Directory.Exists(targetPath)) + targetPath = Path.GetFullPath(Path.Combine(assemblyLocation ?? ".", $@"..\..\..\{application}\bin\Debug\net{version}")); +#else + var targetPath = Path.GetFullPath(Path.Combine(assemblyLocation ?? ".", $@"..\..\..\{application}\bin\Release\netcoreapp{version}")); + if (!Directory.Exists(targetPath)) + targetPath = Path.GetFullPath(Path.Combine(assemblyLocation ?? ".", $@"..\..\..\{application}\bin\Release\net{version}")); +#endif + var targetApp = Directory.EnumerateFiles(targetPath, $"{application}.dll", SearchOption.AllDirectories).FirstOrDefault(); + + Console.WriteLine($"Found target application in '{targetApp}'"); + + Assert.IsTrue(File.Exists(targetApp)); + + _scenarioContext["TargetApp"] = targetApp; + } + + [When(@"I execute OpenCover against the target application using the switch '(.*)'")] + public void WhenIExecuteOpenCoverAgainstTheTargetApplicationUsingTheSwitch(string additionalSwitch) + { + var dotnetexe = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"dotnet\dotnet.exe"); + var targetApp = (string)_scenarioContext["TargetApp"]; + var targetFolder = (string)_scenarioContext["TargetFolder"]; + var outputXml = Path.Combine(Path.GetDirectoryName(targetApp) ?? ".", "results.xml"); + if (File.Exists(outputXml)) + File.Delete(outputXml); + + var info = new ProcessStartInfo + { + FileName = Path.Combine(targetFolder, "OpenCover.Console.exe"), + Arguments = $"{additionalSwitch ?? ""} -register:user \"-target:{dotnetexe}\" \"-targetargs:{targetApp}\" \"-output:{outputXml}\"", + WorkingDirectory = targetFolder, + UseShellExecute = false, + RedirectStandardOutput = true + }; + + //Console.WriteLine($"{info.FileName} {info.Arguments}"); + + var process = Process.Start(info); + Assert.NotNull(process); + var console = process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + + Assert.True(File.Exists(outputXml)); + + _scenarioContext["OutputXml"] = outputXml; + } + + [Then(@"I should have a results\.xml file with a coverage greater than or equal to '(.*)'%")] + public void ThenIShouldHaveAResults_XmlFileWithACoverageGreaterThanOrEqualTo(int coveragePercentage) + { + var xml = File.ReadAllText((string) _scenarioContext["OutputXml"]); + var coverage = Utils.GetTotalCoverage(xml) ?? "-1"; + Assert.GreaterOrEqual(decimal.Parse(coverage), coveragePercentage); + } + } +} diff --git a/main/OpenCover.sln b/main/OpenCover.sln index 2e3eb6373..ac7e21dff 100644 --- a/main/OpenCover.sln +++ b/main/OpenCover.sln @@ -109,11 +109,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCover.Simple.Target.Cor EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCover.Simple.Target.Core.2.2.Embedded", "OpenCover.Simple.Target.Core.2.2.Embedded\OpenCover.Simple.Target.Core.2.2.Embedded.csproj", "{3E9D9683-FFBA-407C-898F-8CB5B80ACF29}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenCover.Simple.Target.Core.3.1", "OpenCover.Simple.Target.Core.3.1\OpenCover.Simple.Target.Core.3.1.csproj", "{430012FA-1A96-4D46-9211-38163ECB3E69}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCover.Simple.Target.Core.3.1", "OpenCover.Simple.Target.Core.3.1\OpenCover.Simple.Target.Core.3.1.csproj", "{430012FA-1A96-4D46-9211-38163ECB3E69}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenCover.Simple.Target.Core.3.1.Embedded", "OpenCover.Simple.Target.Core.3.1.Embedded\OpenCover.Simple.Target.Core.3.1.Embedded.csproj", "{9E4C874B-E0D6-401A-9758-221F5553A5D4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCover.Simple.Target.Core.3.1.Embedded", "OpenCover.Simple.Target.Core.3.1.Embedded\OpenCover.Simple.Target.Core.3.1.Embedded.csproj", "{9E4C874B-E0D6-401A-9758-221F5553A5D4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenCover.Simple.Target.Core.3.1.Portable", "OpenCover.Simple.Target.Core.3.1.Portable\OpenCover.Simple.Target.Core.3.1.Portable.csproj", "{B8393633-E01A-452E-8848-464C27DC4C07}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCover.Simple.Target.Core.3.1.Portable", "OpenCover.Simple.Target.Core.3.1.Portable\OpenCover.Simple.Target.Core.3.1.Portable.csproj", "{B8393633-E01A-452E-8848-464C27DC4C07}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenCover.Simple.Target.Core.5.0", "OpenCover.Simple.Target.Core.5.0\OpenCover.Simple.Target.Core.5.0.csproj", "{5331BFDB-B1D6-48D4-9D6F-08F593650474}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenCover.Simple.Target.Core.5.0.Portable", "OpenCover.Simple.Target.Core.5.0.Portable\OpenCover.Simple.Target.Core.5.0.Portable.csproj", "{658DBB03-563F-4399-AAF3-7243BA1393D1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenCover.Simple.Target.Core.5.0.Embedded", "OpenCover.Simple.Target.Core.5.0.Embedded\OpenCover.Simple.Target.Core.5.0.Embedded.csproj", "{C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -280,6 +286,30 @@ Global {B8393633-E01A-452E-8848-464C27DC4C07}.Release|x64.Build.0 = Release|Any CPU {B8393633-E01A-452E-8848-464C27DC4C07}.Release|x86.ActiveCfg = Release|Any CPU {B8393633-E01A-452E-8848-464C27DC4C07}.Release|x86.Build.0 = Release|Any CPU + {5331BFDB-B1D6-48D4-9D6F-08F593650474}.Debug|x64.ActiveCfg = Debug|Any CPU + {5331BFDB-B1D6-48D4-9D6F-08F593650474}.Debug|x64.Build.0 = Debug|Any CPU + {5331BFDB-B1D6-48D4-9D6F-08F593650474}.Debug|x86.ActiveCfg = Debug|Any CPU + {5331BFDB-B1D6-48D4-9D6F-08F593650474}.Debug|x86.Build.0 = Debug|Any CPU + {5331BFDB-B1D6-48D4-9D6F-08F593650474}.Release|x64.ActiveCfg = Release|Any CPU + {5331BFDB-B1D6-48D4-9D6F-08F593650474}.Release|x64.Build.0 = Release|Any CPU + {5331BFDB-B1D6-48D4-9D6F-08F593650474}.Release|x86.ActiveCfg = Release|Any CPU + {5331BFDB-B1D6-48D4-9D6F-08F593650474}.Release|x86.Build.0 = Release|Any CPU + {658DBB03-563F-4399-AAF3-7243BA1393D1}.Debug|x64.ActiveCfg = Debug|Any CPU + {658DBB03-563F-4399-AAF3-7243BA1393D1}.Debug|x64.Build.0 = Debug|Any CPU + {658DBB03-563F-4399-AAF3-7243BA1393D1}.Debug|x86.ActiveCfg = Debug|Any CPU + {658DBB03-563F-4399-AAF3-7243BA1393D1}.Debug|x86.Build.0 = Debug|Any CPU + {658DBB03-563F-4399-AAF3-7243BA1393D1}.Release|x64.ActiveCfg = Release|Any CPU + {658DBB03-563F-4399-AAF3-7243BA1393D1}.Release|x64.Build.0 = Release|Any CPU + {658DBB03-563F-4399-AAF3-7243BA1393D1}.Release|x86.ActiveCfg = Release|Any CPU + {658DBB03-563F-4399-AAF3-7243BA1393D1}.Release|x86.Build.0 = Release|Any CPU + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}.Debug|x64.ActiveCfg = Debug|Any CPU + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}.Debug|x64.Build.0 = Debug|Any CPU + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}.Debug|x86.ActiveCfg = Debug|Any CPU + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}.Debug|x86.Build.0 = Debug|Any CPU + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}.Release|x64.ActiveCfg = Release|Any CPU + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}.Release|x64.Build.0 = Release|Any CPU + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}.Release|x86.ActiveCfg = Release|Any CPU + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -307,6 +337,9 @@ Global {430012FA-1A96-4D46-9211-38163ECB3E69} = {BB3EABCA-7978-4809-A5CF-51F85860DD55} {9E4C874B-E0D6-401A-9758-221F5553A5D4} = {BB3EABCA-7978-4809-A5CF-51F85860DD55} {B8393633-E01A-452E-8848-464C27DC4C07} = {BB3EABCA-7978-4809-A5CF-51F85860DD55} + {5331BFDB-B1D6-48D4-9D6F-08F593650474} = {BB3EABCA-7978-4809-A5CF-51F85860DD55} + {658DBB03-563F-4399-AAF3-7243BA1393D1} = {BB3EABCA-7978-4809-A5CF-51F85860DD55} + {C2D112ED-11E4-4081-AFEF-655CDD5D4FB2} = {BB3EABCA-7978-4809-A5CF-51F85860DD55} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {07668570-E91E-4CCA-A9BF-EC3A83011035} diff --git a/main/global.json b/main/global.json index 8afc0f0d2..f2363cb09 100644 --- a/main/global.json +++ b/main/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.404" + "version": "5.0.101" } }