Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare 4.2 #928

Merged
merged 29 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d323e2f
prepare 4.2
OsirisTerje Dec 12, 2021
6ab9ed3
Fix warning and set beta,2
OsirisTerje Dec 13, 2021
8f4c8ab
Adding more logging
OsirisTerje Dec 15, 2021
d33ea1b
filters added handling explicits
OsirisTerje Dec 16, 2021
e5565bd
small fixes
OsirisTerje Dec 17, 2021
18f57ec
Code cleanup
OsirisTerje Dec 17, 2021
775622c
beta.4
OsirisTerje Dec 17, 2021
5f0b8f8
Addind filter acceptance tests
OsirisTerje Dec 18, 2021
3c272fd
update with more logs
OsirisTerje Dec 18, 2021
00c55bc
Adding nunit.where tester
OsirisTerje Dec 19, 2021
5b62ebf
FIx warnings
OsirisTerje Dec 19, 2021
34ac272
Added more tests and added csproj base class to make it easier to mak…
OsirisTerje Dec 19, 2021
c602515
fix tests
OsirisTerje Dec 19, 2021
a5e7ba6
fix SA warnings
OsirisTerje Dec 19, 2021
a382d64
Oppdatert pakker o.a.
OsirisTerje Dec 20, 2021
180936f
Reanebled output of console message, introducing another ConsoleOut l…
OsirisTerje Dec 21, 2021
d186238
fixing linux errors
OsirisTerje Dec 22, 2021
57eb94f
Add consoletests
OsirisTerje Dec 22, 2021
49fd993
COnsole and propertytests
OsirisTerje Dec 22, 2021
8b910d5
naming fixed
OsirisTerje Dec 22, 2021
16365e9
fix
OsirisTerje Dec 22, 2021
5d6ab05
FIx namespaces
OsirisTerje Dec 22, 2021
454ef71
sa fix
OsirisTerje Dec 22, 2021
0cd27d1
sa fix
OsirisTerje Dec 22, 2021
044c27c
accentance tests, with parantheses issue
OsirisTerje Dec 23, 2021
ba66812
Fixing Issue #919
OsirisTerje Dec 26, 2021
7b9cb5e
fix braces
OsirisTerje Dec 26, 2021
f2d6448
fix braces
OsirisTerje Dec 26, 2021
d519fab
Version to 4.2.0
OsirisTerje Dec 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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