Skip to content

Commit

Permalink
AllRegistries TestCaseSource
Browse files Browse the repository at this point in the history
  • Loading branch information
Thaina committed Dec 11, 2024
1 parent 5fc0af7 commit 9a86758
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 233 deletions.
248 changes: 124 additions & 124 deletions src/UnityNuGet.Tests/PlatformDefinitionTests.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;

namespace UnityNuGet.Tests
{
public class PlatformDefinitionTests
{
[Test]
public void CanFindDefinitions()
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();

// Look-up by OS should return the most general configuration
PlatformDefinition? win = platformDefs.Find(UnityOs.Windows);
Assert.That(win, Is.Not.Null);
Assert.That(win!.Cpu, Is.EqualTo(UnityCpu.AnyCpu));

// Look-up explicit configuration
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NUnit.Framework;

namespace UnityNuGet.Tests
{
public class PlatformDefinitionTests
{
[Test]
public void CanFindDefinitions()
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();

// Look-up by OS should return the most general configuration
PlatformDefinition? win = platformDefs.Find(UnityOs.Windows);
Assert.That(win, Is.Not.Null);
Assert.That(win!.Cpu, Is.EqualTo(UnityCpu.AnyCpu));

// Look-up explicit configuration
PlatformDefinition? win64 = platformDefs.Find(UnityOs.Windows, UnityCpu.X64);
Assert.Multiple(() =>
{
Expand All @@ -29,116 +29,116 @@ public void CanFindDefinitions()
{
Assert.That(win64?.Cpu, Is.EqualTo(UnityCpu.X64));
Assert.That(win.Children, Does.Contain(win64));
});

// Look-up invalid configuration
PlatformDefinition? and = platformDefs.Find(UnityOs.Android, UnityCpu.None);
Assert.That(and, Is.Null);
}

[Test]
public void RemainingPlatforms_NoneVisited()
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
var visited = new HashSet<PlatformDefinition>();

// If no platform was visited, the remaining platforms should be the (AnyOS, AnyCPU) config.
HashSet<PlatformDefinition> remaining = platformDefs.GetRemainingPlatforms(visited);
});

// Look-up invalid configuration
PlatformDefinition? and = platformDefs.Find(UnityOs.Android, UnityCpu.None);
Assert.That(and, Is.Null);
}

[Test]
public void RemainingPlatforms_NoneVisited()
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
var visited = new HashSet<PlatformDefinition>();

// If no platform was visited, the remaining platforms should be the (AnyOS, AnyCPU) config.
HashSet<PlatformDefinition> remaining = platformDefs.GetRemainingPlatforms(visited);
Assert.That(remaining, Is.Not.Null);
Assert.Multiple(() =>
{
Assert.That(remaining, Has.Count.EqualTo(1));
Assert.That(platformDefs, Is.EqualTo(remaining.First()));
});
}

[Test]
public void RemainingPlatforms_OneVisited()
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
foreach (PlatformDefinition child in platformDefs.Children)
{
var visited = new HashSet<PlatformDefinition>() { child };
HashSet<PlatformDefinition> remaining = platformDefs.GetRemainingPlatforms(visited);

// We should get all other children, except the one already visited
Assert.That(remaining.Count + 1, Is.EqualTo(platformDefs.Children.Count));
foreach (PlatformDefinition r in remaining)
});
}

[Test]
public void RemainingPlatforms_OneVisited()
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();

foreach (var child in platformDefs.Children)
{
var visited = new HashSet<PlatformDefinition>() { child };
HashSet<PlatformDefinition> remaining = platformDefs.GetRemainingPlatforms(visited);

// We should get all other children, except the one already visited
Assert.That(remaining.Count + 1, Is.EqualTo(platformDefs.Children.Count));
foreach (PlatformDefinition r in remaining)
{
Assert.Multiple(() =>
{
Assert.That(child, Is.Not.EqualTo(r));
Assert.That(platformDefs.Children, Does.Contain(r));
});
}
}
}

[Test]
public void RemainingPlatforms_LeafVisited()
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
PlatformDefinition? win64 = platformDefs.Find(UnityOs.Windows, UnityCpu.X64);
var visited = new HashSet<PlatformDefinition>() { win64! };

