-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build target and task for TestPlatform (#88)
* Initial commit for build targets and task for TestPlatform. * Add version suffix for build.cmd. All assemblies are stamped with the suffix. Sign .net core assemblies and independent packages e.g. Build nuget package. * Add test file path. Add tracing for build.
- Loading branch information
Showing
11 changed files
with
574 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.Build.xproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>03fc3baa-417b-460b-b9ef-ab9a4d2a974a</ProjectGuid> | ||
<RootNamespace>Microsoft.TestPlatform.Build</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
40 changes: 40 additions & 0 deletions
40
src/Microsoft.TestPlatform.Build/Microsoft.TestPlatform.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<!-- | ||
*********************************************************************************************** | ||
Microsoft.TestPlatform.targets | ||
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have | ||
created a backup copy. Incorrect changes to this file will make it | ||
impossible to load or build your projects from the command-line or the IDE. | ||
Copyright (c) .NET Foundation. All rights reserved. | ||
*********************************************************************************************** | ||
--> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<!-- Load Microsoft.TestPlatform.Build.Tasks.dll, this can be overridden to use a different version with $(VSTestTaskAssemblyFile) --> | ||
<PropertyGroup> | ||
<VSTestTaskAssemblyFile Condition="$(VSTestTaskAssemblyFile) == ''">Microsoft.TestPlatform.Build.dll</VSTestTaskAssemblyFile> | ||
</PropertyGroup> | ||
<UsingTask TaskName="Microsoft.TestPlatform.Build.Tasks.VSTestTask" AssemblyFile="$(VSTestTaskAssemblyFile)" /> | ||
|
||
<!-- | ||
============================================================ | ||
Test target | ||
Main entry point for running tests through vstest.console.exe | ||
============================================================ | ||
--> | ||
<Target Name="VSTest" DependsOnTargets="Build"> | ||
<Microsoft.TestPlatform.Build.Tasks.VSTestTask | ||
TestFileFullPath="$(TargetPath)" | ||
VSTestSetting="$(VSTestSetting)" | ||
VSTestTests="$(VSTestTests)" | ||
VSTestTestAdapterPath="$(VSTestTestAdapterPath)" | ||
VSTestPlatform="$(VSTestPlatform)" | ||
VSTestFramework="$(VSTestFramework)" | ||
VSTestTestCaseFilter="$(VSTestTestCaseFilter)" | ||
VSTestLogger="$(VSTestLogger)" | ||
VSTestListTests="$(VSTestListTests)" | ||
VSTestParentProcessId="$(VSTestParentProcessId)" | ||
VSTestPort="$(VSTestPort)" | ||
/> | ||
</Target> | ||
</Project> |
19 changes: 19 additions & 0 deletions
19
src/Microsoft.TestPlatform.Build/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("Microsoft.TestPlatform.Build")] | ||
[assembly: AssemblyTrademark("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("03fc3baa-417b-460b-b9ef-ab9a4d2a974a")] |
125 changes: 125 additions & 0 deletions
125
src/Microsoft.TestPlatform.Build/Tasks/ArgumentEscaper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace Microsoft.TestPlatform.Build.Tasks.Utils | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
public static class ArgumentEscaper | ||
{ | ||
/// <summary> | ||
/// Undo the processing which took place to create string[] args in Main, | ||
/// so that the next process will receive the same string[] args | ||
/// | ||
/// See here for more info: | ||
/// http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx | ||
/// </summary> | ||
/// <param name="args"></param> | ||
/// <returns></returns> | ||
public static string EscapeAndConcatenateArgArrayForProcessStart(IEnumerable<string> args) | ||
{ | ||
return string.Join(" ", EscapeArgArray(args)); | ||
} | ||
|
||
/// <summary> | ||
/// Undo the processing which took place to create string[] args in Main, | ||
/// so that the next process will receive the same string[] args | ||
/// | ||
/// See here for more info: | ||
/// http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/everyone-quotes-arguments-the-wrong-way.aspx | ||
/// </summary> | ||
/// <param name="args"></param> | ||
/// <returns></returns> | ||
private static IEnumerable<string> EscapeArgArray(IEnumerable<string> args) | ||
{ | ||
var escapedArgs = new List<string>(); | ||
|
||
foreach (var arg in args) | ||
{ | ||
escapedArgs.Add(EscapeSingleArg(arg)); | ||
} | ||
|
||
return escapedArgs; | ||
} | ||
|
||
public static string EscapeSingleArg(string arg) | ||
{ | ||
var sb = new StringBuilder(); | ||
|
||
var needsQuotes = ShouldSurroundWithQuotes(arg); | ||
var isQuoted = needsQuotes || IsSurroundedWithQuotes(arg); | ||
|
||
if (needsQuotes) sb.Append("\""); | ||
|
||
for (int i = 0; i < arg.Length; ++i) | ||
{ | ||
var backslashCount = 0; | ||
|
||
// Consume All Backslashes | ||
while (i < arg.Length && arg[i] == '\\') | ||
{ | ||
backslashCount++; | ||
i++; | ||
} | ||
|
||
// Escape any backslashes at the end of the arg | ||
// when the argument is also quoted. | ||
// This ensures the outside quote is interpreted as | ||
// an argument delimiter | ||
if (i == arg.Length && isQuoted) | ||
{ | ||
sb.Append('\\', 2 * backslashCount); | ||
} | ||
|
||
// At then end of the arg, which isn't quoted, | ||
// just add the backslashes, no need to escape | ||
else if (i == arg.Length) | ||
{ | ||
sb.Append('\\', backslashCount); | ||
} | ||
|
||
// Escape any preceding backslashes and the quote | ||
else if (arg[i] == '"') | ||
{ | ||
sb.Append('\\', (2 * backslashCount) + 1); | ||
sb.Append('"'); | ||
} | ||
|
||
// Output any consumed backslashes and the character | ||
else | ||
{ | ||
sb.Append('\\', backslashCount); | ||
sb.Append(arg[i]); | ||
} | ||
} | ||
|
||
if (needsQuotes) sb.Append("\""); | ||
|
||
return sb.ToString(); | ||
} | ||
|
||
internal static bool ShouldSurroundWithQuotes(string argument) | ||
{ | ||
// Don't quote already quoted strings | ||
if (IsSurroundedWithQuotes(argument)) | ||
{ | ||
return false; | ||
} | ||
|
||
// Only quote if whitespace exists in the string | ||
return ArgumentContainsWhitespace(argument); | ||
} | ||
|
||
internal static bool IsSurroundedWithQuotes(string argument) | ||
{ | ||
return argument.StartsWith("\"", StringComparison.Ordinal) && | ||
argument.EndsWith("\"", StringComparison.Ordinal); | ||
} | ||
|
||
internal static bool ArgumentContainsWhitespace(string argument) | ||
{ | ||
return argument.Contains(" ") || argument.Contains("\t") || argument.Contains("\n"); | ||
} | ||
} | ||
} |
Oops, something went wrong.