Skip to content

Commit

Permalink
Updates packages (#1164)
Browse files Browse the repository at this point in the history
* Updated nunit and corrected tests.  netcore tests uses 3.14 and net462 uses 4.1

* Update test.sdk to 17.9.0

* Warning cleanup

* Removed more warnings, converted to filebased namespaces
  • Loading branch information
OsirisTerje authored Apr 10, 2024
1 parent 957c129 commit f9b355a
Show file tree
Hide file tree
Showing 126 changed files with 9,537 additions and 9,799 deletions.
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<AssemblyOriginatorKeyFile>..\NUnitAdapter.snk</AssemblyOriginatorKeyFile>
<CodeAnalysisRuleSet>..\..\Osiris.Extended.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors Condition="'$(Configuration)' == 'Release'">true</TreatWarningsAsErrors>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>

<ItemGroup>
Expand Down
427 changes: 213 additions & 214 deletions src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using NUnit.Framework;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance;

// https://github.com/nunit/nunit/issues/3166
[SetUpFixture]
public sealed class AcceptanceTestsTeardownFixture
{
// https://github.com/nunit/nunit/issues/3166
[SetUpFixture]
public sealed class AcceptanceTestsTeardownFixture
[OneTimeTearDown]
public static void OneTimeTearDown()
{
[OneTimeTearDown]
public static void OneTimeTearDown()
{
AcceptanceTests.OnGlobalTeardown();
}
AcceptanceTests.OnGlobalTeardown();
}
}
}
53 changes: 26 additions & 27 deletions src/NUnit.TestAdapter.Tests.Acceptance/BundledDependencyTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance;