// The remaining platforms should be all non-windows, as well as all !x64 windows
var expected = platformDefs.Children
.Except([win64!.Parent])
.Concat(
win64.Parent!.Children
.Except([win64]))
.ToHashSet();
HashSet<PlatformDefinition> actual = platformDefs.GetRemainingPlatforms(visited);
Assert.That(expected.SetEquals(actual), Is.True);
}

[TestCase("")]
[TestCase("base")]
public void TestConfigPath_Root(string basePath)
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
var file = new PlatformFile("a/b/c.dll", platformDefs);

// We don't use extra paths for the (AnyOS, AnyCPU) configuration
string actual = file.GetDestinationPath(basePath);
string expected = Path.Combine(
basePath,
Path.GetFileName(file.SourcePath));
Assert.That(expected, Is.EqualTo(actual));
}

[TestCase("")]
[TestCase("base")]
public void TestConfigPath_OsOnly(string basePath)
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
PlatformDefinition? win = platformDefs.Find(UnityOs.Windows);
var file = new PlatformFile("a/b/c.dll", win!);

string actual = file.GetDestinationPath(basePath);
string expected = Path.Combine(
basePath,
"Windows",
Path.GetFileName(file.SourcePath));
Assert.That(expected, Is.EqualTo(actual));
}

[TestCase("")]
[TestCase("base")]
public void TestConfigPath_Full(string basePath)
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
PlatformDefinition? win64 = platformDefs.Find(UnityOs.Windows, UnityCpu.X64);
var file = new PlatformFile("a/b/c.dll", win64!);

string actual = file.GetDestinationPath(basePath);
string expected = Path.Combine(
basePath,
"Windows",
"x86_64",
Path.GetFileName(file.SourcePath));
Assert.That(expected, Is.EqualTo(actual));
}
}
}
});
}
}
}

[Test]
public void RemainingPlatforms_LeafVisited()
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
PlatformDefinition? win64 = platformDefs.Find(UnityOs.Windows, UnityCpu.X64);
var visited = new HashSet<PlatformDefinition>() { win64! };

// The remaining platforms should be all non-windows, as well as all !x64 windows
var expected = platformDefs.Children
.Except([win64!.Parent])
.Concat(
win64.Parent!.Children
.Except([win64]))
.ToHashSet();
HashSet<PlatformDefinition> actual = platformDefs.GetRemainingPlatforms(visited);
Assert.That(expected.SetEquals(actual), Is.True);
}

[TestCase("")]
[TestCase("base")]
public void TestConfigPath_Root(string basePath)
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
var file = new PlatformFile("a/b/c.dll", platformDefs);

// We don't use extra paths for the (AnyOS, AnyCPU) configuration
string actual = file.GetDestinationPath(basePath);
string expected = Path.Combine(
basePath,
Path.GetFileName(file.SourcePath));
Assert.That(expected, Is.EqualTo(actual));
}

[TestCase("")]
[TestCase("base")]
public void TestConfigPath_OsOnly(string basePath)
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
PlatformDefinition? win = platformDefs.Find(UnityOs.Windows);
var file = new PlatformFile("a/b/c.dll", win!);

string actual = file.GetDestinationPath(basePath);
string expected = Path.Combine(
basePath,
"Windows",
Path.GetFileName(file.SourcePath));
Assert.That(expected, Is.EqualTo(actual));
}

[TestCase("")]
[TestCase("base")]
public void TestConfigPath_Full(string basePath)
{
var platformDefs = PlatformDefinition.CreateAllPlatforms();
PlatformDefinition? win64 = platformDefs.Find(UnityOs.Windows, UnityCpu.X64);
var file = new PlatformFile("a/b/c.dll", win64!);

string actual = file.GetDestinationPath(basePath);
string expected = Path.Combine(
basePath,
"Windows",
"x86_64",
Path.GetFileName(file.SourcePath));
Assert.That(expected, Is.EqualTo(actual));
}
}
}
2 changes: 1 addition & 1 deletion src/UnityNuGet.Tests/RegistryCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace UnityNuGet.Tests
{
public class RegistryCacheTests
{
[Test]
[Test,Order(99)]
public async Task TestBuild()
{
bool errorsTriggered = false;
Expand Down
Loading

0 comments on commit 9a86758

Please sign in to comment.