Skip to content

Commit 0b118ec

Browse files
authored
prepare 4.2 (#928)
* 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
1 parent c499397 commit 0b118ec

47 files changed

Lines changed: 986 additions & 234 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ csharp_space_between_square_brackets = false
172172
# Wrapping preferences
173173
csharp_preserve_single_line_blocks = true
174174
csharp_preserve_single_line_statements = true
175+
dotnet_diagnostic.SA1000.severity=silent
176+
dotnet_diagnostic.SA1518.severity=silent
175177

176178
#### Naming styles ####
177179
[*.{cs,vb}]

build.cake

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#tool vswhere&version=2.7.1
2-
#tool Microsoft.TestPlatform&version=16.11.0
1+
#tool vswhere&version=2.8.4
2+
#tool Microsoft.TestPlatform&version=17.0.0
33

44
//////////////////////////////////////////////////////////////////////
55
// ARGUMENTS
@@ -13,7 +13,7 @@ var configuration = Argument("configuration", "Release");
1313
//////////////////////////////////////////////////////////////////////
1414

1515
var version = "4.2.0";
16-
var modifier = "-alpha.4";
16+
var modifier = "";
1717

1818
var dbgSuffix = configuration.ToLower() == "debug" ? "-dbg" : "";
1919
var packageVersion = version + modifier + dbgSuffix;

nuget/NUnit3TestAdapter.nuspec

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,19 @@
33
<metadata>
44
<id>NUnit3TestAdapter</id>
55
<version>$version$</version>
6-
<title>NUnit 3 Test Adapter for Visual Studio and DotNet</title>
6+
<title>NUnit3 Test Adapter for Visual Studio and DotNet</title>
77
<authors>Charlie Poole, Terje Sandstrom</authors>
88
<license type="expression">MIT</license>
99
<projectUrl>https://docs.nunit.org/articles/vs-test-adapter/Index.html</projectUrl>
1010
<repository type="git" url="https://github.com/nunit/nunit3-vs-adapter"/>
1111
<iconUrl>https://cdn.rawgit.com/nunit/resources/master/images/icon/nunit_256.png</iconUrl>
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
13-
<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>
13+
<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>
1414
<description>
1515
The NUnit3 TestAdapter for Visual Studio, all versions from 2012 and onwards, and DotNet (incl. .Net core).
1616

1717
Note that this package ONLY contains the adapter, not the NUnit framework.
1818
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.)
19-
20-
Note that with this package you should not install the VSIX adapter package.
2119
</description>
2220
<releaseNotes>See https://docs.nunit.org/articles/vs-test-adapter/Adapter-Release-Notes.html </releaseNotes>
2321
<copyright>Copyright (c) 2011-2021 Charlie Poole, 2014-2021 Terje Sandstrom</copyright>

src/Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.66" PrivateAssets="all" />
12+
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.376" PrivateAssets="all" />
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" />
16+
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
1717
<PackageReference Include="jnm2.ReferenceAssemblies.net35" Version="1.0.1" />
1818
</ItemGroup>
1919

src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,87 +3,97 @@
33
using System.Diagnostics;
44
using System.IO;
55
using System.Linq;
6+
67
using NUnit.Framework;
78
using NUnit.Framework.Interfaces;
89
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;
910

