Skip to content

Commit 6ebf1b8

Browse files
committed
Modify TC to compare strings before ':'
In order to avoid failure due to modification of dotnet#44013, the TC has been modified so that the content after':' is not compared.
1 parent 1a8f80f commit 6ebf1b8

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

src/tests/baseservices/exceptions/sharedexceptions/emptystacktrace/oomexception01.cs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,55 @@ public static int Main()
1818

1919
public void RunTest()
2020
{
21-
CreateAndThrow();
21+
CreateAndThrow();
2222
}
2323

2424
public void CreateAndThrow()
2525
{
26-
string currStack;
27-
26+
string currStack;
27+
2828
try
2929
{
30-
throw new Exception();
30+
throw new Exception();
31+
}
32+
catch(Exception e)
33+
{
34+
currStack = e.StackTrace;
3135
}
32-
catch(Exception e)
33-
{
34-
currStack = e.StackTrace;
35-
}
36-
36+
3737
try
38-
{
38+
{
3939
Guid[] g = new Guid[Int32.MaxValue];
4040
}
4141
catch(OutOfMemoryException e)
4242
{
4343
retVal = 100;
44-
45-
Console.WriteLine("Caught OOM");
4644

47-
if(e.StackTrace.ToString().Substring(0, e.StackTrace.Length - 8) != currStack.Substring(0, currStack.Length - 8))
48-
{
49-
Console.WriteLine("Actual Exception Stack Trace:");
45+
Console.WriteLine("Caught OOM");
46+
47+
string oomStack = e.StackTrace;
48+
string expectedStack = currStack;
49+
50+
if (oomStack.IndexOf(':') != -1)
51+
{
52+
oomStack = oomStack.Substring(0, oomStack.IndexOf(':') - 1);
53+
}
54+
55+
if (expectedStack.IndexOf(':') != -1)
56+
{
57+
expectedStack = expectedStack.Substring(0, expectedStack.IndexOf(':') - 1);
58+
}
59+
60+
if (oomStack != expectedStack)
61+
{
62+
Console.WriteLine("Actual Exception Stack Trace:");
5063
Console.WriteLine(e.StackTrace);
5164
Console.WriteLine();
52-
Console.WriteLine("Expected Stack Trace:");
53-
Console.WriteLine(currStack.ToString());
65+
Console.WriteLine("Expected Stack Trace:");
66+
Console.WriteLine(currStack.ToString());
5467
retVal = 50;
5568
}
5669
}
57-
5870
}
59-
6071
}
6172

0 commit comments

Comments
 (0)