Skip to content

Commit

Permalink
Merge pull request #1206 from nunit/cpm
Browse files Browse the repository at this point in the history
Change to Central Package Management
  • Loading branch information
OsirisTerje committed Aug 27, 2024
2 parents f236efb + c526f48 commit 80ace95
Show file tree
Hide file tree
Showing 33 changed files with 177 additions and 114 deletions.
33 changes: 33 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>false</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>

<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
<PackageVersion Include="nunit" Version="4.2.1" />
<PackageVersion Include="nunit.engine" Version="3.18.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="SourceLink.Create.CommandLine" Version="2.8.3" />
<PackageVersion Include="TestCentric.Metadata" Version="3.0.2" />
<PackageVersion Include="Microsoft.TestPlatform.ObjectModel" Version="17.11.0" PrivateAssets="All"/>
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Castle.Core" Version="5.1.1" />
</ItemGroup>

<ItemGroup>
<GlobalPackageReference Include="NUnit.Analyzers" Version="4.3.0" >
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</GlobalPackageReference>
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />

<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions NUnit3TestAdapter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
build.cmd = build.cmd
build.ps1 = build.ps1
src\Directory.Build.props = src\Directory.Build.props
Directory.Packages.props = Directory.Packages.props
DisableAppDomain.runsettings = DisableAppDomain.runsettings
LICENSE = LICENSE
src\native-assembly\NativeTests.dll = src\native-assembly\NativeTests.dll
Expand Down
7 changes: 0 additions & 7 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,4 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
</ItemGroup>
</Project>
60 changes: 31 additions & 29 deletions src/NUnit.TestAdapter.Tests.Acceptance/AcceptanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,26 @@ public abstract class AcceptanceTests
public const string LowestNetfxTarget = "net462";
public const string LegacyProjectTargetFrameworkVersion = "v4.6.2";

protected static IEnumerable<string> TargetFrameworks => new[]
{
protected static IEnumerable<string> TargetFrameworks =>
[
LowestNetfxTarget,
Frameworks.NetCoreApp31
};
];

protected static IEnumerable<string> DotNetCliTargetFrameworks => new[]
{
protected static IEnumerable<string> DotNetCliTargetFrameworks =>
[
Frameworks.NetCoreApp31,
Frameworks.Net50,
Frameworks.Net60,
Frameworks.Net70
};
];

protected static IEnumerable<string> ModernDotNetCliTargetFrameworks => new[]
{
protected static IEnumerable<string> ModernDotNetCliTargetFrameworks =>
[
Frameworks.Net60,
Frameworks.Net70,
Frameworks.Net80
};
];

protected static string NUnit3 => "3.*";
protected static string NUnit4 => "4.*";
Expand All @@ -58,25 +58,25 @@ public class MultiFrameworkSource
public IEnumerable<string> Frameworks { get; set; } = DotNetCliTargetFrameworks;
public string NUnitVersion { get; set; } = NUnit3;

public static IEnumerable<MultiFrameworkSource> LegacyDotNetFrameworks => new List<MultiFrameworkSource> { new() };
public static IEnumerable<MultiFrameworkSource> LegacyDotNetFrameworks => [new()];

public static IEnumerable<MultiFrameworkSource> ModernDotNetFrameworks => new List<MultiFrameworkSource>
{
public static IEnumerable<MultiFrameworkSource> ModernDotNetFrameworks =>
[
new ()
{
Frameworks = ModernDotNetCliTargetFrameworks,
NUnitVersion = NUnit4
}
};
];

public static IEnumerable<MultiFrameworkSource> NetFxFrameworks => new List<MultiFrameworkSource>
{
public static IEnumerable<MultiFrameworkSource> NetFxFrameworks =>
[
new ()
{
Frameworks = new List<string> { LowestNetfxTarget },
Frameworks = [LowestNetfxTarget],
NUnitVersion = NUnit4
}
};
];

public static IEnumerable<MultiFrameworkSource> AllFrameworks => LegacyDotNetFrameworks.Concat(ModernDotNetFrameworks).Concat(NetFxFrameworks);
}
Expand All @@ -86,10 +86,10 @@ public class SingleFrameworkSource
public string Framework { get; set; } = LowestNetfxTarget;
public string NUnitVersion { get; set; } = NUnit4;

public static IEnumerable<SingleFrameworkSource> NetFxFramework => new List<SingleFrameworkSource> { new() };
public static IEnumerable<SingleFrameworkSource> NetFxFramework => [new()];

