Skip to content

Commit

Permalink
#2385: TeamCity logger uses wrong flowId
Browse files Browse the repository at this point in the history
  • Loading branch information
bradwilson committed May 9, 2023
1 parent da319e0 commit 2dba64b
Show file tree
Hide file tree
Showing 17 changed files with 498 additions and 262 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<DebugType Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework' ">full</DebugType>
<DebugType Condition=" '$(TargetFrameworkIdentifier)' != '.NETFramework' ">embedded</DebugType>
<DefineConstants>$(DefineConstants);XUNIT_IMMUTABLE_COLLECTIONS;XUNIT_NULLABLE;XUNIT_SKIP;XUNIT_SPAN;XUNIT_VALUETASK</DefineConstants>
<LangVersion>11.0</LangVersion>
<LangVersion>10.0</LangVersion>
<NoWarn>$(NoWarn);NU5105</NoWarn>
<RootNamespace>Xunit</RootNamespace>
<SignAssembly>true</SignAssembly>
Expand Down
5 changes: 5 additions & 0 deletions src/common.tests/TestDoubles/SpyRunnerLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public SpyRunnerLogger()
AddMessage("---", stackFrame, message);
}

public void LogRaw(string message)
{
AddMessage("Raw", StackFrameInfo.None, message);
}

public void LogWarning(
StackFrameInfo stackFrame,
string message)
Expand Down
46 changes: 46 additions & 0 deletions src/common.tests/Utility/EnvironmentHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,57 @@
#nullable enable

using System;
using System.Collections.Generic;

static class EnvironmentHelper
{
static readonly Lazy<bool> isMono = new Lazy<bool>(() => Type.GetType("Mono.Runtime") != null);
static readonly string[] reporterEnvironmentVariables =
{
// AppVeyorReporter
"APPVEYOR_API_URL",
// TeamCityReporter
"TEAMCITY_PROJECT_NAME",
"TEAMCITY_PROCESS_FLOW_ID",
// VstsReporter
"VSTS_ACCESS_TOKEN",
"SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",
"SYSTEM_TEAMPROJECT",
"BUILD_BUILDID",
};

/// <summary>
/// Returns <c>true</c> if you're currently running in Mono; <c>false</c> if you're running in .NET Framework.
/// </summary>
public static bool IsMono => isMono.Value;

public static IDisposable NullifyEnvironmentalReporters()
{
var result = new EnvironmentRestorer(reporterEnvironmentVariables);

foreach (var variable in reporterEnvironmentVariables)
Environment.SetEnvironmentVariable(variable, null);

return result;
}

public static IDisposable RestoreEnvironment(params string[] variables) =>
new EnvironmentRestorer(variables);

class EnvironmentRestorer : IDisposable
{
Dictionary<string, string?> savedVariables = new();

public EnvironmentRestorer(string[] variables)
{
foreach (var variable in variables)
savedVariables[variable] = Environment.GetEnvironmentVariable(variable);
}

public void Dispose()
{
foreach (var kvp in savedVariables)
Environment.SetEnvironmentVariable(kvp.Key, kvp.Value);
}
}
}
2 changes: 1 addition & 1 deletion src/xunit.v3.assert/Asserts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ public void BaseSerializationIncludesTypeName()

var result = Encoding.UTF8.GetString(msg.ToJson());

var expected = """
{
"$type": "_MessageSinkMessage"
}
""".Replace("\n", "");
var expected =
@"{
""$type"": ""_MessageSinkMessage""
}".Replace("\n", "");
Assert.Equal(expected, result, ignoreAllWhiteSpace: true);
}

Expand All @@ -43,16 +42,15 @@ public void SerializationExcludesNullValues()

var result = Encoding.UTF8.GetString(msg.ToJson());

var expected = """
{
"$type": "_TestAssemblyStarting",
"AssemblyName": "asm-name",
"StartTime": "2020-09-26T13:55:27.212-07:00",
"TestEnvironment": "test-env",
"TestFrameworkDisplayName": "test-framework",
"AssemblyUniqueID": "asm-id"
}
""".Replace("\n", "");
var expected =
@"{
""$type"": ""_TestAssemblyStarting"",
""AssemblyName"": ""asm-name"",
""StartTime"": ""2020-09-26T13:55:27.212-07:00"",
""TestEnvironment"": ""test-env"",
""TestFrameworkDisplayName"": ""test-framework"",
""AssemblyUniqueID"": ""asm-id""
}".Replace("\n", "");
Assert.Equal(expected, result, ignoreAllWhiteSpace: true);
}

