protected void RunParserTestCase(string testfile)
        {
            _compiler.Parameters.Input.Add(GetCompilerInput(testfile));
            Boo.Lang.Compiler.CompilerContext context = _compiler.Run();
            if (context.Errors.Count > 0)
            {
                Assert.Fail(context.Errors.ToString(true));
            }

            Assert.AreEqual(1, context.CompileUnit.Modules.Count, "expected a module as output");

            string expected = GetDocumentation(context.CompileUnit.Modules[0]);

            string output = _compiler.Parameters.OutputWriter.ToString();

            Assert.AreEqual(expected.Trim(), output.ToString().Trim().Replace("\r\n", "\n"), testfile);
        }
        protected void RunParserTestCase(string testfile)
        {
            _compiler.Parameters.Input.Add(new FileInput(GetTestCasePath(testfile)));
            Boo.Lang.Compiler.CompilerContext context = _compiler.Run();
            if (context.Errors.Count > 0)
            {
                Assert.Fail(context.Errors.ToString(true));
            }

            Assert.AreEqual(1, context.CompileUnit.Modules.Count, "expected a module as output");

            string expected = context.CompileUnit.Modules[0].Documentation;

            if (null == expected)
            {
                Assert.Fail(string.Format("Test case '{0}' does not have a docstring!", testfile));
            }

            string output = _compiler.Parameters.OutputWriter.ToString();

            Assert.AreEqual(expected.Trim(), output.ToString().Trim().Replace("\r\n", "\n"), testfile);
        }
Beispiel #3
0
        public override System.Reflection.Assembly CompileMultiple(Hashtable scriptNamesAndCode)
        {
            bool      bUseTemporaryFiles = true;
            ArrayList files = new ArrayList();             //for easier deletion after compile

            this._compiler.Parameters.Input.Clear();

            foreach (DictionaryEntry de in scriptNamesAndCode)
            {
                string nameID = (string)de.Key;
                string code   = (string)de.Value;

                if (bUseTemporaryFiles)
                {
                    string tempName = "__boo_" + nameID + ".boo";
                    Endogine.Files.FileReadWrite.Write(tempName, code);

                    System.IO.FileInfo file = new System.IO.FileInfo(tempName);
                    files.Add(file);

                    this._compiler.Parameters.Input.Add(new FileInput(tempName));
                }
                else
                {
                    //TODO: why is this StreamReader closed???
                    StringInput inp = new StringInput(nameID, code);
                    inp.Open();
                    this._compiler.Parameters.Input.Add(inp);
                }
            }

            Boo.Lang.Compiler.CompilerContext context = this._compiler.Run();

            if (bUseTemporaryFiles)
            {
                //foreach (System.IO.FileInfo file in files)
                //	file.Delete();
            }


            //The main module name is always filename+Module in pascal case;
            //this file is actually RunBooModule!
            //Using duck-typing, we can directly invoke static methods
            //Without having to do the typical System.Reflection voodoo.

            string[] errors;
            if (context.GeneratedAssembly == null)
            {
                errors = new string[context.Errors.Count];
                string sErrors = "Boo compiler errors\r\n";                 // for "+nameID+":\r\n";
                for (int i = 0; i < context.Errors.Count; i++)
                {
                    Boo.Lang.Compiler.CompilerError err = context.Errors[i];
                    string sError = err.LexicalInfo.FileName + "(" + err.LexicalInfo.Line + "," + err.LexicalInfo.Column + ")" + "\r\n" + err.Message;

                    if (System.IO.File.Exists(err.LexicalInfo.FileName))
                    {
                        sError += "Source:\r\n";
                        System.IO.StreamReader rd = new System.IO.StreamReader(err.LexicalInfo.FileName);
                        string   sFileContents    = rd.ReadToEnd();
                        string[] sLines           = sFileContents.Split("\r\n".ToCharArray());
                        if (err.LexicalInfo.Line > 0)
                        {
                            sError += sLines[(err.LexicalInfo.Line - 1) * 2] + "\r\n";
                        }
                        sError += sLines[err.LexicalInfo.Line * 2];
                    }

                    errors[i] = sError;
                    sErrors  += sError + "\r\n";
                }
                throw new Exception(sErrors);
            }
            else
            {
                foreach (DictionaryEntry de in scriptNamesAndCode)
                {
                    string nameID = (string)de.Key;
                    this._classToAssembly[nameID] = context.GeneratedAssembly;
                }
            }
            return(context.GeneratedAssembly);
        }