public static IEnumerable<SingleFrameworkSource> LegacyDotNetFramework => new List<SingleFrameworkSource>
{
public static IEnumerable<SingleFrameworkSource> LegacyDotNetFramework =>
[
new ()
{
Framework = Frameworks.NetCoreApp31,
Expand All @@ -100,10 +100,10 @@ public class SingleFrameworkSource
Framework = Frameworks.Net50,
NUnitVersion = NUnit3
}
};
];

public static IEnumerable<SingleFrameworkSource> ModernDotNetFramework => new List<SingleFrameworkSource>
{
public static IEnumerable<SingleFrameworkSource> ModernDotNetFramework =>
[
new ()
{
Framework = Frameworks.Net60,
Expand All @@ -119,7 +119,7 @@ public class SingleFrameworkSource
Framework = Frameworks.Net80,
NUnitVersion = NUnit4
}
};
];

public static IEnumerable<SingleFrameworkSource> AllFrameworks => NetFxFramework.Concat(LegacyDotNetFramework).Concat(ModernDotNetFramework);
public static IEnumerable<SingleFrameworkSource> AllFrameworksExceptNetFx => LegacyDotNetFramework.Concat(ModernDotNetFramework);
Expand All @@ -136,12 +136,12 @@ protected string NUnitVersion(string targetFramework) =>
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.");
?? TryAutoDetectProjectWorkspaceDirectory() // Walks the directory tree up to find the project workspace directory, named ".acceptance"
?? throw new InvalidOperationException("Either The test parameter ProjectWorkspaceDirectory must be set in order to run this test, or the `.acceptance` folder has not been found. Run cmd line `build -t acceptance` first");
var nupkgDirectory = TestContext.Parameters["TestNupkgDirectory"]
?? TryAutoDetectTestNupkgDirectory(NuGetPackageId)
?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test.");
?? TryAutoDetectTestNupkgDirectory(NuGetPackageId) // Walks the directory tree up to find the test nupkg directory, named "package"
?? throw new InvalidOperationException("The test parameter TestNupkgDirectory must be set in order to run this test, or the packages have not been created, run cmdline `build -t package` first");
var nupkgVersion = TryGetTestNupkgVersion(nupkgDirectory, packageId: NuGetPackageId)
?? throw new InvalidOperationException($"No NuGet package with the ID {NuGetPackageId} was found in {nupkgDirectory}.");
Expand All @@ -162,7 +162,7 @@ protected string NUnitVersion(string targetFramework) =>
downloadCachePath: Path.Combine(directory, ".toolcache"));
if (keepWorkspaces) manager.PreserveDirectory("The KeepWorkspaces test parameter was set to true.");
TestContext.WriteLine($"Directory: {directory}, NugetPackageDirectory {nupkgDirectory},NugetPackageVersion: {nupkgVersion}");
TestContext.Out.WriteLine($"Directory: {directory}, NugetPackageDirectory {nupkgDirectory},NugetPackageVersion: {nupkgVersion}");
return (manager, nupkgVersion, keepWorkspaces);
});

Expand Down Expand Up @@ -224,7 +224,9 @@ public static void TearDown()
}
}

