Skip to content

Commit 38e77a4

Browse files
committed
Fix stackoverflowtester per Mark's PR feedback
1 parent 2d85c95 commit 38e77a4

File tree

1 file changed

+88
-141
lines changed

1 file changed

+88
-141
lines changed

src/tests/baseservices/exceptions/stackoverflow/stackoverflowtester.cs

Lines changed: 88 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace TestStackOverflow
1111
{
1212
public class Program
1313
{
14-
static bool TestStackOverflow(string testName, string testArgs, out List<string> stderrLines)
14+
static void TestStackOverflow(string testName, string testArgs, out List<string> stderrLines)
1515
{
1616
Console.WriteLine($"Running {testName} test({testArgs})");
1717
List<string> lines = new List<string>();
@@ -56,197 +56,144 @@ static bool TestStackOverflow(string testName, string testArgs, out List<string>
5656
expectedListBuilder.Append($"{separator}0x{code:X8}");
5757
separator = " or ";
5858
});
59-
Console.WriteLine($"Exit code: 0x{testProcess.ExitCode:X8}, expected {expectedListBuilder.ToString()}");
60-
return false;
59+
throw new Exception($"Exit code: 0x{testProcess.ExitCode:X8}, expected {expectedListBuilder.ToString()}");
6160
}
6261

6362
if (lines[0] != "Stack overflow.")
6463
{
65-
Console.WriteLine("Missing \"Stack overflow.\" at the first line");
66-
return false;
64+
throw new Exception("Missing \"Stack overflow.\" at the first line");
6765
}
68-
69-
return true;
7066
}
7167

7268
[Fact]
73-
public static bool TestStackOverflowSmallFrameMainThread()
69+
public static void TestStackOverflowSmallFrameMainThread()
7470
{
75-
List<string> lines;
76-
if (TestStackOverflow("stackoverflow", "smallframe main", out lines))
77-
{
78-
if (!lines[lines.Count - 1].EndsWith(".Main()"))
79-
{
80-
Console.WriteLine("Missing \"Main\" method frame at the last line");
81-
return false;
82-
}
71+
TestStackOverflow("stackoverflow", "smallframe main", out List<string> lines);
8372

84-
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)")))
85-
{
86-
Console.WriteLine("Missing \"Test\" method frame");
87-
return false;
88-
}
89-
90-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA()")))
91-
{
92-
Console.WriteLine("Missing \"InfiniteRecursionA\" method frame");
93-
return false;
94-
}
73+
if (!lines[lines.Count - 1].EndsWith(".Main(System.String[])"))
74+
{
75+
throw new Exception("Missing \"Main\" method frame at the last line");
76+
}
9577

96-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB()")))
97-
{
98-
Console.WriteLine("Missing \"InfiniteRecursionB\" method frame");
99-
return false;
100-
}
78+
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)")))
79+
{
80+
throw new Exception("Missing \"Test\" method frame");
81+
}
10182

102-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC()")))
103-
{
104-
Console.WriteLine("Missing \"InfiniteRecursionC\" method frame");
105-
return false;
106-
}
83+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA()")))
84+
{
85+
throw new Exception("Missing \"InfiniteRecursionA\" method frame");
86+
}
10787

108-
return true;
88+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB()")))
89+
{
90+
throw new Exception("Missing \"InfiniteRecursionB\" method frame");
10991
}
11092

111-
return false;
93+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC()")))
94+
{
95+
throw new Exception("Missing \"InfiniteRecursionC\" method frame");
96+
}
11297
}
11398

11499
[Fact]
115-
public static bool TestStackOverflowLargeFrameMainThread()
100+
public static void TestStackOverflowLargeFrameMainThread()
116101
{
117-
List<string> lines;
118-
if (TestStackOverflow("stackoverflow", "largeframe main", out lines))
119-
{
120-
if (!lines[lines.Count - 1].EndsWith("at TestStackOverflow.Program.Main(System.String[])"))
121-
{
122-
Console.WriteLine("Missing \"Main\" method frame at the last line");
123-
return false;
124-
}
125-
126-
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)")))
127-
{
128-
Console.WriteLine("Missing \"Test\" method frame");
129-
return false;
130-
}
102+
TestStackOverflow("stackoverflow", "largeframe main", out List<string> lines);
131103

132-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA2()")))
133-
{
134-
Console.WriteLine("Missing \"InfiniteRecursionA2\" method frame");
135-
return false;
136-
}
104+
if (!lines[lines.Count - 1].EndsWith("at TestStackOverflow.Program.Main(System.String[])"))
105+
{
106+
throw new Exception("Missing \"Main\" method frame at the last line");
107+
}
137108

138-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB2()")))
139-
{
140-
Console.WriteLine("Missing \"InfiniteRecursionB2\" method frame");
141-
return false;
142-
}
109+
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.Test(Boolean)")))
110+
{
111+
throw new Exception("Missing \"Test\" method frame");
112+
}
143113

144-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC2()")))
145-
{
146-
Console.WriteLine("Missing \"InfiniteRecursionC2\" method frame");
147-
return false;
148-
}
114+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA2()")))
115+
{
116+
throw new Exception("Missing \"InfiniteRecursionA2\" method frame");
117+
}
149118

150-
return true;
119+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB2()")))
120+
{
121+
throw new Exception("Missing \"InfiniteRecursionB2\" method frame");
151122
}
152123

153-
return false;
124+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC2()")))
125+
{
126+
throw new Exception("Missing \"InfiniteRecursionC2\" method frame");
127+
}
154128
}
155129