public sealed class BundledDependencyTests : AcceptanceTests
{
public sealed class BundledDependencyTests : AcceptanceTests
[Test, Platform("Win")]
public static void User_tests_get_the_version_of_Mono_Cecil_referenced_from_the_test_project()
{
[Test, Platform("Win")]
public static void User_tests_get_the_version_of_Mono_Cecil_referenced_from_the_test_project()
{
var workspace = CreateWorkspace()
.AddProject("Test.csproj", $@"
var workspace = CreateWorkspace()
.AddProject("Test.csproj", $@"
<Project Sdk='Microsoft.NET.Sdk'>
<PropertyGroup>
Expand All @@ -28,7 +28,7 @@ public static void User_tests_get_the_version_of_Mono_Cecil_referenced_from_the_
</ItemGroup>
</Project>")
.AddFile("BundledDependencyTests.cs", @"
.AddFile("BundledDependencyTests.cs", @"
using System.Diagnostics;
using System.Reflection;
using NUnit.Framework;
Expand All @@ -50,19 +50,19 @@ 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", VsTestFilter.NoFilter);
}
foreach (var targetFramework in TargetFrameworks)
{
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll", VsTestFilter.NoFilter);
}
}

[Test, Platform("Win")]
public static void Engine_uses_its_bundled_version_of_Mono_Cecil_instead_of_the_version_referenced_by_the_test_project()
{
var workspace = CreateWorkspace()
.AddProject("Test.csproj", $@"
[Test, Platform("Win")]
public static void Engine_uses_its_bundled_version_of_Mono_Cecil_instead_of_the_version_referenced_by_the_test_project()
{
var workspace = CreateWorkspace()
.AddProject("Test.csproj", $@"
<Project Sdk='Microsoft.NET.Sdk'>
<PropertyGroup>
Expand All @@ -89,7 +89,7 @@ public static void Engine_uses_its_bundled_version_of_Mono_Cecil_instead_of_the_
</ItemGroup>
</Project>")
.AddFile("BundledDependencyTests.cs", @"
.AddFile("BundledDependencyTests.cs", @"
using System.Diagnostics;
using System.Reflection;
using NUnit.Framework;
Expand All @@ -110,7 +110,7 @@ public void Engine_uses_its_bundled_version_of_Mono_Cecil_instead_of_the_version
Assert.That(versionBlock.ProductVersion, Is.EqualTo(""0.10.0.0""));
}
}")
.AddFile("TestNUnitEngineExtension.cs", @"
.AddFile("TestNUnitEngineExtension.cs", @"
using NUnit.Engine;
using NUnit.Engine.Extensibility;
Expand All @@ -125,15 +125,14 @@ public void OnTestEvent(string report)
{
}
}")
.AddFile("test.addins", @"
.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", VsTestFilter.NoFilter);
}
foreach (var targetFramework in TargetFrameworks)
{
workspace.VSTest($@"bin\Debug\{targetFramework}\Test.dll", VsTestFilter.NoFilter);
}
}
}
}
23 changes: 11 additions & 12 deletions src/NUnit.TestAdapter.Tests.Acceptance/ConsoleOutTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using NUnit.Framework;
using NUnit.VisualStudio.TestAdapter.Tests.Acceptance.WorkspaceTools;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance;

public sealed class ConsoleOutTests : CsProjAcceptanceTests
{
public sealed class ConsoleOutTests : CsProjAcceptanceTests
protected override void AddTestsCs(IsolatedWorkspace workspace)
{
protected override void AddTestsCs(IsolatedWorkspace workspace)
{
workspace.AddFile("Issue774.cs", @"
using System;
using NUnit.Framework;
Expand All @@ -32,22 +32,21 @@ public void Test2()
}");
}

protected override string Framework => Frameworks.NetCoreApp31;
protected override string Framework => Frameworks.NetCoreApp31;

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

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance;

public abstract class CsProjAcceptanceTests : AcceptanceTests
{
public abstract class CsProjAcceptanceTests : AcceptanceTests
{
protected abstract void AddTestsCs(IsolatedWorkspace workspace);
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", $@"
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>
Expand All @@ -26,30 +26,29 @@ protected IsolatedWorkspace CreateTestWorkspace(string framework)
</ItemGroup>
</Project>");
return workspace;
}
return workspace;
}

protected IsolatedWorkspace Build()
{
var workspace = CreateTestWorkspace(Framework);
AddTestsCs(workspace);
workspace.MsBuild(restore: true);
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)
protected void Verify(int executed, int total, VSTestResult results)
{
TestContext.WriteLine(" ");
foreach (var error in results.RunErrors)
TestContext.WriteLine(error);
Assert.Multiple(() =>
{
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");
});
}
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");
});
}
}
}
47 changes: 23 additions & 24 deletions src/NUnit.TestAdapter.Tests.Acceptance/DirectoryMutex.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
using System;
using System.IO;

namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance
namespace NUnit.VisualStudio.TestAdapter.Tests.Acceptance;

public sealed class DirectoryMutex : IDisposable
{
public sealed class DirectoryMutex : IDisposable
private readonly FileStream mutexFile;

public static DirectoryMutex TryAcquire(string directoryPath)
{
private readonly FileStream mutexFile;
var mutexFilePath = Path.Combine(directoryPath, ".mutex");

public static DirectoryMutex TryAcquire(string directoryPath)
FileStream stream;
try
{
var mutexFilePath = Path.Combine(directoryPath, ".mutex");

FileStream stream;
try
{
stream = new FileStream(mutexFilePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 1, FileOptions.DeleteOnClose);
}
catch (IOException) // On Windows, (ushort)ex.HResult will be ERROR_SHARING_VIOLATION
{
return null;
}

return new DirectoryMutex(stream, directoryPath);
stream = new FileStream(mutexFilePath, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 1, FileOptions.DeleteOnClose);
}

private DirectoryMutex(FileStream mutexFile, string directoryPath)
catch (IOException) // On Windows, (ushort)ex.HResult will be ERROR_SHARING_VIOLATION
{
this.mutexFile = mutexFile ?? throw new ArgumentNullException(nameof(mutexFile));
DirectoryPath = directoryPath ?? throw new ArgumentNullException(nameof(directoryPath));
return null;
}

public string DirectoryPath { get; }
return new DirectoryMutex(stream, directoryPath);
}

public void Dispose() => mutexFile.Dispose();
private DirectoryMutex(FileStream mutexFile, string directoryPath)
{
this.mutexFile = mutexFile ?? throw new ArgumentNullException(nameof(mutexFile));
DirectoryPath = directoryPath ?? throw new ArgumentNullException(nameof(directoryPath));
}
}

public string DirectoryPath { get; }

public void Dispose() => mutexFile.Dispose();
}
Loading

0 comments on commit f9b355a

Please sign in to comment.