Skip to content

Commit

Permalink
xplat: Adds FreeBSD support.
Browse files Browse the repository at this point in the history
Refs: dotnet/corefx#2068
PR-URL: #180
  • Loading branch information
Peter Jas authored and ViktorHofer committed Jul 20, 2018
1 parent a42b210 commit 78d026f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
5 changes: 3 additions & 2 deletions Discoverers/ActiveIssueDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitA

string issue = ctorArgs.First().ToString();
PlatformID platforms = (PlatformID)ctorArgs.Last();
if ((platforms.HasFlag(PlatformID.Windows) && Interop.IsWindows) ||
if ((platforms.HasFlag(PlatformID.FreeBSD) && Interop.IsFreeBSD) ||
(platforms.HasFlag(PlatformID.Linux) && Interop.IsLinux) ||
(platforms.HasFlag(PlatformID.OSX) && Interop.IsOSX))
(platforms.HasFlag(PlatformID.OSX) && Interop.IsOSX) ||
(platforms.HasFlag(PlatformID.Windows) && Interop.IsWindows))
{
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.Failing);
yield return new KeyValuePair<string, string>(XunitConstants.ActiveIssue, issue);
Expand Down
2 changes: 2 additions & 0 deletions Discoverers/PlatformSpecificDiscoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitA
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonLinuxTest);
if (!platform.HasFlag(PlatformID.OSX))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonOSXTest);
if (!platform.HasFlag(PlatformID.FreeBSD))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonFreeBSDTest);
}
}
}
24 changes: 17 additions & 7 deletions Interop.PlatformDetection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ internal static partial class Interop
{
internal enum OperatingSystem
{
Windows,
FreeBSD,
Linux,
OSX
OSX,
Windows
}

internal static bool IsWindows
internal static bool IsFreeBSD
{
get { return OperatingSystem.Windows == PlatformDetection.OperatingSystem; }
get { return OperatingSystem.FreeBSD == PlatformDetection.OperatingSystem; }
}

internal static bool IsLinux
Expand All @@ -31,6 +32,11 @@ internal static bool IsOSX
get { return OperatingSystem.OSX == PlatformDetection.OperatingSystem; }
}

internal static bool IsWindows
{
get { return OperatingSystem.Windows == PlatformDetection.OperatingSystem; }
}

internal static class PlatformDetection
{
internal static OperatingSystem OperatingSystem { get { return s_os.Value; } }
Expand All @@ -44,9 +50,13 @@ internal static class PlatformDetection
byte* buffer = stackalloc byte[8192]; // the size use with uname is platform specific; this should be large enough for any OS
if (uname(buffer) == 0)
{
return Marshal.PtrToStringAnsi((IntPtr)buffer) == "Darwin" ?
OperatingSystem.OSX :
OperatingSystem.Linux;
string os = Marshal.PtrToStringAnsi((IntPtr)buffer);
if (os == "FreeBSD")
return OperatingSystem.FreeBSD;
else if (os == "Darwin")
return OperatingSystem.OSX;
else
return OperatingSystem.Linux;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions PlatformID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public enum PlatformID
Windows = 1,
Linux = 2,
OSX = 4,
AnyUnix = Linux | OSX,
Any = Windows | Linux | OSX
FreeBSD = 8,
AnyUnix = FreeBSD | Linux | OSX,
Any = ~0
}
}
3 changes: 2 additions & 1 deletion XunitConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace Xunit.NetCore.Extensions
{
internal struct XunitConstants
{
public const string NonWindowsTest = "nonwindowstests";
public const string NonFreeBSDTest = "nonfreebsdtests";
public const string NonLinuxTest = "nonlinuxtests";
public const string NonOSXTest = "nonosxtests";
public const string NonWindowsTest = "nonwindowstests";
public const string Category = "category";
public const string Failing = "failing";
public const string ActiveIssue = "activeissue";
Expand Down

0 comments on commit 78d026f

Please sign in to comment.