1011
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
1112
{
13+
public class Frameworks
14+
{
15+
public const string NetCoreApp31 = "netcoreapp3.1";
16+
public const string NetCoreApp21 = "netcoreapp2.1";
17+
public const string Net50 = "net5.0";
18+
public const string Net60 = "net6.0";
19+
}
20+
1221
[Category("Acceptance")]
1322
public abstract class AcceptanceTests
1423
{
15-
public static string NuGetPackageId { get; } = "NUnit3TestAdapter";
24+
public static string NuGetPackageId => "NUnit3TestAdapter";
1625

17-
public static string NuGetPackageVersion => Initialization.Value.nupkgVersion;
26+
public static string NuGetPackageVersion => Initialization.Value.NupkgVersion;
1827

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

2231
public static IEnumerable<string> TargetFrameworks => new[]
2332
{
2433
LowestNetfxTarget,
25-
"netcoreapp2.1"
34+
Frameworks.NetCoreApp21
2635
};
2736

2837
public static IEnumerable<string> DotNetCliTargetFrameworks => new[]
2938
{
30-
"netcoreapp2.1",
31-
"netcoreapp3.1"
39+
Frameworks.NetCoreApp21,
40+
Frameworks.NetCoreApp31,
41+
Frameworks.Net50
3242
};
3343

34-
private static readonly Lazy<(IsolatedWorkspaceManager manager, string nupkgVersion, bool keepWorkspaces)> Initialization = new (() =>
35-
{
36-
var directory = TestContext.Parameters["ProjectWorkspaceDirectory"]
37-
?? TryAutoDetectProjectWorkspaceDirectory()
38-
?? throw new InvalidOperationException("The test parameter ProjectWorkspaceDirectory must be set in order to run this test.");
44+
private static readonly Lazy<(IsolatedWorkspaceManager Manager, string NupkgVersion, bool KeepWorkspaces)> Initialization = new(() =>
45+
{
46+
var directory = TestContext.Parameters["ProjectWorkspaceDirectory"]
47+
?? TryAutoDetectProjectWorkspaceDirectory()
48+
?? throw new InvalidOperationException("The test parameter ProjectWorkspaceDirectory must be set in order to run this test.");
3949

40-
var nupkgDirectory = TestContext.Parameters["TestNupkgDirectory"]
41-
?? TryAutoDetectTestNupkgDirectory(NuGetPackageId)
42-
?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test.");
50+
var nupkgDirectory = TestContext.Parameters["TestNupkgDirectory"]
51+
?? TryAutoDetectTestNupkgDirectory(NuGetPackageId)
52+
?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test.");
4353

44-
var nupkgVersion = TryGetTestNupkgVersion(nupkgDirectory, packageId: NuGetPackageId)
45-
?? throw new InvalidOperationException($"No NuGet package with the ID {NuGetPackageId} was found in {nupkgDirectory}.");
54+
var nupkgVersion = TryGetTestNupkgVersion(nupkgDirectory, packageId: NuGetPackageId)
55+
?? throw new InvalidOperationException($"No NuGet package with the ID {NuGetPackageId} was found in {nupkgDirectory}.");
4656

47-
var keepWorkspaces = TestContext.Parameters.Get("KeepWorkspaces", defaultValue: false);
57+
var keepWorkspaces = TestContext.Parameters.Get("KeepWorkspaces", defaultValue: false);
4858

49-
var packageCachePath = Path.Combine(directory, ".isolatednugetcache");
50-
ClearCachedTestNupkgs(packageCachePath);
59+
var packageCachePath = Path.Combine(directory, ".isolatednugetcache");
60+
ClearCachedTestNupkgs(packageCachePath);
5161

52-
var manager = new IsolatedWorkspaceManager(
53-
reason: string.Join(
54-
Environment.NewLine,
55-
"Test assembly: " + typeof(AcceptanceTests).Assembly.Location,
56-
"Runner process: " + Process.GetCurrentProcess().MainModule.FileName),
57-
directory,
58-
nupkgDirectory,
59-
packageCachePath,
60-
downloadCachePath: Path.Combine(directory, ".toolcache"));
62+
var manager = new IsolatedWorkspaceManager(
63+
reason: string.Join(
64+
Environment.NewLine,
65+
"Test assembly: " + typeof(AcceptanceTests).Assembly.Location,
66+
"Runner process: " + Process.GetCurrentProcess().MainModule.FileName),
67+
directory,
68+
nupkgDirectory,
69+
packageCachePath,
70+
downloadCachePath: Path.Combine(directory, ".toolcache"));
6171

62-
if (keepWorkspaces) manager.PreserveDirectory("The KeepWorkspaces test parameter was set to true.");
72+
if (keepWorkspaces) manager.PreserveDirectory("The KeepWorkspaces test parameter was set to true.");
6373

64-
return (manager, nupkgVersion, keepWorkspaces);
65-
});
74+
return (manager, nupkgVersion, keepWorkspaces);
75+
});
6676

6777
private static void ClearCachedTestNupkgs(string packageCachePath)
6878
{
6979
Utils.DeleteDirectoryRobust(Path.Combine(packageCachePath, NuGetPackageId));
7080
}
7181

72-
private static readonly Dictionary<string, List<IsolatedWorkspace>> WorkspacesByTestId = new ();
82+
private static readonly Dictionary<string, List<IsolatedWorkspace>> WorkspacesByTestId = new();
7383

7484
protected static IsolatedWorkspace CreateWorkspace()
7585
{
7686
var test = TestContext.CurrentContext?.Test ?? throw new InvalidOperationException("There is no current test.");
77-
78-
var workspace = Initialization.Value.manager.CreateWorkspace(test.Name);
87+
const string chars = "=()!,~-";
88+
string name = chars.Aggregate(test.Name, (current, ch) => current.Replace(ch, '_'));
89+
var workspace = Initialization.Value.Manager.CreateWorkspace(name);
7990

8091
lock (WorkspacesByTestId)
8192
{
8293
if (!WorkspacesByTestId.TryGetValue(test.ID, out var workspaces))
8394
WorkspacesByTestId.Add(test.ID, workspaces = new List<IsolatedWorkspace>());
8495
workspaces.Add(workspace);
8596
}
86-
8797
return workspace;
8898
}
8999

@@ -111,11 +121,11 @@ public static void TearDown()
111121

112122
if (TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
113123
{
114-
Initialization.Value.manager.PreserveDirectory(
124+
Initialization.Value.Manager.PreserveDirectory(
115125
test.FullName + " failed:" + Environment.NewLine
116126
+ TestContext.CurrentContext.Result.Message.TrimEnd() + Environment.NewLine);
117127
}
118-
else if (!Initialization.Value.keepWorkspaces)
128+
else if (!Initialization.Value.KeepWorkspaces)
119129
{
120130
foreach (var workspace in workspaces)
121131
Utils.DeleteDirectoryRobust(workspace.Directory);
@@ -126,7 +136,7 @@ internal static void OnGlobalTeardown()
126136
{
127137
if (!Initialization.IsValueCreated) return;
128138

129-
Initialization.Value.manager.Dispose();
139+
Initialization.Value.Manager.Dispose();
130140
}
131141

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

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

153164
try
154165
{
155166
if (Directory.EnumerateFiles(Path.Combine(directory, "package"), packageId + ".*.nupkg").Any())
167+
{
156168
return packagePath;
169+
}
157170
}
158171
catch (DirectoryNotFoundException)
159172
{

src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using NUnit.Framework;
2+
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;
23

34
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
45
{
@@ -49,11 +50,11 @@ public static void User_tests_get_the_version_of_Mono_Cecil_referenced_from_the_
4950
}
5051
}");
5152

52-
workspace.MSBuild(restore: true);
53+
workspace.MsBuild(restore: true);
5354

5455
foreach (var targetFramework in TargetFrameworks)
5556
{
56-
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll");
57+
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll", VsTestFilter.NoFilter);
5758
}
5859
}
5960

@@ -127,11 +128,11 @@ public void OnTestEvent(string report)
127128
.AddFile("test.addins", @"
128129
Test.dll");
129130

130-
workspace.MSBuild(restore: true);
131+
workspace.MsBuild(restore: true);
131132

132133
foreach (var targetFramework in TargetFrameworks)
133134
{
134-
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll");
135+
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll", VsTestFilter.NoFilter);
135136
}
136137
}
137138
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using NUnit.Framework;
2+
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;
3+
4+
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
5+
{
6+
public sealed class ConsoleOutTests : CsProjAcceptanceTests
7+
{
8+
protected override void AddTestsCs(IsolatedWorkspace workspace)
9+
{
10+
workspace.AddFile("Issue774.cs", @"
11+
using System;
12+
using NUnit.Framework;
13+
14+
namespace Issue774
15+
{
16+
public class ConsoleOutTest
17+
{
18+
[Test]
19+
public void Test1()
20+
{
21+
Console.WriteLine(); // Did not work pre-Issue774 fix
22+
Assert.Pass();
23+
}
24+
25+
[Test]
26+
public void Test2()
27+
{
28+
Console.WriteLine(""Does work"");
29+
Assert.Pass();
30+
}
31+
}
32+
}");
33+
}
34+
35+
protected override string Framework => Frameworks.NetCoreApp31;
36+
37+
[Test, Platform("Win")]
38+
public void DotNetTest()
39+
{
40+
var workspace = Build();
41+
var results = workspace.DotNetTest("", true, true, TestContext.WriteLine);
42+
Verify(2, 2, results);
43+
}
44+
45+
[Test, Platform("Win")]
46+
public void VsTest()
47+
{
48+
var workspace = Build();
49+
var results = workspace.VSTest($@"bin\Debug\{Framework}\Test.dll", VsTestFilter.NoFilter);
50+
Verify(2, 2, results);
51+
}
52+
}
53+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using NUnit.Framework;
2+
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;
3+
4+
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
5+
{
6+
public abstract class CsProjAcceptanceTests : AcceptanceTests
7+
{
8+
protected abstract void AddTestsCs(IsolatedWorkspace workspace);
9+
10+
protected abstract string Framework { get; }
11+
protected const string NoFilter = "";
12+
protected IsolatedWorkspace CreateTestWorkspace(string framework)
13+
{
14+
var workspace = CreateWorkspace()
15+
.AddProject("Test.csproj", $@"
16+
<Project Sdk='Microsoft.NET.Sdk'>
17+
18+
<PropertyGroup>
19+
<TargetFramework>{framework}</TargetFramework>
20+
</PropertyGroup>
21+
22+
<ItemGroup>
23+
<PackageReference Include='Microsoft.NET.Test.Sdk' Version='*' />
24+
<PackageReference Include='NUnit' Version='*' />
25+
<PackageReference Include='NUnit3TestAdapter' Version='{NuGetPackageVersion}' />
26+
</ItemGroup>
27+
28+
</Project>");
29+
return workspace;
30+
}
31+
32+
protected IsolatedWorkspace Build()
33+
{
34+
var workspace = CreateTestWorkspace(Framework);
35+
AddTestsCs(workspace);
36+
workspace.MsBuild(restore: true);
37+
return workspace;
38+
}
39+
40+
protected void Verify(int executed, int total, VSTestResult results)
41+
{
42+
TestContext.WriteLine(" ");
43+
foreach (var error in results.RunErrors)
44+
TestContext.WriteLine(error);
45+
Assert.Multiple(() =>
46+
{
47+
Assert.That(results.Counters.Total, Is.EqualTo(total),
48+
$"Total tests counter did not match expectation\n{results.ProcessRunResult.StdOut}");
49+
Assert.That(results.Counters.Executed, Is.EqualTo(executed),
50+
"Executed tests counter did not match expectation");
51+
Assert.That(results.Counters.Passed, Is.EqualTo(executed), "Passed tests counter did not match expectation");
52+
});
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)