Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Test Information from the New Testing Platform #42494

Merged
merged 16 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/Cli/dotnet/commands/dotnet-test/CliConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,42 @@ internal static class CliConstants
public const string ServerOptionValue = "dotnettestcli";

public const string MSBuildExeName = "MSBuild.dll";
}

internal static class TestStates
{
internal const string Passed = "Passed";

internal const string Skipped = "Skipped";

internal const string Failed = "Failed";

internal const string Error = "Error";

internal const string Timeout = "Timeout";

internal const string Cancelled = "Cancelled";
}

internal static class SessionEventTypes
{
internal const string TestSessionStart = "TestSessionStart";
internal const string TestSessionEnd = "TestSessionEnd";
}

internal static class HandshakeInfoPropertyNames
{
internal const string PID = "PID";
internal const string Architecture = "Architecture";
internal const string Framework = "Framework";
internal const string OS = "OS";
internal const string ProtocolVersion = "ProtocolVersion";
internal const string HostType = "HostType";
internal const string ModulePath = "ModulePath";
}

internal static class ProtocolConstants
{
internal const string Version = "1.0.0";
}
}
36 changes: 34 additions & 2 deletions src/Cli/dotnet/commands/dotnet-test/CustomEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,45 @@

namespace Microsoft.DotNet.Cli
{
internal class ErrorEventArgs : EventArgs
internal class HandshakeInfoArgs : EventArgs
{
public string ErrorMessage { get; set; }
public HandshakeInfo handshakeInfo { get; set; }
}

internal class HelpEventArgs : EventArgs
{
public CommandLineOptionMessages CommandLineOptionMessages { get; set; }
}

internal class SuccessfulTestResultEventArgs : EventArgs
{
public SuccessfulTestResultMessage SuccessfulTestResultMessage { get; set; }
}

internal class FailedTestResultEventArgs : EventArgs
{
public FailedTestResultMessage FailedTestResultMessage { get; set; }
}

internal class FileArtifactInfoEventArgs : EventArgs
{
public FileArtifactInfo FileArtifactInfo { get; set; }
}

internal class SessionEventArgs : EventArgs
{
public TestSessionEvent SessionEvent { get; set; }
}

internal class ErrorEventArgs : EventArgs
{
public string ErrorMessage { get; set; }
}

internal class TestProcessExitEventArgs : EventArgs
{
public List<string> OutputData { get; set; }
public List<string> ErrorData { get; set; }
public int ExitCode { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record CommandLineOptionMessage(string Name, string Description, bool IsHidden, bool IsBuiltIn) : IRequest;
internal sealed record CommandLineOptionMessage(string? Name, string? Description, bool? IsHidden, bool? IsBuiltIn) : IRequest;

internal sealed record CommandLineOptionMessages(string ModulePath, CommandLineOptionMessage[] CommandLineOptionMessageList) : IRequest;
internal sealed record CommandLineOptionMessages(string? ModulePath, CommandLineOptionMessage[]? CommandLineOptionMessageList) : IRequest;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record FileArtifactInfo(string? FullPath, string? DisplayName, string? Description, string? TestUid, string? TestDisplayName, string? SessionUid, string? ModulePath) : IRequest;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record HandshakeInfo(Dictionary<string, string>? Properties) : IRequest, IResponse;
}
4 changes: 3 additions & 1 deletion src/Cli/dotnet/commands/dotnet-test/IPC/Models/Module.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

namespace Microsoft.DotNet.Tools.Test;

internal sealed record class Module(string DLLPath, string ProjectPath) : IRequest;
internal sealed record class Module(string? DLLPath, string? ProjectPath) : IRequest;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record SuccessfulTestResultMessage(string? Uid, string? DisplayName, string? State, string? Reason, string? SessionUid, string? ModulePath) : IRequest;

internal sealed record FailedTestResultMessage(string? Uid, string? DisplayName, string? State, string? Reason, string? ErrorMessage, string? ErrorStackTrace, string? SessionUid, string? ModulePath) : IRequest;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#nullable enable

namespace Microsoft.DotNet.Tools.Test
{
internal sealed record TestSessionEvent(string? SessionType, string? SessionUid, string? ModulePath) : IRequest;
}
40 changes: 40 additions & 0 deletions src/Cli/dotnet/commands/dotnet-test/IPC/ObjectFieldIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,44 @@ internal static class CommandLineOptionMessageFieldsId
internal const int IsHidden = 3;
internal const int IsBuiltIn = 4;
}

internal static class SuccessfulTestResultMessageFieldsId
{
internal const int Uid = 1;
internal const int DisplayName = 2;
internal const int State = 3;
internal const int Reason = 4;
internal const int SessionUid = 5;
internal const int ModulePath = 6;
}

internal static class FailedTestResultMessageFieldsId
{
internal const int Uid = 1;
internal const int DisplayName = 2;
internal const int State = 3;
internal const int Reason = 4;
internal const int ErrorMessage = 5;
internal const int ErrorStackTrace = 6;
internal const int SessionUid = 7;
internal const int ModulePath = 8;
}

internal static class FileArtifactInfoFieldsId
{
internal const int FullPath = 1;
internal const int DisplayName = 2;
internal const int Description = 3;
internal const int TestUid = 4;
internal const int TestDisplayName = 5;
internal const int SessionUid = 6;
internal const int ModulePath = 7;
}

internal static class TestSessionEventFieldsId
{
internal const int SessionType = 1;
internal const int SessionUid = 2;
internal const int ModulePath = 3;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,26 @@ protected static void WriteField(Stream stream, ushort id, string? value)
WriteString(stream, value);
}

protected static void WriteField(Stream stream, ushort id, bool value)
protected static void WriteField(Stream stream, string? value)
{
if (value is null)
{
return;
}

WriteString(stream, value);
}

protected static void WriteField(Stream stream, ushort id, bool? value)
{
if (value is null)
{
return;
}

WriteShort(stream, id);
WriteSize<bool>(stream);
WriteBool(stream, value);
WriteBool(stream, value.Value);
}

protected static void SetPosition(Stream stream, long position) => stream.Position = position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal sealed class CommandLineOptionMessagesSerializer : BaseSerializer, INam

public object Deserialize(Stream stream)
{
string moduleName = string.Empty;
string? moduleName = null;
List<CommandLineOptionMessage>? commandLineOptionMessages = null;

ushort fieldCount = ReadShort(stream);
Expand Down Expand Up @@ -83,8 +83,8 @@ private static List<CommandLineOptionMessage> ReadCommandLineOptionMessagesPaylo
int length = ReadInt(stream);
for (int i = 0; i < length; i++)
{
string name = string.Empty, description = string.Empty, arity = string.Empty;
bool isHidden = false, isBuiltIn = false;
string? name = null, description = null;
bool? isHidden = null, isBuiltIn = null;

int fieldCount = ReadShort(stream);

Expand Down Expand Up @@ -135,9 +135,9 @@ public void Serialize(object objectToSerialize, Stream stream)
WriteCommandLineOptionMessagesPayload(stream, commandLineOptionMessages.CommandLineOptionMessageList);
}

private static void WriteCommandLineOptionMessagesPayload(Stream stream, CommandLineOptionMessage[] commandLineOptionMessageList)
private static void WriteCommandLineOptionMessagesPayload(Stream stream, CommandLineOptionMessage[]? commandLineOptionMessageList)
{
if (IsNull(commandLineOptionMessageList))
if (commandLineOptionMessageList is null || commandLineOptionMessageList.Length == 0)
{
return;
}
Expand Down Expand Up @@ -165,13 +165,13 @@ private static void WriteCommandLineOptionMessagesPayload(Stream stream, Command
WriteAtPosition(stream, (int)(stream.Position - before), before - sizeof(int));
}

private static ushort GetFieldCount(CommandLineOptionMessages commandLineOptionMessages) => (ushort)((string.IsNullOrEmpty(commandLineOptionMessages.ModulePath) ? 0 : 1) +
(commandLineOptionMessages is null ? 0 : 1));
private static ushort GetFieldCount(CommandLineOptionMessages commandLineOptionMessages) =>
(ushort)((commandLineOptionMessages.ModulePath is null ? 0 : 1) +
(commandLineOptionMessages is null ? 0 : 1));

private static ushort GetFieldCount(CommandLineOptionMessage commandLineOptionMessage) => (ushort)((string.IsNullOrEmpty(commandLineOptionMessage.Name) ? 0 : 1) +
(string.IsNullOrEmpty(commandLineOptionMessage.Description) ? 0 : 1) +
2);

private static bool IsNull<T>(T[] items) => items is null || items.Length == 0;
private static ushort GetFieldCount(CommandLineOptionMessage commandLineOptionMessage) =>
(ushort)((commandLineOptionMessage.Name is null ? 0 : 1) +
(commandLineOptionMessage.Description is null ? 0 : 1) +
2);
}
}
Loading
Loading