From 580ed7ea9646b6684834a52c51d14062ecb30b76 Mon Sep 17 00:00:00 2001 From: Lakshmi Priya Sekar Date: Tue, 22 Mar 2016 17:00:45 -0700 Subject: [PATCH] Get runtime OS info to add xunit categories. --- .../project.json | 25 +++++++------ .../GetTargetOS.cs | 35 +++++++++++++++++++ .../Microsoft.DotNet.Build.Tasks.csproj | 1 + .../PackageFiles/tests.targets | 25 ++++++++----- src/Microsoft.DotNet.Build.Tasks/project.json | 5 +-- 5 files changed, 70 insertions(+), 21 deletions(-) create mode 100644 src/Microsoft.DotNet.Build.Tasks/GetTargetOS.cs diff --git a/src/Microsoft.DotNet.Build.Tasks.net45/project.json b/src/Microsoft.DotNet.Build.Tasks.net45/project.json index cc970678d1..e555782272 100644 --- a/src/Microsoft.DotNet.Build.Tasks.net45/project.json +++ b/src/Microsoft.DotNet.Build.Tasks.net45/project.json @@ -1,11 +1,16 @@ { - "dependencies": { - "Newtonsoft.Json": "7.0.1", - "NuGet.Versioning": "3.4.0-beta-488", - "System.Collections.Immutable": "1.1.37", - "System.Reflection.Metadata": "1.1.0" - }, - "frameworks": { - "net45": { } - } -} \ No newline at end of file + "dependencies": { + "Newtonsoft.Json": "7.0.1", + "NuGet.Versioning": "3.4.0-beta-488", + "System.Collections.Immutable": "1.1.37", + "System.Reflection.Metadata": "1.1.0", + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23907", + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-rc2-23907" + }, + "frameworks": { + "net46": { } + }, + "runtimes": { + "win": { } + } +} diff --git a/src/Microsoft.DotNet.Build.Tasks/GetTargetOS.cs b/src/Microsoft.DotNet.Build.Tasks/GetTargetOS.cs new file mode 100644 index 0000000000..2ada9b44a3 --- /dev/null +++ b/src/Microsoft.DotNet.Build.Tasks/GetTargetOS.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using System.Runtime.InteropServices; +using System; +using System.IO; +using System.Linq; + +namespace Microsoft.DotNet.Build.Tasks +{ + public class GetTargetOS : Task + { + [Output] + public string TargetOS { get; set; } + + public override bool Execute() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + TargetOS = "Windows_NT"; + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + TargetOS = "Linux"; + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + TargetOS = "OSX"; + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))) + TargetOS = "FreeBSD"; + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD"))) + TargetOS = "NetBSD"; + + return true; + } + } +} diff --git a/src/Microsoft.DotNet.Build.Tasks/Microsoft.DotNet.Build.Tasks.csproj b/src/Microsoft.DotNet.Build.Tasks/Microsoft.DotNet.Build.Tasks.csproj index 5e02fbe12f..a620ca9732 100644 --- a/src/Microsoft.DotNet.Build.Tasks/Microsoft.DotNet.Build.Tasks.csproj +++ b/src/Microsoft.DotNet.Build.Tasks/Microsoft.DotNet.Build.Tasks.csproj @@ -26,6 +26,7 @@ + diff --git a/src/Microsoft.DotNet.Build.Tasks/PackageFiles/tests.targets b/src/Microsoft.DotNet.Build.Tasks/PackageFiles/tests.targets index b7cdc7a242..3d93ded150 100644 --- a/src/Microsoft.DotNet.Build.Tasks/PackageFiles/tests.targets +++ b/src/Microsoft.DotNet.Build.Tasks/PackageFiles/tests.targets @@ -3,7 +3,7 @@ - + false @@ -59,11 +59,7 @@ testResults.xml $(XunitOptions) -xml $(XunitResultsFileName) - $(XunitOptions) -notrait category=nonwindowstests - $(XunitOptions) -notrait category=nonlinuxtests - $(XunitOptions) -notrait category=nonosxtests - $(XunitOptions) -notrait category=nonfreebsdtests - $(XunitOptions) -notrait category=nonnetbsdtests + $(XunitOptions) -notrait Benchmark=true $(XunitOptions) -maxthreads $(XunitMaxThreads) @@ -113,6 +109,14 @@ Outputs="$(TestsSuccessfulSemaphore);$(TestPath)%(TestTargetFramework.Folder)/$(XunitResultsFileName);$(CoverageOutputFilePath)" Condition="'$(TestDisabled)'!='true'"> + + + + + + + + $(XunitTraitOptions) -trait category=@(RunWithTraits, ' -trait category=') $(XunitTraitOptions) -notrait category=@(RunWithoutTraits, ' -notrait category=') @@ -169,10 +173,13 @@ + + + - true + true - + diff --git a/src/Microsoft.DotNet.Build.Tasks/project.json b/src/Microsoft.DotNet.Build.Tasks/project.json index 908a1ed667..5a0daeb1c6 100644 --- a/src/Microsoft.DotNet.Build.Tasks/project.json +++ b/src/Microsoft.DotNet.Build.Tasks/project.json @@ -5,7 +5,7 @@ "Microsoft.Build.Utilities.Core": "0.1.0-preview-00005", "Microsoft.CSharp": "4.0.1-rc2-23907", "Microsoft.NETCore.Platforms": "1.0.1-rc2-23907", - "Microsoft.Win32.Registry": { + "Microsoft.Win32.Registry": { "version": "4.0.0-rc2-23907", "exclude": "Compile" }, @@ -21,7 +21,8 @@ "System.Reflection.Metadata": "1.1.0", "System.Xml.ReaderWriter": "4.0.11-rc2-23907", "System.Xml.XDocument": "4.0.11-rc2-23907", - "System.Xml.XPath.XmlDocument": "4.0.0" + "System.Xml.XPath.XmlDocument": "4.0.0", + "System.Runtime.InteropServices.RuntimeInformation": "4.0.0-rc2-23907" }, "frameworks": { "dnxcore50": {}