Skip to content

Commit

Permalink
Merge branch 'release/7.0.3xx'
Browse files Browse the repository at this point in the history
  • Loading branch information
v-wuzhai committed Mar 13, 2023
2 parents cc24780 + 13edb13 commit da65c01
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 9 deletions.
1 change: 1 addition & 0 deletions build/RunTestsOnHelix.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dotnet new --debug:ephemeral-hive

REM We downloaded a special zip of files to the .nuget folder so add that as a source
dotnet nuget list source --configfile %TestExecutionDirectory%\nuget.config
PowerShell -ExecutionPolicy ByPass "dotnet nuget locals all -l | ForEach-Object { $_.Split(' ')[1]} | Where-Object{$_ -like '*cache'} | Get-ChildItem -Recurse -File -Filter '*.dat' | Measure"
dotnet nuget add source %DOTNET_ROOT%\.nuget --configfile %TestExecutionDirectory%\nuget.config

dotnet nuget remove source dotnet6-transport --configfile %TestExecutionDirectory%\nuget.config
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/CommonOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ internal static string ArchOptionValue(ParseResult parseResult) =>

public static readonly Option<string> TestFrameworkOption = new Option<string>("--Framework");

public static readonly Option<string> TestLoggerOption = new Option<string>("--logger");
public static readonly Option<string[]> TestLoggerOption = new Option<string[]>("--logger");

public static void ValidateSelfContainedOptions(bool hasSelfContainedOption, bool hasNoSelfContainedOption)
{
Expand Down
26 changes: 25 additions & 1 deletion src/Cli/dotnet/Telemetry/TopLevelCommandNameAndOptionToLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,36 @@ public List<ApplicationInsightsEntryFormat> AllowList(ParseResult parseResult, D
new Dictionary<string, string>
{
{ "verb", topLevelCommandName},
{ option.Name, optionValue }
{ option.Name, Stringify(parseResult.GetValueForOption(option)) }
},
measurements));
}
}
return result;
}

/// <summary>
/// We're dealing with untyped payloads here, so we need to handle arrays vs non-array values
/// </summary>
private static string Stringify(object value)
{
if (value is null)
{
return null;
}
if (value is IEnumerable<string> enumerable)
{
return string.Join(";", enumerable);
}
if (value is IEnumerable<object> enumerableOfObjects)
{
return string.Join(";", enumerableOfObjects);
}
if (value is object[] arr)
{
return string.Join(";", arr);
}
return value.ToString();
}
}
}
7 changes: 4 additions & 3 deletions src/Cli/dotnet/commands/dotnet-vstest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ private static string[] GetArgs(ParseResult parseResult)
if (parseResult.HasOption(CommonOptions.TestLoggerOption))
{
// System command line might have mutated the options, reformat test logger option so vstest recognizes it
string loggerValue = parseResult.GetValue(CommonOptions.TestLoggerOption);
args = args.Where(a => !a.Equals(loggerValue) && !CommonOptions.TestLoggerOption.Aliases.Contains(a));
args = args.Prepend($"{CommonOptions.TestLoggerOption.Aliases.First()}:{loggerValue}");
var loggerValues = parseResult.GetValueForOption(CommonOptions.TestLoggerOption);
var loggerArgs = loggerValues.Select(loggerValue => $"{CommonOptions.TestLoggerOption.Aliases.First()}:{loggerValue}");
args = args.Where(a => !loggerValues.Contains(a) && !CommonOptions.TestLoggerOption.Aliases.Contains(a));
args = loggerArgs.Concat(args);
}

return args.ToArray();
Expand Down
9 changes: 5 additions & 4 deletions src/Tests/UnitTests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<PropertyGroup>
<HelixPreCommands Condition="!$(IsPosixShell)">call %HELIX_CORRELATION_PAYLOAD%\t\RunTestsOnHelix.cmd $(TestFullMSBuild);$(HelixPreCommands)</HelixPreCommands>
<HelixPreCommands Condition="$(IsPosixShell)">. $HELIX_CORRELATION_PAYLOAD/t/RunTestsOnHelix.sh;$(HelixPreCommands)</HelixPreCommands>
<HelixPostCommands Condition="!$(IsPosixShell)">PowerShell -ExecutionPolicy ByPass "dotnet nuget locals all -l | ForEach-Object { $_.Split(' ')[1]} | Where-Object{$_ -like '*cache'} | Get-ChildItem -Recurse -File -Filter '*.dat' | Measure";$(HelixPostCommands)</HelixPostCommands>
<TestDotnetRoot>$(RepoRoot)artifacts\bin\redist\$(Configuration)\dotnet</TestDotnetRoot>
<TestDotnetVersion>$(Version)</TestDotnetVersion>
<MSBuildSdkResolverDir>$(RepoRoot)artifacts\bin\Microsoft.DotNet.MSBuildSdkResolver</MSBuildSdkResolverDir>
Expand Down Expand Up @@ -128,16 +129,16 @@
<Destination>r</Destination>
</HelixCorrelationPayload>

