Ejemplo n.º 1
0
        public void AssertTypeException(Thread thread, string expression, string exp_result)
        {
            string text = null;

            try {
                ScriptingContext context = GetContext(thread);

                TargetType type = EvaluateExpressionType(context, expression);
                text = context.FormatType(type);
                Assert.Fail("Evaluation of expression `{0}' failed to throw " +
                            "exception {1}.", expression, exp_result);
            } catch (AssertionException) {
                throw;
            } catch (ScriptingException ex) {
                text = ex.Message;
            } catch (Exception ex) {
                Assert.Fail("Failed to print expression `{0}': {1}",
                            expression, ex);
            }

            if (text != exp_result)
            {
                Assert.Fail("Expression `{0}' evaluated to `{1}', but expected `{2}'.",
                            expression, text, exp_result);
            }
        }
Ejemplo n.º 2
0
        protected override string Execute(ScriptingContext context,
                                          Expression expression, DisplayFormat format)
        {
            // try-catch block for whole method: if an exception occurs, we are able to
            // release the semaphore waiting for the command answer
            try {
                TargetType type = expression.EvaluateType(context);

                string fieldNames           = "";
                string fieldNamesStaticOnly = "";
                if (type.Kind == TargetObjectKind.Class || type.Kind == TargetObjectKind.Struct)
                {
                    TargetClassType stype = (TargetClassType)type;
                    foreach (TargetFieldInfo field in stype.Fields)
                    {
                        fieldNames += field.Name;
                        fieldNames += " ";
                        if (field.IsStatic)
                        {
                            fieldNamesStaticOnly += field.Name;
                            fieldNamesStaticOnly += " ";
                        }
                    }
                    fieldNames           = fieldNames.Trim();
                    fieldNamesStaticOnly = fieldNamesStaticOnly.Trim();
                }
                string text = context.FormatType(type);
                context.Print(text);

                EmonicInterpreter.ptypeOutput           = fieldNames;
                EmonicInterpreter.ptypeOutputStaticOnly = fieldNamesStaticOnly;
                EmonicInterpreter.ptypeSem.Release();

                return(text);
            } catch {
                EmonicInterpreter.ptypeOutput           = "--";
                EmonicInterpreter.ptypeOutputStaticOnly = "--";
                EmonicInterpreter.ptypeSem.Release();
                throw;
            }
        }
Ejemplo n.º 3
0
        public void AssertType(Thread thread, string expression, string exp_result)
        {
            string text = null;

            try {
                ScriptingContext context = GetContext(thread);

                TargetType type = EvaluateExpressionType(context, expression);
                text = context.FormatType(type);
            } catch (AssertionException) {
                throw;
            } catch (Exception ex) {
                Assert.Fail("Failed to evaluate type of expression `{0}': {1}",
                            expression, ex);
            }

            if (text != exp_result)
            {
                Assert.Fail("Type of expression `{0}' is `{1}', but expected `{2}'.",
                            expression, text, exp_result);
            }
        }