Skip to content

Commit

Permalink
prepare 4.2 (#928)
Browse files Browse the repository at this point in the history
* prepare 4.2

* Fix warning and set beta,2

* Adding more logging

* filters added handling explicits

* small fixes

* Code cleanup

* beta.4

* Addind filter acceptance tests

* update with more logs

* Adding nunit.where tester

* FIx warnings

* Added more tests and added csproj base class to make it easier to make more

* fix tests

* fix SA warnings

* Oppdatert pakker o.a.

* Reanebled output of console message, introducing another ConsoleOut level, so one can go back.  Fixes #934

* fixing linux errors

* Add consoletests

* COnsole and propertytests

* naming fixed

* fix

* FIx namespaces

* sa fix

* sa fix

* accentance tests, with parantheses issue

* Fixing Issue #919

* fix braces

* fix braces

* Version to 4.2.0
  • Loading branch information
OsirisTerje authored Dec 27, 2021
1 parent c499397 commit 0b118ec
Show file tree
Hide file tree
Showing 47 changed files with 986 additions and 234 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ csharp_space_between_square_brackets = false
# Wrapping preferences
csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = true
dotnet_diagnostic.SA1000.severity=silent
dotnet_diagnostic.SA1518.severity=silent

#### Naming styles ####
[*.{cs,vb}]
Expand Down
6 changes: 3 additions & 3 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#tool vswhere&version=2.7.1
#tool Microsoft.TestPlatform&version=16.11.0
#tool vswhere&version=2.8.4
#tool Microsoft.TestPlatform&version=17.0.0

//////////////////////////////////////////////////////////////////////
// ARGUMENTS
Expand All @@ -13,7 +13,7 @@ var configuration = Argument("configuration", "Release");
//////////////////////////////////////////////////////////////////////

var version = "4.2.0";
var modifier = "-alpha.4";
var modifier = "";

var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
var packageVersion = version + modifier + dbgSuffix;
Expand Down
6 changes: 2 additions & 4 deletions nuget/NUnit3TestAdapter.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
<metadata>
<id>NUnit3TestAdapter</id>
<version>$version$</version>
<title>NUnit 3 Test Adapter for Visual Studio and DotNet</title>
<title>NUnit3 Test Adapter for Visual Studio and DotNet</title>
<authors>Charlie Poole, Terje Sandstrom</authors>
<license type="expression">MIT</license>
<projectUrl>https://docs.nunit.org/articles/vs-test-adapter/Index.html</projectUrl>
<repository type="git" url="https://github.com/nunit/nunit3-vs-adapter"/>
<iconUrl>https://cdn.rawgit.com/nunit/resources/master/images/icon/nunit_256.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<summary>NUnit 3 adapter for running tests in Visual Studio and DotNet. Works with NUnit 3.x, use the NUnit 2 adapter for 2.x tests.</summary>
<summary>NUnit3 adapter for running tests in Visual Studio and DotNet. Works with NUnit 3.x, use the NUnit 2 adapter for 2.x tests.</summary>
<description>
The NUnit3 TestAdapter for Visual Studio, all versions from 2012 and onwards, and DotNet (incl. .Net core).

Note that this package ONLY contains the adapter, not the NUnit framework.
For VS 2017 and forward, you should add this package to every test project in your solution. (Earlier versions only require a single adapter package per solution.)

Note that with this package you should not install the VSIX adapter package.
</description>
<releaseNotes>See https://docs.nunit.org/articles/vs-test-adapter/Adapter-Release-Notes.html </releaseNotes>
<copyright>Copyright (c) 2011-2021 Charlie Poole, 2014-2021 Terje Sandstrom</copyright>
Expand Down
4 changes: 2 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.66" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
<PackageReference Include="jnm2.ReferenceAssemblies.net35" Version="1.0.1" />
</ItemGroup>

Expand Down
87 changes: 50 additions & 37 deletions src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,87 +3,97 @@
using System.Diagnostics;
using System.IO;
using System.Linq;

using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
{
public class Frameworks
{
public const string NetCoreApp31 = "netcoreapp3.1";
public const string NetCoreApp21 = "netcoreapp2.1";
public const string Net50 = "net5.0";
public const string Net60 = "net6.0";
}

[Category("Acceptance")]
public abstract class AcceptanceTests
{
public static string NuGetPackageId { get; } = "NUnit3TestAdapter";
public static string NuGetPackageId => "NUnit3TestAdapter";

public static string NuGetPackageVersion => Initialization.Value.nupkgVersion;
public static string NuGetPackageVersion => Initialization.Value.NupkgVersion;

public const string LowestNetfxTarget = "net35";
public const string LegacyProjectTargetFrameworkVersion = "v3.5";

public static IEnumerable<string> TargetFrameworks => new[]
{
LowestNetfxTarget,
"netcoreapp2.1"
Frameworks.NetCoreApp21
};

public static IEnumerable<string> DotNetCliTargetFrameworks => new[]
{
"netcoreapp2.1",
"netcoreapp3.1"
Frameworks.NetCoreApp21,
Frameworks.NetCoreApp31,
Frameworks.Net50
};

private static readonly Lazy<(IsolatedWorkspaceManager manager, string nupkgVersion, bool keepWorkspaces)> Initialization = new (() =>
{
var directory = TestContext.Parameters["ProjectWorkspaceDirectory"]
?? TryAutoDetectProjectWorkspaceDirectory()
?? throw new InvalidOperationException("The test parameter ProjectWorkspaceDirectory must be set in order to run this test.");
private static readonly Lazy<(IsolatedWorkspaceManager Manager, string NupkgVersion, bool KeepWorkspaces)> Initialization = new(() =>
{
var directory = TestContext.Parameters["ProjectWorkspaceDirectory"]
?? TryAutoDetectProjectWorkspaceDirectory()
?? throw new InvalidOperationException("The test parameter ProjectWorkspaceDirectory must be set in order to run this test.");
var nupkgDirectory = TestContext.Parameters["TestNupkgDirectory"]
?? TryAutoDetectTestNupkgDirectory(NuGetPackageId)
?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test.");
var nupkgDirectory = TestContext.Parameters["TestNupkgDirectory"]
?? TryAutoDetectTestNupkgDirectory(NuGetPackageId)
?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test.");
var nupkgVersion = TryGetTestNupkgVersion(nupkgDirectory, packageId: NuGetPackageId)
?? throw new InvalidOperationException($"No NuGet package with the ID {NuGetPackageId} was found in {nupkgDirectory}.");
var nupkgVersion = TryGetTestNupkgVersion(nupkgDirectory, packageId: NuGetPackageId)
?? throw new InvalidOperationException($"No NuGet package with the ID {NuGetPackageId} was found in {nupkgDirectory}.");
var keepWorkspaces = TestContext.Parameters.Get("KeepWorkspaces", defaultValue: false);
var keepWorkspaces = TestContext.Parameters.Get("KeepWorkspaces", defaultValue: false);
var packageCachePath = Path.Combine(directory, ".isolatednugetcache");
ClearCachedTestNupkgs(packageCachePath);
var packageCachePath = Path.Combine(directory, ".isolatednugetcache");
ClearCachedTestNupkgs(packageCachePath);
var manager = new IsolatedWorkspaceManager(
reason: string.Join(
Environment.NewLine,
"Test assembly: " + typeof(AcceptanceTests).Assembly.Location,
"Runner process: " + Process.GetCurrentProcess().MainModule.FileName),
directory,
nupkgDirectory,
packageCachePath,
downloadCachePath: Path.Combine(directory, ".toolcache"));
var manager = new IsolatedWorkspaceManager(
reason: string.Join(
Environment.NewLine,
"Test assembly: " + typeof(AcceptanceTests).Assembly.Location,
"Runner process: " + Process.GetCurrentProcess().MainModule.FileName),
directory,
nupkgDirectory,
packageCachePath,
downloadCachePath: Path.Combine(directory, ".toolcache"));
if (keepWorkspaces) manager.PreserveDirectory("The KeepWorkspaces test parameter was set to true.");
if (keepWorkspaces) manager.PreserveDirectory("The KeepWorkspaces test parameter was set to true.");
return (manager, nupkgVersion, keepWorkspaces);
});
return (manager, nupkgVersion, keepWorkspaces);
});

private static void ClearCachedTestNupkgs(string packageCachePath)
{
Utils.DeleteDirectoryRobust(Path.Combine(packageCachePath, NuGetPackageId));
}

private static readonly Dictionary<string, List<IsolatedWorkspace>> WorkspacesByTestId = new ();
private static readonly Dictionary<string, List<IsolatedWorkspace>> WorkspacesByTestId = new();

protected static IsolatedWorkspace CreateWorkspace()
{
var test = TestContext.CurrentContext?.Test ?? throw new InvalidOperationException("There is no current test.");

var workspace = Initialization.Value.manager.CreateWorkspace(test.Name);
const string chars = "=()!,~-";
string name = chars.Aggregate(test.Name, (current, ch) => current.Replace(ch, '_'));
var workspace = Initialization.Value.Manager.CreateWorkspace(name);

lock (WorkspacesByTestId)
{
if (!WorkspacesByTestId.TryGetValue(test.ID, out var workspaces))
WorkspacesByTestId.Add(test.ID, workspaces = new List<IsolatedWorkspace>());
workspaces.Add(workspace);
}

return workspace;
}

Expand Down Expand Up @@ -111,11 +121,11 @@ public static void TearDown()

if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
{
Initialization.Value.manager.PreserveDirectory(
Initialization.Value.Manager.PreserveDirectory(
test.FullName + " failed:" + Environment.NewLine
+ TestContext.CurrentContext.Result.Message.TrimEnd() + Environment.NewLine);
}
else if (!Initialization.Value.keepWorkspaces)
else if (!Initialization.Value.KeepWorkspaces)
{
foreach (var workspace in workspaces)
Utils.DeleteDirectoryRobust(workspace.Directory);
Expand All @@ -126,7 +136,7 @@ internal static void OnGlobalTeardown()
{
if (!Initialization.IsValueCreated) return;

Initialization.Value.manager.Dispose();
Initialization.Value.Manager.Dispose();
}

private static string TryAutoDetectProjectWorkspaceDirectory()
Expand All @@ -146,14 +156,17 @@ private static string TryAutoDetectTestNupkgDirectory(string packageId)
{
// Keep in sync with build.cake.

// Search for it
for (var directory = TestContext.CurrentContext.TestDirectory; directory != null; directory = Path.GetDirectoryName(directory))
{
var packagePath = Path.Combine(directory, "package");

try
{
if (Directory.EnumerateFiles(Path.Combine(directory, "package"), packageId + ".*.nupkg").Any())
{
return packagePath;
}
}
catch (DirectoryNotFoundException)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
{
Expand Down Expand Up @@ -49,11 +50,11 @@ public static void User_tests_get_the_version_of_Mono_Cecil_referenced_from_the_
}
}");

workspace.MSBuild(restore: true);
workspace.MsBuild(restore: true);

foreach (var targetFramework in TargetFrameworks)
{
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll");
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll", VsTestFilter.NoFilter);
}
}

Expand Down Expand Up @@ -127,11 +128,11 @@ public void OnTestEvent(string report)
.AddFile("test.addins", @"
Test.dll");

workspace.MSBuild(restore: true);
workspace.MsBuild(restore: true);

foreach (var targetFramework in TargetFrameworks)
{
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll");
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll", VsTestFilter.NoFilter);
}
}
}
Expand Down
53 changes: 53 additions & 0 deletions src/NUnit.TestAdapter.Tests.Acceptance/ConsoleOutTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
{
public sealed class ConsoleOutTests : CsProjAcceptanceTests
{
protected override void AddTestsCs(IsolatedWorkspace workspace)
{
workspace.AddFile("Issue774.cs", @"
using System;
using NUnit.Framework;
namespace Issue774
{
public class ConsoleOutTest
{
[Test]
public void Test1()
{
Console.WriteLine(); // Did not work pre-Issue774 fix
Assert.Pass();
}
[Test]
public void Test2()
{
Console.WriteLine(""Does work"");
Assert.Pass();
}
}
}");
}

protected override string Framework => Frameworks.NetCoreApp31;

[Test, Platform("Win")]
public void DotNetTest()
{
var workspace = Build();
var results = workspace.DotNetTest("", true, true, TestContext.WriteLine);
Verify(2, 2, results);
}

[Test, Platform("Win")]
public void VsTest()
{
var workspace = Build();
var results = workspace.VSTest($@"bin\Debug\{Framework}\Test.dll", VsTestFilter.NoFilter);
Verify(2, 2, results);
}
}
}
55 changes: 55 additions & 0 deletions src/NUnit.TestAdapter.Tests.Acceptance/CsProjAcceptanceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
{
public abstract class CsProjAcceptanceTests : AcceptanceTests
{
protected abstract void AddTestsCs(IsolatedWorkspace workspace);

protected abstract string Framework { get; }
protected const string NoFilter = "";
protected IsolatedWorkspace CreateTestWorkspace(string framework)
{
var workspace = CreateWorkspace()
.AddProject("Test.csproj", $@"
<Project Sdk='Microsoft.NET.Sdk'>
<PropertyGroup>
<TargetFramework>{framework}</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include='Microsoft.NET.Test.Sdk' Version='*' />
<PackageReference Include='NUnit' Version='*' />
<PackageReference Include='NUnit3TestAdapter' Version='{NuGetPackageVersion}' />
</ItemGroup>
</Project>");
return workspace;
}

protected IsolatedWorkspace Build()
{
var workspace = CreateTestWorkspace(Framework);
AddTestsCs(workspace);
workspace.MsBuild(restore: true);
return workspace;
}

protected void Verify(int executed, int total, VSTestResult results)
{
TestContext.WriteLine(" ");
foreach (var error in results.RunErrors)
TestContext.WriteLine(error);
Assert.Multiple(() =>
{
Assert.That(results.Counters.Total, Is.EqualTo(total),
$"Total tests counter did not match expectation\n{results.ProcessRunResult.StdOut}");
Assert.That(results.Counters.Executed, Is.EqualTo(executed),
"Executed tests counter did not match expectation");
Assert.That(results.Counters.Passed, Is.EqualTo(executed), "Passed tests counter did not match expectation");
});
}
}
}
Loading

0 comments on commit 0b118ec

Please sign in to comment.