Skip to content

Commit 3313aec

Browse files
committed
Fix tests on windows platform and create a better structure
1 parent a77d242 commit 3313aec

11 files changed

Lines changed: 712 additions & 155 deletions

ebuild.Tests/Common/LinkerTests.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using NUnit.Framework;
2+
using ebuild.Platforms;
3+
using ebuild.Linkers;
4+
using ebuild.Compilers;
5+
using System;
6+
7+
namespace ebuild.Tests.Common;
8+
9+
[TestFixture]
10+
public class LinkerTests
11+
{
12+
[OneTimeSetUp]
13+
public void OneTimeSetUp()
14+
{
15+
// Register platforms, compilers, and linkers
16+
try
17+
{
18+
PlatformRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
19+
CompilerRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
20+
LinkerRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
21+
22+
// Also try to register explicitly
23+
LinkerRegistry.GetInstance().Register("Gcc", typeof(GccLinker));
24+
LinkerRegistry.GetInstance().Register("MsvcLink", typeof(MsvcLinkLinker));
25+
LinkerRegistry.GetInstance().Register("MsvcLib", typeof(MsvcLibLinker));
26+
}
27+
catch (System.ArgumentException)
28+
{
29+
// Already registered, ignore
30+
}
31+
}
32+
33+
[Test]
34+
public void LinkerRegistry_Should_Retrieve_Linker_By_Name()
35+
{
36+
// Arrange
37+
var registry = LinkerRegistry.GetInstance();
38+
try
39+
{
40+
registry.Register("Gcc", typeof(GccLinker));
41+
registry.Register("MsvcLink", typeof(MsvcLinkLinker));
42+
}
43+
catch (ArgumentException)
44+
{
45+
// Already registered, that's fine
46+
}
47+
48+
// Act
49+
var gccLinker = registry.Get("Gcc");
50+
var msvcLinker = registry.Get("MsvcLink");
51+
52+
// Assert
53+
Assert.That(gccLinker, Is.InstanceOf<GccLinker>());
54+
Assert.That(msvcLinker, Is.InstanceOf<MsvcLinkLinker>());
55+
}
56+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using NUnit.Framework;
2+
using ebuild.Platforms;
3+
using ebuild.Linkers;
4+
using ebuild.Compilers;
5+
using System;
6+
7+
namespace ebuild.Tests.Common;
8+
9+
[TestFixture]
10+
public class RegistryIntegrationTests
11+
{
12+
[OneTimeSetUp]
13+
public void OneTimeSetUp()
14+
{
15+
// Register platforms, compilers, and linkers
16+
try
17+
{
18+
PlatformRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
19+
CompilerRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
20+
LinkerRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
21+
}
22+
catch (System.ArgumentException)
23+
{
24+
// Already registered, ignore
25+
}
26+
}
27+
28+
[Test]
29+
public void Compiler_Should_Accept_Linker_And_Pass_Module()
30+
{
31+
// Arrange
32+
var compiler = new GccCompiler();
33+
var linker = new GccLinker();
34+
35+
// Act
36+
compiler.SetLinker(linker);
37+
38+
// Assert - No exception should be thrown
39+
Assert.DoesNotThrow(() => compiler.SetLinker(linker));
40+
}
41+
42+
[Test]
43+
public void PlatformRegistry_Should_Get_Host_Platform()
44+
{
45+
// Act
46+
var hostPlatform = PlatformRegistry.GetHostPlatform();
47+
48+
// Assert
49+
Assert.That(hostPlatform, Is.Not.Null);
50+
Assert.That(hostPlatform.GetName(), Is.Not.Null.And.Not.Empty);
51+
}
52+
53+
[Test]
54+
public void CompilerRegistry_Should_Get_Default_Compiler_Name()
55+
{
56+
// Act
57+
var defaultCompilerName = CompilerRegistry.GetDefaultCompilerName();
58+
59+
// Assert
60+
Assert.That(defaultCompilerName, Is.Not.Null.And.Not.Empty);
61+
}
62+
}

ebuild.Tests/ZlibEbuildTests.cs renamed to ebuild.Tests/Integration/ZlibEbuildTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using ebuild.Compilers;
1111
using ebuild.Linkers;
1212

13-
namespace ebuild.Tests;
13+
namespace ebuild.Tests.Integration;
1414

1515
[TestFixture]
1616
public class ZlibEbuildTests
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using NUnit.Framework;
2+
using ebuild.Platforms;
3+
using ebuild.Linkers;
4+
using System;
5+
using System.Runtime.InteropServices;
6+
7+
namespace ebuild.Tests.UnixTests;
8+
9+
[TestFixture]
10+
public class ArLinkerTests
11+
{
12+
[OneTimeSetUp]
13+
public void OneTimeSetUp()
14+
{
15+
// Register platforms, compilers, and linkers
16+
try
17+
{
18+
PlatformRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
19+
LinkerRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
20+
21+
// Also try to register explicitly
22+
LinkerRegistry.GetInstance().Register("Ar", typeof(ArLinker));
23+
}
24+
catch (System.ArgumentException)
25+
{
26+
// Already registered, ignore
27+
}
28+
}
29+
30+
[Test]
31+
public void ArLinker_Should_Have_Correct_Name()
32+
{
33+
// Arrange
34+
var linker = new ArLinker();
35+
36+
// Act
37+
var name = linker.GetName();
38+
39+
// Assert
40+
Assert.That(name, Is.EqualTo("Ar"));
41+
}
42+
43+
[Test]
44+
public void ArLinker_Should_Be_Available_For_Unix_Platform()
45+
{
46+
// Skip this test on Windows as it's Unix-specific
47+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
48+
Assert.Ignore();
49+
// Arrange
50+
var linker = new ArLinker();
51+
var platform = new UnixPlatform();
52+
53+
// On Unix systems, AR should be available
54+
// Act
55+
var isAvailable = linker.IsAvailable(platform);
56+
57+
// Assert
58+
Assert.That(isAvailable, Is.True, "AR linker should be available on Unix systems");
59+
}
60+
61+
[Test]
62+
public void ArLinker_Should_Not_Be_Available_For_Win32_Platform()
63+
{
64+
// Arrange
65+
var linker = new ArLinker();
66+
var platform = new Win32Platform();
67+
68+
// Act
69+
var isAvailable = linker.IsAvailable(platform);
70+
71+
// Assert
72+
Assert.That(isAvailable, Is.False);
73+
}
74+
75+
[Test]
76+
public void LinkerRegistry_Should_Register_And_Retrieve_ArLinker()
77+
{
78+
// Arrange
79+
var registry = LinkerRegistry.GetInstance();
80+
81+
// Act & Assert - Check if already registered or register manually
82+
try
83+
{
84+
registry.Register("Ar", typeof(ArLinker));
85+
}
86+
catch (ArgumentException)
87+
{
88+
// Already registered, that's fine
89+
}
90+
91+
Assert.DoesNotThrow(() => registry.Get<ArLinker>());
92+
}
93+
94+
[Test]
95+
public void LinkerRegistry_Should_Retrieve_ArLinker_By_Name()
96+
{
97+
// Arrange
98+
var registry = LinkerRegistry.GetInstance();
99+
try
100+
{
101+
registry.Register("Ar", typeof(ArLinker));
102+
}
103+
catch (ArgumentException)
104+
{
105+
// Already registered, that's fine
106+
}
107+
108+
// Act
109+
var arLinker = registry.Get("Ar");
110+
111+
// Assert
112+
Assert.That(arLinker, Is.InstanceOf<ArLinker>());
113+
}
114+
}
Lines changed: 26 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,19 @@
11
using NUnit.Framework;
22
using ebuild.Platforms;
33
using ebuild.Compilers;
4+
using System.Runtime.InteropServices;
45

5-
namespace ebuild.Tests;
6-
7-
[TestFixture]
8-
public class UnixPlatformTests
9-
{
10-
[OneTimeSetUp]
11-
public void OneTimeSetUp()
12-
{
13-
// Only register if not already registered
14-
try
15-
{
16-
PlatformRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
17-
}
18-
catch (System.ArgumentException)
19-
{
20-
// Already registered, ignore
21-
}
22-
}
23-
24-
[Test]
25-
public void UnixPlatform_Should_Be_Registered()
26-
{
27-
// Arrange
28-
var registry = PlatformRegistry.GetInstance();
29-
30-
// Act & Assert
31-
Assert.DoesNotThrow(() => registry.Get<UnixPlatform>());
32-
}
33-
34-
[Test]
35-
public void UnixPlatform_Should_Have_Correct_Name()
36-
{
37-
// Arrange
38-
var platform = new UnixPlatform();
39-
40-
// Act
41-
var name = platform.GetName();
42-
43-
// Assert
44-
Assert.That(name, Is.EqualTo("Unix"));
45-
}
46-
47-
[Test]
48-
public void UnixPlatform_Should_Return_Gcc_As_Default_Compiler()
49-
{
50-
// Arrange
51-
var platform = new UnixPlatform();
52-
53-
// Act
54-
var compilerName = platform.GetDefaultCompilerName();
55-
56-
// Assert
57-
Assert.That(compilerName, Is.EqualTo("Gcc"));
58-
}
59-
}
6+
namespace ebuild.Tests.UnixTests;
607

618
[TestFixture]
629
public class GccCompilerTests
6310
{
6411
[OneTimeSetUp]
6512
public void OneTimeSetUp()
6613
{
67-
// Only register if not already registered
14+
if(!RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
15+
Assert.Ignore();
16+
// Register platforms and compilers
6817
try
6918
{
7019
PlatformRegistry.GetInstance().RegisterAllFromAssembly(typeof(EBuild).Assembly);
@@ -92,16 +41,19 @@ public void GccCompiler_Should_Have_Correct_Name()
9241
[Test]
9342
public void GccCompiler_Should_Be_Available_For_Unix_Platform()
9443
{
44+
// Skip this test on Windows as it's Unix-specific
45+
Assume.That(RuntimeInformation.IsOSPlatform(OSPlatform.Windows), Is.False,
46+
"This test is Unix-specific and should be skipped on Windows");
47+
9548
// Arrange
9649
var compiler = new GccCompiler();
9750
var platform = new UnixPlatform();
98-
if(PlatformRegistry.GetHostPlatform().GetType() == typeof(UnixPlatform))
99-
{
100-
// Act
101-
var isAvailable = compiler.IsAvailable(platform);
102-
// Assert
103-
Assert.That(isAvailable, Is.True);
104-
}
51+
52+
// Act
53+
var isAvailable = compiler.IsAvailable(platform);
54+
55+
// Assert
56+
Assert.That(isAvailable, Is.True);
10557
}
10658

10759
[Test]
@@ -117,4 +69,14 @@ public void GccCompiler_Should_Not_Be_Available_For_Win32_Platform()
11769
// Assert
11870
Assert.That(isAvailable, Is.False);
11971
}
120-
}
72+
73+
[Test]
74+
public void GccCompiler_Should_Be_Registered_In_Registry()
75+
{
76+
// Arrange
77+
var registry = CompilerRegistry.GetInstance();
78+
79+
// Act & Assert
80+
Assert.DoesNotThrow(() => registry.Create<GccCompiler>());
81+
}
82+
}

0 commit comments

Comments
 (0)