Expand All @@ -76,22 +74,21 @@ public void SerializesEnumsAsStrings()

var result = Encoding.UTF8.GetString(msg.ToJson());

var expected = """
{
"$type": "_TestFailed",
"Cause": "Assertion",
"ExceptionParentIndices": [-1],
"ExceptionTypes": ["exception-type"],
"Messages": ["exception-message"],
"StackTraces": ["stack-trace"],
"ExecutionTime": 123.45,
"Output": "",
"TestUniqueID": "test-id",
"TestCaseUniqueID": "test-case-id",
"TestCollectionUniqueID": "test-collection-id",
"AssemblyUniqueID": "asm-id"
}
""".Replace("\n", "");
var expected =
@"{
""$type"": ""_TestFailed"",
""Cause"": ""Assertion"",
""ExceptionParentIndices"": [-1],
""ExceptionTypes"": [""exception-type""],
""Messages"": [""exception-message""],
""StackTraces"": [""stack-trace""],
""ExecutionTime"": 123.45,
""Output"": """",
""TestUniqueID"": ""test-id"",
""TestCaseUniqueID"": ""test-case-id"",
""TestCollectionUniqueID"": ""test-collection-id"",
""AssemblyUniqueID"": ""asm-id""
}".Replace("\n", "");
Assert.Equal(expected, result, ignoreAllWhiteSpace: true);
}

Expand All @@ -103,22 +100,21 @@ class TestMessageWithEnum : _MessageSinkMessage
[Fact]
public void DeserializesEnumsAsStrings()
{
var msg = """
{
"$type": "_TestFailed",
"Cause": "Assertion",
"ExceptionParentIndices": [-1],
"ExceptionTypes": ["exception-type"],
"Messages": ["exception-message"],
"StackTraces": ["stack-trace"],
"ExecutionTime": 123.45,
"Output": "",
"TestUniqueID": "test-id",
"TestCaseUniqueID": "test-case-id",
"TestCollectionUniqueID": "test-collection-id",
"AssemblyUniqueID": "asm-id"
}
""";
var msg =
@"{
""$type"": ""_TestFailed"",
""Cause"": ""Assertion"",
""ExceptionParentIndices"": [-1],
""ExceptionTypes"": [""exception-type""],
""Messages"": [""exception-message""],
""StackTraces"": [""stack-trace""],
""ExecutionTime"": 123.45,
""Output"": """",
""TestUniqueID"": ""test-id"",
""TestCaseUniqueID"": ""test-case-id"",
""TestCollectionUniqueID"": ""test-collection-id"",
""AssemblyUniqueID"": ""asm-id""
}";

var result = _MessageSinkMessage.ParseJson(Encoding.UTF8.GetBytes(msg));

Expand Down Expand Up @@ -148,22 +144,21 @@ public void CanRoundTripTraits()

var serialized = msg.ToJson();

var expected = """
{
"$type": "_TestCaseDiscovered",
"Serialization": "serialized-value",
"TestCaseDisplayName": "test-case-display-name",
"Traits":
{
"foo": ["bar", "baz"],
"abc": ["123"],
"empty": []
},
"TestCaseUniqueID": "test-case-id",
"TestCollectionUniqueID": "test-collection-id",
"AssemblyUniqueID": "asm-id"
}
""".Replace("\n", "");
var expected =
@"{
""$type"": ""_TestCaseDiscovered"",
""Serialization"": ""serialized-value"",
""TestCaseDisplayName"": ""test-case-display-name"",
""Traits"":
{
""foo"": [""bar"", ""baz""],
""abc"": [""123""],
""empty"": []
},
""TestCaseUniqueID"": ""test-case-id"",
""TestCollectionUniqueID"": ""test-collection-id"",
""AssemblyUniqueID"": ""asm-id""
}".Replace("\n", "");
Assert.Equal(expected, Encoding.UTF8.GetString(serialized), ignoreAllWhiteSpace: true);

// Validate deserialization
Expand Down

0 comments on commit 2dba64b

Please sign in to comment.