#pragma warning disable NUnit1028 // The non-test method is public
internal static void OnGlobalTeardown()
#pragma warning restore NUnit1028 // The non-test method is public
{
if (!Initialization.IsValueCreated) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static void User_tests_get_the_version_of_Mono_Cecil_referenced_from_the_
<PropertyGroup>
<TargetFrameworks>{string.Join(";", TargetFrameworks)}</TargetFrameworks>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally><Deterministic>false</Deterministic>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -67,6 +68,7 @@ public static void Engine_uses_its_bundled_version_of_Mono_Cecil_instead_of_the_
<PropertyGroup>
<TargetFrameworks>{string.Join(";", TargetFrameworks)}</TargetFrameworks>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally><Deterministic>false</Deterministic>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected IsolatedWorkspace CreateTestWorkspace(string framework)
<PropertyGroup>
<TargetFramework>{framework}</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally><Deterministic>false</Deterministic>
</PropertyGroup>
<ItemGroup>
Expand All @@ -39,9 +40,9 @@ protected IsolatedWorkspace Build()

protected void Verify(int executed, int total, VSTestResult results)
{
TestContext.WriteLine(" ");
TestContext.Out.WriteLine(" ");
foreach (var error in results.RunErrors)
TestContext.WriteLine(error);
TestContext.Out.WriteLine(error);
Assert.Multiple(() =>
{
Assert.That(results.Counters.Total, Is.EqualTo(total),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="nunit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="nunit" />
<PackageReference Include="NUnit3TestAdapter" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/NUnit.TestAdapter.Tests.Acceptance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# How to run the acceptance tests

## Running the tests by command line

```cmd
build -t acceptance
```

This will build and package the test adapter and run the acceptance tests.

## Running the tests in Visual Studio

You can also run the acceptance tests in Visual Studio.
To do this, open the solution in Visual Studio and run the `NUnit.TestAdapter.Tests.Acceptance` Tests from the Test Explorer.

Note: Running the acceptance tests in Visual Studio require that the package are built and packaged on commandline before running the tests.
This will create the `.acceptance` directory and add the package to the `package` directory.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private IsolatedWorkspace CreateSingleTargetWorkspace(string fileName, SingleFra
<PropertyGroup>
<TargetFramework>{source.Framework}</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -105,6 +106,7 @@ private IsolatedWorkspace CreateMultiTargetWorkspace(string fileName, MultiFrame
<PropertyGroup>
<TargetFrameworks>{string.Join(";", source.Frameworks)}</TargetFrameworks>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
Expand Down Expand Up @@ -181,6 +183,7 @@ public void Legacy_csproj_with_PackageReference()
<TargetFrameworkVersion>{LegacyProjectTargetFrameworkVersion}</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally><Deterministic>false</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -251,6 +254,7 @@ public void Legacy_vbproj_with_PackageReference()
<MyType>Windows</MyType>
<TargetFrameworkVersion>{LegacyProjectTargetFrameworkVersion}</TargetFrameworkVersion>
<Deterministic>true</Deterministic>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally><Deterministic>false</Deterministic>
</PropertyGroup>
<PropertyGroup Condition="" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ public static void Single_target_csproj(SingleFrameworkSource source)
<ItemGroup>
<Reference Include=""System.ValueTuple"" />
</ItemGroup>" : "";
TestContext.WriteLine($"Testing {source.Framework}");
TestContext.Out.WriteLine($"Testing {source.Framework}");
var workspace = CreateWorkspace()
.AddProject("Test.csproj", $@"
<Project Sdk='Microsoft.NET.Sdk'>
<PropertyGroup>
<TargetFramework>{source.Framework}</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally><Deterministic>false</Deterministic>
</PropertyGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/NUnit.TestAdapter.Tests.Acceptance/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void DeleteDirectoryRobust(string directory)
}
catch (IOException ex) when (attempt < 3 && (WinErrorCode)ex.HResult == WinErrorCode.DirNotEmpty)
{
TestContext.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying...");
TestContext.Out.WriteLine("Another process added files to the directory while its contents were being deleted. Retrying...");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@


<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit" VersionOverride="3.14.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/NUnitTestAdapter/CategoryList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class CategoryList

private readonly NUnitProperty explicitTrait = new (ExplicitTraitName, ExplicitTraitValue);

private readonly List<string> categorylist = new ();
private readonly List<string> categorylist = [];
private readonly TestCase testCase;
private readonly IAdapterSettings settings;
private readonly bool showInternalProperties;
Expand Down
10 changes: 5 additions & 5 deletions src/NUnitTestAdapter/NUnit.TestAdapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.3" PrivateAssets="All" />
<PackageReference Include="nunit.engine" Version="3.18.1" />
<PackageReference Include="TestCentric.Metadata" Version="3.0.2" Aliases="TestCentric" />
<PackageReference Include="SourceLink.Create.CommandLine" PrivateAssets="All" />
<PackageReference Include="nunit.engine" />
<PackageReference Include="TestCentric.Metadata" Aliases="TestCentric" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="11.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" VersionOverride="11.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="15.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" VersionOverride="15.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/NUnitTestAdapter/NUnitEngine/DiscoveryConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal static class NUnitXmlAttributeNames

public bool HasExplicitTests => NoOfExplicitTestCases > 0;

private readonly List<TestCase> loadedTestCases = new();
private readonly List<TestCase> loadedTestCases = [];
public IList<TestCase> LoadedTestCases => loadedTestCases;

public int NoOfLoadedTestCases => loadedTestCases.Count;
Expand Down Expand Up @@ -134,7 +134,7 @@ public IEnumerable<TestCase> GetExplicitTestCases(IEnumerable<TestCase> filtered
public IList<TestCase> Convert(NUnitResults discoveryResults, string assemblyPath)
{
if (discoveryResults == null)
return new List<TestCase>();
return [];
AssemblyPath = assemblyPath;
var timing = new TimingLogger(Settings, TestLog);
if (Settings.DiscoveryMethod != DiscoveryMethod.Legacy)
Expand Down
Loading

0 comments on commit 80ace95

Please sign in to comment.