You've already forked linux-packaging-mono
Imported Upstream version 5.8.0.22
Former-commit-id: df344e34b07851d296efb3e6604c8db42b6f7aa3
This commit is contained in:
parent
5f4a27cc8a
commit
7d05485754
@@ -2,6 +2,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Diagnostics.StackTrace.Tests", "tests\System.Diagnostics.StackTrace.Tests.csproj", "{297A9116-1005-499D-A895-2063D03E4C94}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{02304469-722E-4723-92A1-820B9A37D275} = {02304469-722E-4723-92A1-820B9A37D275}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Diagnostics.StackTrace", "src\System.Diagnostics.StackTrace.csproj", "{02304469-722E-4723-92A1-820B9A37D275}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{C38217EF-88F4-4D56-9F58-780BE1DDAFF6} = {C38217EF-88F4-4D56-9F58-780BE1DDAFF6}
|
||||
@@ -9,6 +14,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Diagnostics.StackTra
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "System.Diagnostics.StackTrace", "ref\System.Diagnostics.StackTrace.csproj", "{C38217EF-88F4-4D56-9F58-780BE1DDAFF6}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{1A2F9F4A-A032-433E-B914-ADD5992BB178}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E107E9C1-E893-4E87-987E-04EF0DCEAEFD}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ref", "ref", "{2E666815-2EDB-464B-9DF6-380BF4789AD4}"
|
||||
@@ -19,6 +26,10 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{297A9116-1005-499D-A895-2063D03E4C94}.Debug|Any CPU.ActiveCfg = netstandard-Debug|Any CPU
|
||||
{297A9116-1005-499D-A895-2063D03E4C94}.Debug|Any CPU.Build.0 = netstandard-Debug|Any CPU
|
||||
{297A9116-1005-499D-A895-2063D03E4C94}.Release|Any CPU.ActiveCfg = netstandard-Release|Any CPU
|
||||
{297A9116-1005-499D-A895-2063D03E4C94}.Release|Any CPU.Build.0 = netstandard-Release|Any CPU
|
||||
{02304469-722E-4723-92A1-820B9A37D275}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
|
||||
{02304469-722E-4723-92A1-820B9A37D275}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
|
||||
{02304469-722E-4723-92A1-820B9A37D275}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
|
||||
@@ -32,6 +43,7 @@ Global
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{297A9116-1005-499D-A895-2063D03E4C94} = {1A2F9F4A-A032-433E-B914-ADD5992BB178}
|
||||
{02304469-722E-4723-92A1-820B9A37D275} = {E107E9C1-E893-4E87-987E-04EF0DCEAEFD}
|
||||
{C38217EF-88F4-4D56-9F58-780BE1DDAFF6} = {2E666815-2EDB-464B-9DF6-380BF4789AD4}
|
||||
EndGlobalSection
|
||||
|
9
external/corefx/src/System.Diagnostics.StackTrace/tests/Configurations.props
vendored
Normal file
9
external/corefx/src/System.Diagnostics.StackTrace/tests/Configurations.props
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
netstandard;
|
||||
netfx;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
93
external/corefx/src/System.Diagnostics.StackTrace/tests/StackFrameExtensionsTests.cs
vendored
Normal file
93
external/corefx/src/System.Diagnostics.StackTrace/tests/StackFrameExtensionsTests.cs
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "StackFrame is not supported in uapaot.")]
|
||||
public class StackFrameExtensionsTests
|
||||
{
|
||||
public static IEnumerable<object[]> StackFrame_TestData()
|
||||
{
|
||||
yield return new object[] { null };
|
||||
yield return new object[] { new StackFrame() };
|
||||
yield return new object[] { new StackFrame(int.MaxValue) };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(StackFrame_TestData))]
|
||||
public void HasNativeImage_StackFrame_ReturnsFalse(StackFrame stackFrame)
|
||||
{
|
||||
Assert.False(stackFrame.HasNativeImage());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(StackFrame_TestData))]
|
||||
public void GetNativeIP_StackFrame_ReturnsZero(StackFrame stackFrame)
|
||||
{
|
||||
Assert.Equal(IntPtr.Zero, stackFrame.GetNativeIP());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(StackFrame_TestData))]
|
||||
public void GetNativeImageBase_StackFrame_ReturnsZero(StackFrame stackFrame)
|
||||
{
|
||||
Assert.Equal(IntPtr.Zero, stackFrame.GetNativeImageBase());
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> HasMethod_TestData()
|
||||
{
|
||||
yield return new object[] { new StackFrame(), true };
|
||||
yield return new object[] { new StackFrame(int.MaxValue), false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(HasMethod_TestData))]
|
||||
public void HasILOffset_Invoke_ReturnsExpected(StackFrame stackFrame, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, stackFrame.HasILOffset());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasILOffset_NullStackFrame_ThrowsNullReferenceException()
|
||||
{
|
||||
Assert.Throws<NullReferenceException>(() => StackFrameExtensions.HasILOffset(null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(HasMethod_TestData))]
|
||||
public void HasMethod_Invoke_ReturnsExpected(StackFrame stackFrame, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, stackFrame.HasMethod());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasMethod_NullStackFrame_ThrowsNullReferenceException()
|
||||
{
|
||||
Assert.Throws<NullReferenceException>(() => StackFrameExtensions.HasMethod(null));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> HasSource_TestData()
|
||||
{
|
||||
yield return new object[] { new StackFrame(), false };
|
||||
yield return new object[] { new StackFrame("FileName", 1), true };
|
||||
yield return new object[] { new StackFrame(int.MaxValue), false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(HasSource_TestData))]
|
||||
public void HasSource_Invoke_ReturnsExpected(StackFrame stackFrame, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, stackFrame.HasSource());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasSource_NullStackFrame_ThrowsNullReferenceException()
|
||||
{
|
||||
Assert.Throws<NullReferenceException>(() => StackFrameExtensions.HasSource(null));
|
||||
}
|
||||
}
|
||||
}
|
205
external/corefx/src/System.Diagnostics.StackTrace/tests/StackFrameTests.cs
vendored
Normal file
205
external/corefx/src/System.Diagnostics.StackTrace/tests/StackFrameTests.cs
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "StackFrame is not supported in uapaot.")]
|
||||
public class StackFrameTests
|
||||
{
|
||||
[Fact]
|
||||
public void OffsetUnknown_Get_ReturnsNegativeOne()
|
||||
{
|
||||
Assert.Equal(-1, StackFrame.OFFSET_UNKNOWN);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
var stackFrame = new StackFrame();
|
||||
VerifyStackFrame(stackFrame, false, 0, typeof(StackFrameTests).GetMethod(nameof(Ctor_Default)), isCurrentFrame: true);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Ctor_FNeedFileInfo(bool fNeedFileInfo)
|
||||
{
|
||||
var stackFrame = new StackFrame(fNeedFileInfo);
|
||||
VerifyStackFrame(stackFrame, fNeedFileInfo, 0, typeof(StackFrameTests).GetMethod(nameof(Ctor_FNeedFileInfo)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(StackFrame.OFFSET_UNKNOWN)]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
public void Ctor_SkipFrames(int skipFrames)
|
||||
{
|
||||
var stackFrame = new StackFrame(skipFrames);
|
||||
VerifyStackFrame(stackFrame, true, skipFrames, typeof(StackFrameTests).GetMethod(nameof(Ctor_SkipFrames)), isCurrentFrame: skipFrames == 0);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(StackFrame.OFFSET_UNKNOWN, true)]
|
||||
[InlineData(0, true)]
|
||||
[InlineData(1, true)]
|
||||
[InlineData(StackFrame.OFFSET_UNKNOWN, false)]
|
||||
[InlineData(0, false)]
|
||||
[InlineData(1, false)]
|
||||
public void Ctor_SkipFrames_FNeedFileInfo(int skipFrames, bool fNeedFileInfo)
|
||||
{
|
||||
var stackFrame = new StackFrame(skipFrames, fNeedFileInfo);
|
||||
VerifyStackFrame(stackFrame, fNeedFileInfo, skipFrames, typeof(StackFrameTests).GetMethod(nameof(Ctor_SkipFrames_FNeedFileInfo)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SkipFrames_CallMethod_ReturnsExpected()
|
||||
{
|
||||
StackFrame stackFrame = CallMethod(1);
|
||||
MethodInfo expectedMethod = typeof(StackFrameTests).GetMethod(nameof(SkipFrames_CallMethod_ReturnsExpected));
|
||||
#if DEBUG
|
||||
Assert.Equal(expectedMethod, stackFrame.GetMethod());
|
||||
#else
|
||||
Assert.NotEqual(expectedMethod, stackFrame.GetMethod());
|
||||
#endif
|
||||
}
|
||||
|
||||
public StackFrame CallMethod(int skipFrames) => new StackFrame(skipFrames);
|
||||
|
||||
[Theory]
|
||||
[InlineData(int.MinValue)]
|
||||
[InlineData(int.MaxValue)]
|
||||
public void SkipFrames_ManyFrames_HasNoMethod(int skipFrames)
|
||||
{
|
||||
var stackFrame = new StackFrame(skipFrames);
|
||||
VerifyStackFrame(stackFrame, true, skipFrames, null);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, StackFrame.OFFSET_UNKNOWN)]
|
||||
[InlineData("", 0)]
|
||||
[InlineData("FileName", 1)]
|
||||
public void Ctor_Filename_LineNumber(string fileName, int lineNumber)
|
||||
{
|
||||
var stackFrame = new StackFrame(fileName, lineNumber);
|
||||
Assert.Equal(fileName, stackFrame.GetFileName());
|
||||
Assert.Equal(lineNumber, stackFrame.GetFileLineNumber());
|
||||
Assert.Equal(0, stackFrame.GetFileColumnNumber());
|
||||
|
||||
VerifyStackFrameSkipFrames(stackFrame, true, 0, typeof(StackFrameTests).GetMethod(nameof(Ctor_Filename_LineNumber)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null, StackFrame.OFFSET_UNKNOWN, 0)]
|
||||
[InlineData("", 0, StackFrame.OFFSET_UNKNOWN)]
|
||||
[InlineData("FileName", 1, 2)]
|
||||
public void Ctor_Filename_LineNumber_ColNumber(string fileName, int lineNumber, int columnNumber)
|
||||
{
|
||||
var stackFrame = new StackFrame(fileName, lineNumber, columnNumber);
|
||||
Assert.Equal(fileName, stackFrame.GetFileName());
|
||||
Assert.Equal(lineNumber, stackFrame.GetFileLineNumber());
|
||||
Assert.Equal(columnNumber, stackFrame.GetFileColumnNumber());
|
||||
|
||||
VerifyStackFrameSkipFrames(stackFrame, true, 0, typeof(StackFrameTests).GetMethod(nameof(Ctor_Filename_LineNumber_ColNumber)));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ToString_TestData()
|
||||
{
|
||||
#if DEBUG
|
||||
yield return new object[] { new StackFrame(), "MoveNext at offset {offset} in file:line:column {fileName}:{lineNumber}:{column}" + Environment.NewLine };
|
||||
yield return new object[] { new StackFrame("FileName", 1, 2), "MoveNext at offset {offset} in file:line:column FileName:1:2" + Environment.NewLine };
|
||||
yield return new object[] { new StackFrame(int.MaxValue), "<null>" + Environment.NewLine };
|
||||
yield return new object[] { GenericMethod<string>(), "GenericMethod<T> at offset {offset} in file:line:column {fileName}:{lineNumber}:{column}" + Environment.NewLine };
|
||||
yield return new object[] { GenericMethod<string, int>(), "GenericMethod<T,U> at offset {offset} in file:line:column {fileName}:{lineNumber}:{column}" + Environment.NewLine };
|
||||
yield return new object[] { new ClassWithConstructor().StackFrame, ".ctor at offset {offset} in file:line:column {fileName}:{lineNumber}:{column}" + Environment.NewLine };
|
||||
#else
|
||||
yield break;
|
||||
#endif
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ToString_TestData))]
|
||||
public void ToString_Invoke_ReturnsExpected(StackFrame stackFrame, string expectedToString)
|
||||
{
|
||||
expectedToString = expectedToString.Replace("{offset}", stackFrame.GetNativeOffset().ToString())
|
||||
.Replace("{fileName}", stackFrame.GetFileName() ?? "<filename unknown>")
|
||||
.Replace("{lineNumber}", stackFrame.GetFileLineNumber().ToString())
|
||||
.Replace("{column}", stackFrame.GetFileLineNumber().ToString());
|
||||
Assert.Equal(expectedToString, stackFrame.ToString());
|
||||
}
|
||||
|
||||
private static StackFrame GenericMethod<T>() => new StackFrame();
|
||||
private static StackFrame GenericMethod<T, U>() => new StackFrame();
|
||||
|
||||
private class ClassWithConstructor
|
||||
{
|
||||
public StackFrame StackFrame { get; }
|
||||
public ClassWithConstructor() => StackFrame = new StackFrame();
|
||||
}
|
||||
|
||||
private static void VerifyStackFrame(StackFrame stackFrame, bool hasFileInfo, int skipFrames, MethodInfo expectedMethod, bool isCurrentFrame = false)
|
||||
{
|
||||
if (!hasFileInfo)
|
||||
{
|
||||
Assert.Null(stackFrame.GetFileName());
|
||||
Assert.Equal(0, stackFrame.GetFileLineNumber());
|
||||
Assert.Equal(0, stackFrame.GetFileColumnNumber());
|
||||
}
|
||||
|
||||
VerifyStackFrameSkipFrames(stackFrame, false, skipFrames, expectedMethod, isCurrentFrame);
|
||||
}
|
||||
|
||||
private static void VerifyStackFrameSkipFrames(StackFrame stackFrame, bool isFileConstructor, int skipFrames, MethodInfo expectedMethod, bool isCurrentFrame = false)
|
||||
{
|
||||
// GetILOffset returns StackFrame.OFFSET_UNKNOWN for unknown frames.
|
||||
if (skipFrames == int.MinValue || skipFrames > 0)
|
||||
{
|
||||
Assert.Equal(StackFrame.OFFSET_UNKNOWN, stackFrame.GetILOffset());
|
||||
}
|
||||
#if !DEBUG
|
||||
else if ((!PlatformDetection.IsFullFramework && isFileConstructor) || (PlatformDetection.IsFullFramework && !isFileConstructor && !isCurrentFrame && skipFrames == 0))
|
||||
{
|
||||
Assert.Equal(0, stackFrame.GetILOffset());
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
Assert.True(stackFrame.GetILOffset() > 0, $"Expected GetILOffset() {stackFrame.GetILOffset()} for {stackFrame} to be greater than zero.");
|
||||
}
|
||||
|
||||
// GetMethod returns null for unknown frames.
|
||||
if (expectedMethod == null)
|
||||
{
|
||||
Assert.Null(stackFrame.GetMethod());
|
||||
}
|
||||
else if (skipFrames == 0)
|
||||
{
|
||||
Assert.Equal(expectedMethod, stackFrame.GetMethod());
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.NotEqual(expectedMethod, stackFrame.GetMethod());
|
||||
}
|
||||
|
||||
// GetNativeOffset returns StackFrame.OFFSET_UNKNOWN for unknown frames.
|
||||
// GetNativeOffset returns 0 for known frames with a positive skipFrames.
|
||||
if (skipFrames == int.MaxValue || skipFrames == int.MinValue)
|
||||
{
|
||||
Assert.Equal(StackFrame.OFFSET_UNKNOWN, stackFrame.GetNativeOffset());
|
||||
}
|
||||
else if (skipFrames <= 0)
|
||||
{
|
||||
Assert.True(stackFrame.GetNativeOffset() > 0, $"Expected GetNativeOffset() {stackFrame.GetNativeOffset()} for {stackFrame} to be greater than zero.");
|
||||
Assert.True(stackFrame.GetNativeOffset() > 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal(0, stackFrame.GetNativeOffset());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
377
external/corefx/src/System.Diagnostics.StackTrace/tests/StackTraceTests.cs
vendored
Normal file
377
external/corefx/src/System.Diagnostics.StackTrace/tests/StackTraceTests.cs
vendored
Normal file
@@ -0,0 +1,377 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics
|
||||
{
|
||||
public static class Ignored
|
||||
{
|
||||
public static StackTrace Method() => new StackTrace();
|
||||
public static StackTrace MethodWithException()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return new StackTrace(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace System.Diagnostics.Tests
|
||||
{
|
||||
[SkipOnTargetFramework(TargetFrameworkMonikers.UapAot, "StackTrace is not supported in uapaot.")]
|
||||
public class StackTraceTests
|
||||
{
|
||||
[Fact]
|
||||
public void MethodsToSkip_Get_ReturnsZero()
|
||||
{
|
||||
Assert.Equal(0, StackTrace.METHODS_TO_SKIP);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
var stackTrace = new StackTrace();
|
||||
VerifyFrames(stackTrace, false);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Ctor_FNeedFileInfo(bool fNeedFileInfo)
|
||||
{
|
||||
var stackTrace = new StackTrace(fNeedFileInfo);
|
||||
VerifyFrames(stackTrace, fNeedFileInfo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
public void Ctor_SkipFrames(int skipFrames)
|
||||
{
|
||||
var emptyStackTrace = new StackTrace();
|
||||
IEnumerable<MethodBase> expectedMethods = emptyStackTrace.GetFrames().Skip(skipFrames).Select(f => f.GetMethod());
|
||||
|
||||
var stackTrace = new StackTrace(skipFrames);
|
||||
Assert.Equal(emptyStackTrace.FrameCount - skipFrames, stackTrace.FrameCount);
|
||||
Assert.Equal(expectedMethods, stackTrace.GetFrames().Select(f => f.GetMethod()));
|
||||
|
||||
VerifyFrames(stackTrace, false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_LargeSkipFrames_GetFramesReturnsNull()
|
||||
{
|
||||
var stackTrace = new StackTrace(int.MaxValue);
|
||||
Assert.Equal(0, stackTrace.FrameCount);
|
||||
Assert.Null(stackTrace.GetFrames());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, true)]
|
||||
[InlineData(1, true)]
|
||||
[InlineData(0, false)]
|
||||
[InlineData(1, false)]
|
||||
public void Ctor_SkipFrames_FNeedFileInfo(int skipFrames, bool fNeedFileInfo)
|
||||
{
|
||||
var emptyStackTrace = new StackTrace();
|
||||
IEnumerable<MethodBase> expectedMethods = emptyStackTrace.GetFrames().Skip(skipFrames).Select(f => f.GetMethod());
|
||||
|
||||
var stackTrace = new StackTrace(skipFrames, fNeedFileInfo);
|
||||
Assert.Equal(emptyStackTrace.FrameCount - skipFrames, stackTrace.FrameCount);
|
||||
Assert.Equal(expectedMethods, stackTrace.GetFrames().Select(f => f.GetMethod()));
|
||||
|
||||
VerifyFrames(stackTrace, fNeedFileInfo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Ctor_LargeSkipFramesFNeedFileInfo_GetFramesReturnsNull(bool fNeedFileInfo)
|
||||
{
|
||||
var stackTrace = new StackTrace(int.MaxValue, fNeedFileInfo);
|
||||
Assert.Equal(0, stackTrace.FrameCount);
|
||||
Assert.Null(stackTrace.GetFrames());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_ThrownException_GetFramesReturnsExpected()
|
||||
{
|
||||
var stackTrace = new StackTrace(InvokeException());
|
||||
VerifyFrames(stackTrace, false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_EmptyException_GetFramesReturnsNull()
|
||||
{
|
||||
var exception = new Exception();
|
||||
var stackTrace = new StackTrace(exception);
|
||||
Assert.Equal(0, stackTrace.FrameCount);
|
||||
Assert.Null(stackTrace.GetFrames());
|
||||
Assert.Null(stackTrace.GetFrame(0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Ctor_ThrownException_GetFramesReturnsExpected(bool fNeedFileInfo)
|
||||
{
|
||||
var stackTrace = new StackTrace(InvokeException(), fNeedFileInfo);
|
||||
VerifyFrames(stackTrace, fNeedFileInfo);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Ctor_EmptyException_FNeedFileInfo(bool fNeedFileInfo)
|
||||
{
|
||||
var exception = new Exception();
|
||||
var stackTrace = new StackTrace(exception, fNeedFileInfo);
|
||||
Assert.Equal(0, stackTrace.FrameCount);
|
||||
Assert.Null(stackTrace.GetFrames());
|
||||
Assert.Null(stackTrace.GetFrame(0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
public void Ctor_Exception_SkipFrames(int skipFrames)
|
||||
{
|
||||
Exception ex = InvokeException();
|
||||
var exceptionStackTrace = new StackTrace(ex);
|
||||
IEnumerable<MethodBase> expectedMethods = exceptionStackTrace.GetFrames().Skip(skipFrames).Select(f => f.GetMethod());
|
||||
|
||||
var stackTrace = new StackTrace(ex, skipFrames);
|
||||
Assert.Equal(exceptionStackTrace.FrameCount - skipFrames, stackTrace.FrameCount);
|
||||
|
||||
// Netfx has null Frames if skipping frames in Release mode.
|
||||
StackFrame[] frames = stackTrace.GetFrames();
|
||||
#if DEBUG
|
||||
Assert.Equal(expectedMethods, frames.Select(f => f.GetMethod()));
|
||||
#else
|
||||
if (PlatformDetection.IsFullFramework && skipFrames > 0)
|
||||
{
|
||||
Assert.Null(frames);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal(expectedMethods, frames.Select(f => f.GetMethod()));
|
||||
}
|
||||
#endif
|
||||
if (frames != null)
|
||||
{
|
||||
VerifyFrames(stackTrace, false);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_Exception_LargeSkipFrames()
|
||||
{
|
||||
var stackTrace = new StackTrace(InvokeException(), int.MaxValue);
|
||||
Assert.Equal(0, stackTrace.FrameCount);
|
||||
Assert.Null(stackTrace.GetFrames());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_EmptyException_SkipFrames()
|
||||
{
|
||||
var stackTrace = new StackTrace(new Exception(), 0);
|
||||
Assert.Equal(0, stackTrace.FrameCount);
|
||||
Assert.Null(stackTrace.GetFrames());
|
||||
Assert.Null(stackTrace.GetFrame(0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0, true)]
|
||||
[InlineData(1, true)]
|
||||
[InlineData(0, false)]
|
||||
[InlineData(1, false)]
|
||||
public void Ctor_Exception_SkipFrames_FNeedFileInfo(int skipFrames, bool fNeedFileInfo)
|
||||
{
|
||||
Exception ex = InvokeException();
|
||||
var exceptionStackTrace = new StackTrace(ex);
|
||||
IEnumerable<MethodBase> expectedMethods = exceptionStackTrace.GetFrames().Skip(skipFrames).Select(f => f.GetMethod());
|
||||
|
||||
var stackTrace = new StackTrace(ex, skipFrames, fNeedFileInfo);
|
||||
|
||||
// Netfx has null Frames if skipping frames in Release mode.
|
||||
StackFrame[] frames = stackTrace.GetFrames();
|
||||
#if DEBUG
|
||||
Assert.Equal(expectedMethods, frames.Select(f => f.GetMethod()));
|
||||
#else
|
||||
if (PlatformDetection.IsFullFramework && skipFrames > 0)
|
||||
{
|
||||
Assert.Null(frames);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal(expectedMethods, frames.Select(f => f.GetMethod()));
|
||||
}
|
||||
#endif
|
||||
if (frames != null)
|
||||
{
|
||||
VerifyFrames(stackTrace, fNeedFileInfo);
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Ctor_Exception_LargeSkipFrames_FNeedFileInfo(bool fNeedFileInfo)
|
||||
{
|
||||
var stackTrace = new StackTrace(InvokeException(), int.MaxValue);
|
||||
Assert.Equal(0, stackTrace.FrameCount);
|
||||
Assert.Null(stackTrace.GetFrames());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void Ctor_EmptyException_SkipFrames_FNeedFileInfo(bool fNeedFileInfo)
|
||||
{
|
||||
var stackTrace = new StackTrace(new Exception(), 0, fNeedFileInfo);
|
||||
Assert.Equal(0, stackTrace.FrameCount);
|
||||
Assert.Null(stackTrace.GetFrames());
|
||||
Assert.Null(stackTrace.GetFrame(0));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ctor_NullException_ThrowsArgumentNullException()
|
||||
{
|
||||
AssertExtensions.Throws<ArgumentNullException>("e", () => new StackTrace((Exception)null));
|
||||
AssertExtensions.Throws<ArgumentNullException>("e", () => new StackTrace((Exception)null, false));
|
||||
AssertExtensions.Throws<ArgumentNullException>("e", () => new StackTrace(null, 1));
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Ctor_Frame_TestData()
|
||||
{
|
||||
yield return new object[] { new StackFrame() };
|
||||
yield return new object[] { null };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Ctor_Frame_TestData))]
|
||||
public void Ctor_Frame(StackFrame stackFrame)
|
||||
{
|
||||
var stackTrace = new StackTrace(stackFrame);
|
||||
Assert.Equal(1, stackTrace.FrameCount);
|
||||
Assert.Equal(new StackFrame[] { stackFrame }, stackTrace.GetFrames());
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> ToString_TestData()
|
||||
{
|
||||
// Debug mode and Release mode give different results.
|
||||
#if DEBUG
|
||||
yield return new object[] { new StackTrace(InvokeException()), " at System.Diagnostics.Tests.StackTraceTests.ThrowException()" };
|
||||
yield return new object[] { new StackTrace(new Exception()), "" };
|
||||
yield return new object[] { NoParameters(), " at System.Diagnostics.Tests.StackTraceTests.NoParameters()" };
|
||||
yield return new object[] { OneParameter(1), " at System.Diagnostics.Tests.StackTraceTests.OneParameter(Int32 x)" };
|
||||
yield return new object[] { TwoParameters(1, null), " at System.Diagnostics.Tests.StackTraceTests.TwoParameters(Int32 x, String y)" };
|
||||
yield return new object[] { Generic<int>(), " at System.Diagnostics.Tests.StackTraceTests.Generic[T]()" };
|
||||
yield return new object[] { Generic<int, string>(), " at System.Diagnostics.Tests.StackTraceTests.Generic[T,U]()" };
|
||||
yield return new object[] { new ClassWithConstructor().StackTrace, " at System.Diagnostics.Tests.StackTraceTests.ClassWithConstructor..ctor()" };
|
||||
|
||||
// Methods belonging to the System.Diagnostics namespace are ignored.
|
||||
yield return new object[] { InvokeIgnoredMethod(), " at System.Diagnostics.Tests.StackTraceTests.InvokeIgnoredMethod()" };
|
||||
#endif
|
||||
|
||||
yield return new object[] { InvokeIgnoredMethodWithException(), " at System.Diagnostics.Ignored.MethodWithException()" };
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetFrame_InvalidIndex_ReturnsNull()
|
||||
{
|
||||
var stackTrace = new StackTrace();
|
||||
Assert.Null(stackTrace.GetFrame(-1));
|
||||
Assert.Null(stackTrace.GetFrame(stackTrace.FrameCount));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ToString_TestData))]
|
||||
public void ToString_Invoke_ReturnsExpected(StackTrace stackTrace, string expectedToString)
|
||||
{
|
||||
if (expectedToString.Length == 0)
|
||||
{
|
||||
Assert.Equal(Environment.NewLine, stackTrace.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
string toString = stackTrace.ToString();
|
||||
Assert.StartsWith(expectedToString, toString);
|
||||
Assert.EndsWith(Environment.NewLine, toString);
|
||||
|
||||
string[] frames = toString.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
||||
Assert.Equal(frames.Length, stackTrace.FrameCount);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_NullFrame_ThrowsNullReferenceException()
|
||||
{
|
||||
var stackTrace = new StackTrace((StackFrame)null);
|
||||
Assert.Throws<NullReferenceException>(() => stackTrace.ToString());
|
||||
}
|
||||
|
||||
private static StackTrace NoParameters() => new StackTrace();
|
||||
private static StackTrace OneParameter(int x) => new StackTrace();
|
||||
private static StackTrace TwoParameters(int x, string y) => new StackTrace();
|
||||
|
||||
private static StackTrace Generic<T>() => new StackTrace();
|
||||
private static StackTrace Generic<T, U>() => new StackTrace();
|
||||
|
||||
private static StackTrace InvokeIgnoredMethod() => Ignored.Method();
|
||||
private static StackTrace InvokeIgnoredMethodWithException() => Ignored.MethodWithException();
|
||||
|
||||
private static Exception InvokeException()
|
||||
{
|
||||
try
|
||||
{
|
||||
ThrowException();
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
|
||||
private static void ThrowException() => throw new Exception();
|
||||
|
||||
private class ClassWithConstructor
|
||||
{
|
||||
public StackTrace StackTrace { get; }
|
||||
public ClassWithConstructor() => StackTrace = new StackTrace();
|
||||
}
|
||||
|
||||
private static void VerifyFrames(StackTrace stackTrace, bool hasFileInfo)
|
||||
{
|
||||
Assert.True(stackTrace.FrameCount > 0);
|
||||
|
||||
StackFrame[] stackFrames = stackTrace.GetFrames();
|
||||
Assert.Equal(stackTrace.FrameCount, stackFrames.Length);
|
||||
|
||||
for (int i = 0; i < stackFrames.Length; i++)
|
||||
{
|
||||
StackFrame stackFrame = stackFrames[i];
|
||||
|
||||
if (!hasFileInfo)
|
||||
{
|
||||
Assert.Null(stackFrame.GetFileName());
|
||||
Assert.Equal(0, stackFrame.GetFileLineNumber());
|
||||
Assert.Equal(0, stackFrame.GetFileColumnNumber());
|
||||
}
|
||||
Assert.NotNull(stackFrame.GetMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
external/corefx/src/System.Diagnostics.StackTrace/tests/SymDocumentTypeTests.cs
vendored
Normal file
23
external/corefx/src/System.Diagnostics.StackTrace/tests/SymDocumentTypeTests.cs
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.SymbolStore.Tests
|
||||
{
|
||||
public class SymDocumentTypeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
Assert.NotNull(new SymDocumentType());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Text_Get_ReturnsExpected()
|
||||
{
|
||||
Assert.Equal(new Guid("5a869d0b-6611-11d3-bd2a-0000f80849bd"), SymDocumentType.Text);
|
||||
}
|
||||
}
|
||||
}
|
40
external/corefx/src/System.Diagnostics.StackTrace/tests/SymLanguageTypeTests.cs
vendored
Normal file
40
external/corefx/src/System.Diagnostics.StackTrace/tests/SymLanguageTypeTests.cs
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.SymbolStore.Tests
|
||||
{
|
||||
public class SymLanguageTypeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
Assert.NotNull(new SymLanguageType());
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> LanguageTypes_TestData()
|
||||
{
|
||||
yield return new object[] { SymLanguageType.C, new Guid("63a08714-fc37-11d2-904c-00c04fa302a1") };
|
||||
yield return new object[] { SymLanguageType.CPlusPlus, new Guid("3a12d0b7-c26c-11d0-b442-00a0244a1dd2") };
|
||||
yield return new object[] { SymLanguageType.CSharp, new Guid("3f5162f8-07c6-11d3-9053-00c04fa302a1") };
|
||||
yield return new object[] { SymLanguageType.Basic, new Guid("3a12d0b8-c26c-11d0-b442-00a0244a1dd2") };
|
||||
yield return new object[] { SymLanguageType.Java, new Guid("3a12d0b4-c26c-11d0-b442-00a0244a1dd2") };
|
||||
yield return new object[] { SymLanguageType.Cobol, new Guid("af046cd1-d0e1-11d2-977c-00a0c9b4d50c") };
|
||||
yield return new object[] { SymLanguageType.Pascal, new Guid("af046cd2-d0e1-11d2-977c-00a0c9b4d50c") };
|
||||
yield return new object[] { SymLanguageType.ILAssembly, new Guid("af046cd3-d0e1-11d2-977c-00a0c9b4d50c") };
|
||||
yield return new object[] { SymLanguageType.JScript, new Guid("3a12d0b6-c26c-11d0-b442-00a0244a1dd2") };
|
||||
yield return new object[] { SymLanguageType.SMC, new Guid("0d9b9f7b-6611-11d3-bd2a-0000f80849bd") };
|
||||
yield return new object[] { SymLanguageType.MCPlusPlus, new Guid("4b35fde8-07c6-11d3-9053-00c04fa302a1") };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(LanguageTypes_TestData))]
|
||||
public void LanguageTypes_Get_ReturnsExpected(Guid languageType, Guid expected)
|
||||
{
|
||||
Assert.Equal(expected, languageType);
|
||||
}
|
||||
}
|
||||
}
|
23
external/corefx/src/System.Diagnostics.StackTrace/tests/SymLanguageVendorTests.cs
vendored
Normal file
23
external/corefx/src/System.Diagnostics.StackTrace/tests/SymLanguageVendorTests.cs
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.SymbolStore.Tests
|
||||
{
|
||||
public class SymLanguageVendorTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
Assert.NotNull(new SymLanguageVendor());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Microsoft_Get_ReturnsExpected()
|
||||
{
|
||||
Assert.Equal(new Guid("994b45c4-e6e9-11d2-903f-00c04fa302a1"), SymLanguageVendor.Microsoft);
|
||||
}
|
||||
}
|
||||
}
|
53
external/corefx/src/System.Diagnostics.StackTrace/tests/SymbolTokenTests.cs
vendored
Normal file
53
external/corefx/src/System.Diagnostics.StackTrace/tests/SymbolTokenTests.cs
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Diagnostics.SymbolStore.Tests
|
||||
{
|
||||
public class SymbolTokenTests
|
||||
{
|
||||
[Fact]
|
||||
public void Ctor_Default()
|
||||
{
|
||||
var symbolToken = new SymbolToken();
|
||||
Assert.Equal(0, symbolToken.GetToken());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)]
|
||||
[InlineData(0)]
|
||||
[InlineData(1)]
|
||||
public void Ctor_Value(int value)
|
||||
{
|
||||
var symbolToken = new SymbolToken(value);
|
||||
Assert.Equal(value, symbolToken.GetToken());
|
||||
Assert.Equal(value, symbolToken.GetHashCode());
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> Equals_TestData()
|
||||
{
|
||||
yield return new object[] { new SymbolToken(1), new SymbolToken(1), true };
|
||||
yield return new object[] { new SymbolToken(1), new SymbolToken(0), false };
|
||||
yield return new object[] { new SymbolToken(), new SymbolToken(0), true };
|
||||
|
||||
yield return new object[] { new SymbolToken(), new object(), false };
|
||||
yield return new object[] { new SymbolToken(), null, false };
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Equals_TestData))]
|
||||
public void Equals_Other_ReturnsExpected(SymbolToken symbolToken, object other, bool expected)
|
||||
{
|
||||
Assert.Equal(expected, symbolToken.Equals(other));
|
||||
if (other is SymbolToken otherSymbolToken)
|
||||
{
|
||||
Assert.Equal(expected, symbolToken.Equals(otherSymbolToken));
|
||||
Assert.Equal(expected, symbolToken == otherSymbolToken);
|
||||
Assert.Equal(!expected, symbolToken != otherSymbolToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{297A9116-1005-499D-A895-2063D03E4C94}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
|
||||
<!-- Default configurations to help VS understand the configurations -->
|
||||
<ItemGroup>
|
||||
<Compile Include="StackTraceTests.cs" />
|
||||
<Compile Include="SymDocumentTypeTests.cs" />
|
||||
<Compile Include="SymLanguageTypeTests.cs" />
|
||||
<Compile Include="SymLanguageVendorTests.cs" />
|
||||
<Compile Include="SymbolTokenTests.cs" />
|
||||
<Compile Include="StackFrameTests.cs" />
|
||||
<Compile Include="StackFrameExtensionsTests.cs" Condition="'$(TargetGroup)' != 'netfx'" />
|
||||
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
|
||||
<Link>Common\System\PlatformDetection.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'netfx'">
|
||||
<ReferenceFromRuntime Include="System.Runtime.InteropServices.RuntimeInformation" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
Reference in New Issue
Block a user