From 3be446880ae6335c71ff6b112746bc587145a8e4 Mon Sep 17 00:00:00 2001 From: Malte Rosenbjerg Date: Fri, 17 Oct 2025 14:45:11 +0200 Subject: [PATCH] Only run downloader tests on windows and linux since macos CI runs on arm which builds are not available for --- .../Enums/EnumExtensions.cs | 13 ++++++ FFMpegCore.Test/DownloaderTests.cs | 5 ++- .../Utilities/OsSpecificTestMethod.cs | 42 +++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 FFMpegCore.Extensions.Downloader/Enums/EnumExtensions.cs create mode 100644 FFMpegCore.Test/Utilities/OsSpecificTestMethod.cs diff --git a/FFMpegCore.Extensions.Downloader/Enums/EnumExtensions.cs b/FFMpegCore.Extensions.Downloader/Enums/EnumExtensions.cs new file mode 100644 index 0000000..7743820 --- /dev/null +++ b/FFMpegCore.Extensions.Downloader/Enums/EnumExtensions.cs @@ -0,0 +1,13 @@ +namespace FFMpegCore.Extensions.Downloader.Enums; + +public static class EnumExtensions +{ + public static TEnum[] GetFlags(this TEnum input) where TEnum : Enum + { + return Enum.GetValues(input.GetType()) + .Cast() + .Where(input.HasFlag) + .Cast() + .ToArray(); + } +} diff --git a/FFMpegCore.Test/DownloaderTests.cs b/FFMpegCore.Test/DownloaderTests.cs index 165e813..7acf30a 100644 --- a/FFMpegCore.Test/DownloaderTests.cs +++ b/FFMpegCore.Test/DownloaderTests.cs @@ -1,12 +1,13 @@ using FFMpegCore.Extensions.Downloader; using FFMpegCore.Extensions.Downloader.Enums; +using FFMpegCore.Test.Utilities; namespace FFMpegCore.Test; [TestClass] public class DownloaderTests { - [TestMethod] + [OsSpecificTestMethod(OsPlatforms.Windows | OsPlatforms.Linux)] public async Task GetSpecificVersionTest() { var binaries = await FFMpegDownloader.DownloadFFMpegSuite(FFMpegVersions.V6_1); @@ -20,7 +21,7 @@ public class DownloaderTests } } - [TestMethod] + [OsSpecificTestMethod(OsPlatforms.Windows | OsPlatforms.Linux)] public async Task GetAllLatestSuiteTest() { var binaries = await FFMpegDownloader.DownloadFFMpegSuite(); diff --git a/FFMpegCore.Test/Utilities/OsSpecificTestMethod.cs b/FFMpegCore.Test/Utilities/OsSpecificTestMethod.cs new file mode 100644 index 0000000..b3563a9 --- /dev/null +++ b/FFMpegCore.Test/Utilities/OsSpecificTestMethod.cs @@ -0,0 +1,42 @@ +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using FFMpegCore.Extensions.Downloader.Enums; + +namespace FFMpegCore.Test.Utilities; + +[Flags] +internal enum OsPlatforms : ushort +{ + Windows, + Linux, + MacOS +} + +internal class OsSpecificTestMethod : TestMethodAttribute +{ + private readonly IEnumerable _supportedOsPlatforms; + + public OsSpecificTestMethod(OsPlatforms supportedOsPlatforms, [CallerFilePath] string callerFilePath = "", + [CallerLineNumber] int callerLineNumber = -1) : base(callerFilePath, callerLineNumber) + { + _supportedOsPlatforms = supportedOsPlatforms.GetFlags() + .Select(flag => OSPlatform.Create(flag.ToString().ToUpperInvariant())) + .ToArray(); + } + + public override async Task ExecuteAsync(ITestMethod testMethod) + { + if (_supportedOsPlatforms.Any(RuntimeInformation.IsOSPlatform)) + { + return await base.ExecuteAsync(testMethod); + } + + var message = $"Test only executed on specific platforms: {string.Join(", ", _supportedOsPlatforms.Select(platform => platform.ToString()))}"; + { + return + [ + new TestResult { Outcome = UnitTestOutcome.Inconclusive, TestFailureException = new AssertInconclusiveException(message) } + ]; + } + } +}