<HelixCorrelationPayload Include="SDKTestPackages.System.zip">
<HelixCorrelationPayload Include="SDKTestRunPackages.zip">
<PayloadDirectory>$(TestDotnetRoot)</PayloadDirectory>
<Destination>d/.nuget</Destination>
<Uri>https://netcorenativeassets.blob.core.windows.net/resource-packages/external/any/sdk-test-assets/SDKTestPackages.System.zip</Uri>
<Uri>https://netcorenativeassets.blob.core.windows.net/resource-packages/external/any/sdk-test-assets/SDKTestRunPackages.zip</Uri>
</HelixCorrelationPayload>

<HelixCorrelationPayload Include="SDKTestPackages.Runtime.zip">
<HelixCorrelationPayload Include="SDKTestRunPackages2.zip">
<PayloadDirectory>$(TestDotnetRoot)</PayloadDirectory>
<Destination>d/.nuget</Destination>
<Uri>https://netcorenativeassets.blob.core.windows.net/resource-packages/external/any/sdk-test-assets/SDKTestPackages.Runtime.zip</Uri>
<Uri>https://netcorenativeassets.blob.core.windows.net/resource-packages/external/any/sdk-test-assets/SDKTestRunPackages2.zip</Uri>
</HelixCorrelationPayload>
</ItemGroup>
</Target>
Expand Down
74 changes: 74 additions & 0 deletions src/Tests/dotnet-vstest.Tests/VSTestTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,80 @@ public void ItShouldSetDotnetRootToLocationOfDotnetExecutable()
result.StartInfo.EnvironmentVariables[dotnetRoot].Should().Be(Path.GetDirectoryName(dotnet));
}

[Fact]
public void ItShouldAcceptMultipleLoggers()
{
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();

var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

new BuildCommand(Log, testProjectDirectory)
.Execute()
.Should().Pass();

var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, ToolsetInfo.CurrentTargetFramework, "VSTestTestRunParameters.dll");

var logFileName = $"{Path.GetTempFileName()}.trx";
// Call test
CommandResult result = new DotnetVSTestCommand(Log)
.Execute(new[] {
outputDll,
"--logger:console;verbosity=normal",
$"--logger:trx;LogFileName={logFileName}",
"--",
"TestRunParameters.Parameter(name=\"myParam\",",
"value=\"value\")",
"TestRunParameters.Parameter(name=\"myParam2\",",
"value=\"value",
"with",
"space\")"
});

// Verify
if (!TestContext.IsLocalized())
{
result.StdOut.Should().NotMatch("The test run parameter argument '*' is invalid.");
result.StdOut.Should().Contain("Total tests: 1");
result.StdOut.Should().Contain("Passed: 1");
result.StdOut.Should().Contain("Passed VSTestTestRunParameters");
}
result.ExitCode.Should().Be(0, $"Should have executed successfully, but got: {result.StdOut}");

var testResultsDirectory = new FileInfo(Path.Combine(Environment.CurrentDirectory, "TestResults", logFileName));
testResultsDirectory.Exists.Should().BeTrue("expected the test results file to be created");
}

[Fact]
public void ItShouldAcceptNoLoggers()
{
var testProjectDirectory = this.CopyAndRestoreVSTestDotNetCoreTestApp();

var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";

new BuildCommand(Log, testProjectDirectory)
.Execute()
.Should().Pass();

var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, ToolsetInfo.CurrentTargetFramework, "VSTestTestRunParameters.dll");

// Call test
CommandResult result = new DotnetVSTestCommand(Log)
.Execute(new[] {
outputDll,
"--",
"TestRunParameters.Parameter(name=\"myParam\",",
"value=\"value\")",
"TestRunParameters.Parameter(name=\"myParam2\",",
"value=\"value",
"with",
"space\")"
});

//Verify
// since there are no loggers, all we have to go on it the exit code
result.ExitCode.Should().Be(0, $"Should have executed successfully, but got: {result.StdOut}");
}

private string CopyAndRestoreVSTestDotNetCoreTestApp([CallerMemberName] string callingMethod = "")
{
// Copy VSTestCore project in output directory of project dotnet-vstest.Tests
Expand Down

0 comments on commit da65c01

Please sign in to comment.