|
| 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 | +} |
0 commit comments