Beispiel #1
0
        public static string GetInvalidCsxScript(ScriptErrorType errorType)
        {
            switch (errorType)
            {
            case ScriptErrorType.MissingEntryPoint:
                return(@"
                        public static string SomeMethod() => ""test string"";
                    ");

            case ScriptErrorType.DuplicateEntryPoint:
                return(@"
                        public static int Run(int x) {
                            return x * x;
                        }
                        public static int Run(int x, int y) {
                            return x + y;
                        }
                    ");

            case ScriptErrorType.CompilationError:
            default:
                return(@"
                        public static int Run(int x) {
                        return x * x
                    }");
            }
        }
Beispiel #2
0
        public async void CompilationService_TestDuplicateEntryPoints(ScriptErrorType errorType)
        {
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = ScriptTestDataHelper.GetInvalidCsxScript(errorType);

            var          serviceInstance = CompilationServiceFactory.CreateService(metadata, ScriptOptions.Default);
            ICompilation compilation     = await serviceInstance.GetCompilationAsync();

            ScriptCompilationException ex = Assert.Throws <ScriptCompilationException>(() =>
            {
                EntityMethodSignature methodSignature = compilation.GetEntryPointSignature();
            });

            Assert.NotEmpty(ex.CompilationOutput);
        }
        public async void EntityInvoker_TestInvokeWithCompilationError(ScriptErrorType errorType)
        {
            EntityMetadata metadata = ScriptTestDataHelper.GetRandomMetadata();

            metadata.ScriptText = ScriptTestDataHelper.GetInvalidCsxScript(errorType);

            using (EntityInvoker invoker = new EntityInvoker(metadata, ImmutableArray.Create <string>()))
            {
                ScriptCompilationException ex = await Assert.ThrowsAsync <ScriptCompilationException>(async() =>
                {
                    await invoker.InitializeEntryPointAsync();
                    int result = (int)await invoker.Invoke(new object[] { 3 });
                    Assert.Equal(9, result);
                });

                Assert.NotEmpty(ex.CompilationOutput);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Add the specified error and source position of the expression
 /// </summary>
 /// <param name="errorCode">The distinct error code.</param>
 /// <param name="errorText">Error text</param>
 /// <param name="node">The expression associated with the warning</param>
 /// <param name="errorType">Type of error.</param>
 private void AddSemanticError(string errorCode, string errorText, AstNode node, ScriptErrorType errorType)
 {
     string errormsg = errorText + " at line : " + node.Ref.Line + ", pos : " + node.Ref.CharPos;
     var error = new ScriptError();
     error.Line = node.Ref.Line;
     error.File = node.Ref.ScriptName;
     error.Column = node.Ref.CharPos;
     error.ErrorType = errorType.ToString();
     error.ErrorCode = errorCode;
     error.Message = errormsg;
     _errors.Add(error);
 }
        /// <summary>
        /// Add the specified error and source position of the expression
        /// </summary>
        /// <param name="errorCode">The distinct error code.</param>
        /// <param name="errorText">Error text</param>
        /// <param name="node">The expression associated with the warning</param>
        /// <param name="errorType">Type of error.</param>
        private void AddSemanticError(string errorCode, string errorText, AstNode node, ScriptErrorType errorType)
        {
            string errormsg = errorText + " at line : " + node.Ref.Line + ", pos : " + node.Ref.CharPos;
            var    error    = new ScriptError();

            error.Line      = node.Ref.Line;
            error.File      = node.Ref.ScriptName;
            error.Column    = node.Ref.CharPos;
            error.ErrorType = errorType.ToString();
            error.ErrorCode = errorCode;
            error.Message   = errormsg;
            _errors.Add(error);
        }