PageRenderTime 18ms CodeModel.GetById 1ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/IronPython_Main/Runtime/Tests/ETScenarios/Miscellaneous/DebugInfo.cs

#
C# | 300 lines | 214 code | 67 blank | 19 comment | 1 complexity | e1804420c052c1dd13ec4ff4385b3a15 MD5 | raw file
  1#if !CLR2
  2using System.Linq.Expressions;
  3#else
  4using Microsoft.Scripting.Ast;
  5#endif
  6
  7using System;
  8using System.Collections.Generic;
  9using System.Reflection;
 10
 11namespace ETScenarios.Miscellaneous {
 12    using EU = ETUtils.ExpressionUtils;
 13    using Expr = Expression;
 14    using AstUtils = Microsoft.Scripting.Ast.Utils;
 15
 16    public class DebugInfo {
 17        // pass all sorts of expressions to debug info.
 18        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 1", new string[] { "positive", "debuginfo", "miscellaneous", "Pri1" })]
 19        public static Expr DebugInfo1(EU.IValidator V) {
 20            List<Expression> Expressions = new List<Expression>();
 21
 22            var sd = Expr.SymbolDocument("x");
 23
 24            foreach (Expr x in EU.GetAllExpressions()) {
 25                Expressions.Add(EU.AddDebugInfo(x, sd, 1, 1, 2, 3));
 26            }
 27
 28            var tree = EU.BlockVoid(Expressions);
 29            V.Validate(tree);
 30            return tree;
 31        }
 32
 33        // pass null to filename
 34        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 2", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentNullException))]
 35        public static Expr DebugInfo2(EU.IValidator V) {
 36            List<Expression> Expressions = new List<Expression>();
 37
 38            EU.Throws<ArgumentNullException>(() => { Expr.SymbolDocument(null); });
 39
 40            return Expr.Empty();
 41        }
 42
 43        // pass empty string to filename
 44        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 3", new string[] { "positive", "debuginfo", "miscellaneous", "Pri1" })]
 45        public static Expr DebugInfo3(EU.IValidator V) {
 46            List<Expression> Expressions = new List<Expression>();
 47
 48            Expr.SymbolDocument("");
 49
 50            var tree = Expr.Empty();
 51            V.Validate(tree);
 52            return tree;
 53        }
 54
 55        // pass a non existing file to filename
 56        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 4", new string[] { "positive", "debuginfo", "miscellaneous", "Pri1" })]
 57        public static Expr DebugInfo4(EU.IValidator V) {
 58            List<Expression> Expressions = new List<Expression>();
 59
 60            Expr.SymbolDocument("testxxx.xyz");
 61
 62            var tree = Expr.Empty();
 63            V.Validate(tree);
 64            return tree;
 65        }
 66
 67        // pass a string longer than maxpath to filename
 68        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 5", new string[] { "positive", "debuginfo", "miscellaneous", "Pri1" })]
 69        public static Expr DebugInfo5(EU.IValidator V) {
 70            List<Expression> Expressions = new List<Expression>();
 71
 72            var t = new System.Text.StringBuilder();
 73            for (int i = 0; i < 500; i++) { t.Append("X"); }
 74
 75            Expr.SymbolDocument(t.ToString());
 76
 77            var tree = Expr.Empty();
 78            V.Validate(tree);
 79            return tree;
 80        }
 81
 82
 83        // pass null to body
 84        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 6", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentNullException))]
 85        public static Expr DebugInfo6(EU.IValidator V) {
 86            List<Expression> Expressions = new List<Expression>();
 87
 88            var sd = Expr.SymbolDocument("");
 89            EU.Throws<System.ArgumentNullException>(() =>
 90            {
 91                EU.AddDebugInfo(null, sd, 1, 1, 2, 3);
 92            });
 93
 94            return Expr.Empty();
 95        }
 96
 97        // pass null to document
 98        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 7", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentNullException))]
 99        public static Expr DebugInfo7(EU.IValidator V) {
100            List<Expression> Expressions = new List<Expression>();
101
102            EU.Throws<ArgumentNullException>(() => { EU.AddDebugInfo(Expr.Empty(), null, 1, 1, 2, 3); });
103
104            return Expr.Empty();
105        }
106
107        // pass a negative number to startline
108        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 8", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentOutOfRangeException))]
109        public static Expr DebugInfo8(EU.IValidator V) {
110            List<Expression> Expressions = new List<Expression>();
111
112            var sd = Expr.SymbolDocument("");
113            EU.Throws<System.ArgumentOutOfRangeException>(() =>
114            {
115                EU.AddDebugInfo(Expr.Empty(), sd, -1, 1, 2, 3);
116            });
117
118            return Expr.Empty();
119        }
120
121        // pass a negative number to startcolumn
122        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 9", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentOutOfRangeException))]
123        public static Expr DebugInfo9(EU.IValidator V) {
124            List<Expression> Expressions = new List<Expression>();
125
126            var sd = Expr.SymbolDocument("");
127            EU.Throws<System.ArgumentOutOfRangeException>(() =>
128            {
129                EU.AddDebugInfo(Expr.Empty(), sd, 1, -1, 2, 3);
130            });
131
132            return Expr.Empty();
133        }
134
135        // pass a negative number to endline
136        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 10", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentOutOfRangeException))]
137        public static Expr DebugInfo10(EU.IValidator V) {
138            List<Expression> Expressions = new List<Expression>();
139
140            var sd = Expr.SymbolDocument("");
141            EU.Throws<System.ArgumentOutOfRangeException>(() =>
142            {
143                EU.AddDebugInfo(Expr.Empty(), sd, 1, 1, -2, 3);
144            });
145
146            return Expr.Empty();
147        }
148
149        // pass a negative number to endcolumn
150        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 11", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentOutOfRangeException))]
151        public static Expr DebugInfo11(EU.IValidator V) {
152            List<Expression> Expressions = new List<Expression>();
153
154            var sd = Expr.SymbolDocument("");
155            EU.Throws<System.ArgumentOutOfRangeException>(() =>
156            {
157                EU.AddDebugInfo(Expr.Empty(), sd, 1, 1, 2, -3);
158            });
159
160            return Expr.Empty();
161        }
162
163
164        // pass zero to startline
165        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 12", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentOutOfRangeException))]
166        public static Expr DebugInfo12(EU.IValidator V) {
167            List<Expression> Expressions = new List<Expression>();
168
169            var sd = Expr.SymbolDocument("");
170            EU.Throws<System.ArgumentOutOfRangeException>(() =>
171            {
172                EU.AddDebugInfo(Expr.Empty(), sd, 0, 1, 2, 3);
173            });
174
175            return Expr.Empty();
176        }
177
178        // pass zero to startcolumn
179        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 13", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentOutOfRangeException))]
180        public static Expr DebugInfo13(EU.IValidator V) {
181            List<Expression> Expressions = new List<Expression>();
182
183            var sd = Expr.SymbolDocument("");
184            EU.Throws<System.ArgumentOutOfRangeException>(() =>
185            {
186                EU.AddDebugInfo(Expr.Empty(), sd, 1, 0, 2, 3);
187            });
188
189            return Expr.Empty();
190        }
191
192        // pass zero to endline
193        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 14", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentOutOfRangeException))]
194        public static Expr DebugInfo14(EU.IValidator V) {
195            List<Expression> Expressions = new List<Expression>();
196
197            var sd = Expr.SymbolDocument("");
198            EU.Throws<System.ArgumentOutOfRangeException>(() =>
199            {
200                EU.AddDebugInfo(Expr.Empty(), sd, 1, 1, 0, 3);
201            });
202
203            return Expr.Empty();
204        }
205
206        // pass zero to endcolumn
207        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 15", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentOutOfRangeException))]
208        public static Expr DebugInfo15(EU.IValidator V) {
209            List<Expression> Expressions = new List<Expression>();
210
211            var sd = Expr.SymbolDocument("");
212            EU.Throws<System.ArgumentOutOfRangeException>(() =>
213            {
214                EU.AddDebugInfo(Expr.Empty(), sd, 1, 1, 2, 0);
215            });
216
217            return Expr.Empty();
218        }
219
220        // pass endline smaller than startline
221        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 16", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentException))]
222        public static Expr DebugInfo16(EU.IValidator V) {
223            List<Expression> Expressions = new List<Expression>();
224
225            var sd = Expr.SymbolDocument("");
226            EU.Throws<System.ArgumentException>(() =>
227            {
228                EU.AddDebugInfo(Expr.Empty(), sd, 5, 1, 2, 1);
229            });
230
231            return Expr.Empty();
232        }
233
234        // pass endcolumn smaller than startcolumn
235        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 17", new string[] { "negative", "debuginfo", "miscellaneous", "Pri1" }, Exception = typeof(ArgumentException))]
236        public static Expr DebugInfo17(EU.IValidator V) {
237            List<Expression> Expressions = new List<Expression>();
238
239            var sd = Expr.SymbolDocument("");
240            EU.Throws<System.ArgumentException>(() =>
241            {
242                EU.AddDebugInfo(Expr.Empty(), sd, 1, 5, 1, 1);
243            });
244
245            return Expr.Empty();
246        }
247
248        // pass same numbers for all positions
249        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 18", new string[] { "positive", "debuginfo", "miscellaneous", "Pri1" })]
250        public static Expr DebugInfo18(EU.IValidator V) {
251            List<Expression> Expressions = new List<Expression>();
252
253            var sd = Expr.SymbolDocument("");
254            EU.AddDebugInfo(Expr.Empty(), sd, 1, 1, 1, 1);
255
256            var tree = Expr.Empty();
257            V.Validate(tree);
258            return tree;
259        }
260
261
262        // pass same numbers for all positions
263        [ETUtils.TestAttribute(ETUtils.TestState.Enabled, "DebugInfo 19", new string[] { "positive", "debuginfo", "miscellaneous", "Pri1" })]
264        public static Expr DebugInfo19(EU.IValidator V) {
265            List<Expression> Expressions = new List<Expression>();
266            var g1 = Guid.NewGuid();
267            var g2 = Guid.NewGuid();
268            var g3 = Guid.NewGuid();
269            var txtGuid = new Guid(0x5a869d0b, 0x6611, 0x11d3, 0xbd, 0x2a, 0, 0, 0xf8, 8, 0x49, 0xbd);
270
271            var sd1 = Expression.SymbolDocument("blahville");
272            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd1.FileName), Expression.Constant("blahville")));
273            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd1.Language), Expression.Constant(Guid.Empty)));
274            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd1.LanguageVendor), Expression.Constant(Guid.Empty)));
275            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd1.DocumentType), Expression.Constant(txtGuid)));
276
277            var sd2 = Expression.SymbolDocument("blahville", g1);
278            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd2.FileName), Expression.Constant("blahville")));
279            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd2.Language), Expression.Constant(g1)));
280            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd2.LanguageVendor), Expression.Constant(Guid.Empty)));
281            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd2.DocumentType), Expression.Constant(txtGuid)));
282
283            var sd3 = Expression.SymbolDocument("blahville", g1, g2);
284            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd3.FileName), Expression.Constant("blahville")));
285            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd3.Language), Expression.Constant(g1)));
286            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd3.LanguageVendor), Expression.Constant(g2)));
287            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd3.DocumentType), Expression.Constant(txtGuid)));
288
289            var sd4 = Expression.SymbolDocument("blahville", g1, g2, g3);
290            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd4.FileName), Expression.Constant("blahville")));
291            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd4.Language), Expression.Constant(g1)));
292            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd4.LanguageVendor), Expression.Constant(g2)));
293            Expressions.Add(EU.GenAreEqual(Expression.Constant(sd4.DocumentType), Expression.Constant(g3)));
294
295            var tree = EU.BlockVoid(Expressions);
296            V.Validate(tree);
297            return tree;
298        }
299    }
300}