156130
[Fact]
157-
public static bool TestStackOverflowSmallFrameSecondaryThread()
131+
public static void TestStackOverflowSmallFrameSecondaryThread()
158132
{
159-
List<string> lines;
160-
if (TestStackOverflow("stackoverflow", "smallframe secondary", out lines))
161-
{
162-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)")))
163-
{
164-
Console.WriteLine("Missing \"TestStackOverflow.Program.Test\" method frame");
165-
return false;
166-
}
167-
168-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA()")))
169-
{
170-
Console.WriteLine("Missing \"InfiniteRecursionA\" method frame");
171-
return false;
172-
}
133+
TestStackOverflow("stackoverflow", "smallframe secondary", out List<string> lines);
173134

174-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB()")))
175-
{
176-
Console.WriteLine("Missing \"InfiniteRecursionB\" method frame");
177-
return false;
178-
}
135+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)")))
136+
{
137+
throw new Exception("Missing \"TestStackOverflow.Program.Test\" method frame");
138+
}
179139

180-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC()")))
181-
{
182-
Console.WriteLine("Missing \"InfiniteRecursionC\" method frame");
183-
return false;
184-
}
140+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA()")))
141+
{
142+
throw new Exception("Missing \"InfiniteRecursionA\" method frame");
143+
}
185144

186-
return true;
145+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionB()")))
146+
{
147+
throw new Exception("Missing \"InfiniteRecursionB\" method frame");
187148
}
188149

189-
return false;
150+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionC()")))
151+
{
152+
throw new Exception("Missing \"InfiniteRecursionC\" method frame");
153+
}
190154
}
191155

192156
[Fact]
193-
public static bool TestStackOverflowLargeFrameSecondaryThread()
157+
public static void TestStackOverflowLargeFrameSecondaryThread()
194158
{
195-
List<string> lines;
196-
if (TestStackOverflow("stackoverflow", "largeframe secondary", out lines))
197-
{
198-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)")))
199-
{
200-
Console.WriteLine("Missing \"TestStackOverflow.Program.Test\" method frame");
201-
return false;
202-
}
203-
204-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA2()")))
205-
{
206-
Console.WriteLine("Missing \"InfiniteRecursionA2\" method frame");
207-
return false;
208-
}
159+
TestStackOverflow("stackoverflow", "largeframe secondary", out List<string> lines);
209160

210-
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.InfiniteRecursionB2()")))
211-
{
212-
Console.WriteLine("Missing \"InfiniteRecursionB2\" method frame");
213-
return false;
214-
}
161+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.Test(Boolean)")))
162+
{
163+
throw new Exception("Missing \"TestStackOverflow.Program.Test\" method frame");
164+
}
215165

216-
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.InfiniteRecursionC2()")))
217-
{
218-
Console.WriteLine("Missing \"InfiniteRecursionC2\" method frame");
219-
return false;
220-
}
166+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow.Program.InfiniteRecursionA2()")))
167+
{
168+
throw new Exception("Missing \"InfiniteRecursionA2\" method frame");
169+
}
221170

222-
return true;
171+
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.InfiniteRecursionB2()")))
172+
{
173+
throw new Exception("Missing \"InfiniteRecursionB2\" method frame");
223174
}
224175

225-
return false;
176+
if (!lines.Exists(elem => elem.EndsWith("TestStackOverflow.Program.InfiniteRecursionC2()")))
177+
{
178+
throw new Exception("Missing \"InfiniteRecursionC2\" method frame");
179+
}
226180
}
227181

228182
[Fact]
229-
public static bool TestStackOverflow3()
183+
public static void TestStackOverflow3()
230184
{
231-
List<string> lines;
232-
if (TestStackOverflow("stackoverflow3", "", out lines))
233-
{
234-
if (!lines[lines.Count - 1].EndsWith("at TestStackOverflow3.Program.Main()"))
235-
{
236-
Console.WriteLine("Missing \"Main\" method frame at the last line");
237-
return false;
238-
}
185+
TestStackOverflow("stackoverflow3", "", out List<string> lines);
239186

240-
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow3.Program.Execute(System.String)")))
241-
{
242-
Console.WriteLine("Missing \"Execute\" method frame");
243-
return false;
244-
}
187+
if (!lines[lines.Count - 1].EndsWith("at TestStackOverflow3.Program.Main()"))
188+
{
189+
throw new Exception("Missing \"Main\" method frame at the last line");
190+
}
245191

246-
return true;
192+
if (!lines.Exists(elem => elem.EndsWith("at TestStackOverflow3.Program.Execute(System.String)")))
193+
{
194+
throw new Exception("Missing \"Execute\" method frame");
247195
}
248196

249-
return false;
250197
}
251198
}
252199
}

0 commit comments

Comments
 (0)