-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the parameters to VSTestTask to allow dotnet test to work (#2438)
* Add the msbuild parameters to VSTestTask to allow dotnet test to work * Remove trim
- Loading branch information
Showing
7 changed files
with
264 additions
and
10 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
83 changes: 83 additions & 0 deletions
83
src/Microsoft.TestPlatform.CoreUtilities/Utilities/TimeSpanParser.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,83 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace Microsoft.VisualStudio.TestPlatform.Utilities | ||
{ | ||
public static class TimeSpanParser | ||
{ | ||
static readonly Regex pattern = new Regex(@"(?<value>^\d+(?:\.\d+)?)\s*(?<suffix>ms|mil|m|h|d|s?[a-z]*)$", RegexOptions.IgnoreCase); | ||
|
||
public static TimeSpan Parse(string time) | ||
{ | ||
return TryParse(time, out var result) ? result : throw GetFormatException(time); | ||
} | ||
|
||
public static bool TryParse(string time, out TimeSpan result) | ||
{ | ||
if (string.IsNullOrWhiteSpace(time)) | ||
{ | ||
result = TimeSpan.Zero; | ||
return true; | ||
} | ||
|
||
var match = pattern.Match(time); | ||
if (!match.Success) | ||
{ | ||
result = TimeSpan.Zero; | ||
return false; | ||
} | ||
|
||
var value = match.Groups["value"].Value; | ||
if (!double.TryParse(value, out var number)) | ||
{ | ||
throw GetFormatException(value); | ||
} | ||
|
||
var suffix = match.Groups["suffix"].Value; | ||
var c = StringComparison.OrdinalIgnoreCase; | ||
|
||
// mil to distinguish milliseconds from minutes | ||
// "" when there is just the raw milliseconds value | ||
if (suffix.StartsWith("ms", c) || suffix.StartsWith("mil", c) || suffix == string.Empty) | ||
{ | ||
result = TimeSpan.FromMilliseconds(number); | ||
return true; | ||
} | ||
|
||
if (suffix.StartsWith("s", c)) | ||
{ | ||
result = TimeSpan.FromSeconds(number); | ||
return true; | ||
} | ||
|
||
if (suffix.StartsWith("m", c)) | ||
{ | ||
result = TimeSpan.FromMinutes(number); | ||
return true; | ||
} | ||
|
||
if (suffix.StartsWith("h", c)) | ||
{ | ||
result = TimeSpan.FromHours(number); | ||
return true; | ||
} | ||
|
||
if (suffix.StartsWith("d", c)) | ||
{ | ||
result = TimeSpan.FromDays(number); | ||
return true; | ||
} | ||
|
||
result = TimeSpan.Zero; | ||
return false; | ||
} | ||
|
||
static FormatException GetFormatException(string value) | ||
{ | ||
return new FormatException($"The value '{value}' is not a valid time string. Use a time string in this format 5400000 / 5400000ms / 5400s / 90m / 1.5h / 0.625d."); | ||
} | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
src/Microsoft.TestPlatform.Extensions.BlameDataCollector/Resources/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
87 changes: 87 additions & 0 deletions
87
test/Microsoft.TestPlatform.CoreUtilities.UnitTests/Utilities/TimeSpanParserTests.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,87 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
namespace TestPlatform.CoreUtilities.UnitTests | ||
{ | ||
using Microsoft.VisualStudio.TestPlatform.Utilities; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
|
||
[TestClass] | ||
public class TimeSpanParserTests | ||
{ | ||
[TestMethod] | ||
// core use cases | ||
[DataRow("5400000")] | ||
[DataRow("5400000ms")] | ||
[DataRow("5400s")] | ||
[DataRow("90m")] | ||
[DataRow("1.5h")] | ||
[DataRow("0.0625d")] | ||
|
||
// with space for parsing from xml | ||
[DataRow("5400000 ms")] | ||
[DataRow("5400 s")] | ||
[DataRow("90 m")] | ||
[DataRow("1.5 h")] | ||
[DataRow("0.0625 d")] | ||
|
||
// nice to haves | ||
[DataRow("5400000MS")] | ||
[DataRow("5400000millisecond")] | ||
[DataRow("5400000milliseconds")] | ||
[DataRow("5400000mil")] | ||
[DataRow("5400000milisecond")] | ||
[DataRow("5400000miliseconds")] | ||
[DataRow("5400000mils")] | ||
[DataRow("5400000millis")] | ||
[DataRow("5400000millisecs")] | ||
[DataRow("5400000milisecs")] | ||
[DataRow("5400S")] | ||
[DataRow("5400second")] | ||
[DataRow("5400seconds")] | ||
[DataRow("5400sec")] | ||
[DataRow("5400secs")] | ||
[DataRow("90M")] | ||
[DataRow("90minute")] | ||
[DataRow("90minutes")] | ||
[DataRow("90min")] | ||
[DataRow("90mins")] | ||
[DataRow("1.5H")] | ||
[DataRow("1.5hour")] | ||
[DataRow("1.5hours")] | ||
[DataRow("1.5hrs")] | ||
[DataRow("1.5hr")] | ||
[DataRow("0.0625D")] | ||
[DataRow("0.0625day")] | ||
[DataRow("0.0625days")] | ||
public void Parses90Minutes(string time) | ||
{ | ||
Assert.IsTrue(TimeSpanParser.TryParse(time, out var t)); | ||
Assert.AreEqual(TimeSpan.FromMinutes(90), t); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(null)] | ||
[DataRow("")] | ||
[DataRow(" ")] | ||
[DataRow("\n")] | ||
[DataRow("\t")] | ||
public void ReturnsEmptyTimeSpanOnNullOrWhiteSpace(string time) | ||
{ | ||
Assert.IsTrue(TimeSpanParser.TryParse(time, out var t)); | ||
Assert.AreEqual(TimeSpan.Zero, t); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("09808asf")] | ||
[DataRow("asfsadf")] | ||
[DataRow("min")] | ||
[DataRow("ms")] | ||
[DataRow("1.1.1")] | ||
public void ReturnsFalseForInvalidInput(string time) | ||
{ | ||
Assert.IsFalse(TimeSpanParser.TryParse(time, out var _)); | ||
} | ||
} | ||
} |