Пример #1
0
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        internal string GetTempConfigFile(LangSetup[] langs) {
            string xmlPrefix = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +  
"<configuration>" +
  "<configSections>"+
    "<section name=\"microsoft.scripting\" type=\"Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting, Version=1.1.0.20, Culture=neutral, PublicKeyToken=31bf3856ad364e35\" requirePermission=\"false\" />"+
  "</configSections>"+

  "<microsoft.scripting>"+
    "<languages>";

            string xmlSuffix ="</languages>"+
  "</microsoft.scripting>"+
"</configuration>";

    //"<options>"+
    //  "<set language=\"Ruby\" option=\"LibraryPaths\" value=\"..\\..\\Languages\\Ruby\\libs;..\\..\\External.LCA_RESTRICTED\\Languages\\Ruby\\Ruby-1.8.6p287\\lib\\ruby\\site_ruby\\1.8;..\\..\\..\\External.LCA_RESTRICTED\\Languages\\Ruby\\Ruby-1.8.6p287\\lib\\ruby\\site_ruby;..\\..\\..\\External.LCA_RESTRICTED\\Languages\\Ruby\\Ruby-1.8.6p287\\lib\\ruby\\1.8\" />"+
    //"</options>"+

            StringBuilder ret = new StringBuilder();
            Array.ForEach(langs, lang => ret.AppendLine(lang.ToString()));

            string contents = xmlPrefix + ret.ToString() + xmlSuffix;

            return TestHelpers.CreateTempSourceFile( contents, ".config");
        }
Пример #2
0
        static LangSetup() {
            Python = new LangSetup( new[] { "IronPython","Python","py" },new[] { ".py" }, "IronPython 2.6",
                "IronPython.Runtime.PythonContext", "IronPython, Version=2.7.0.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            );

            Ruby = new LangSetup( new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" },"IronRuby",
                "IronRuby.Runtime.RubyContext", "IronRuby, Version=1.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            );
        }
Пример #3
0
        static LangSetup() {
            Python = new LangSetup( new[] { "IronPython","Python","py" },new[] { ".py" }, "IronPython 3.0",
                "IronPython.Runtime.PythonContext", "IronPython, Version=3.0.0.0, Culture=neutral"
            );

            Ruby = new LangSetup( new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" },"IronRuby",
                "IronRuby.Runtime.RubyContext", "IronRuby, Version=1.1.4.0, Culture=neutral"
            );
        }
Пример #4
0
        static LangSetup()
        {
            Python = new LangSetup(new[] { "IronPython", "Python", "py" }, new[] { ".py" }, "IronPython 2.7",
                                   "IronPython.Runtime.PythonContext", "IronPython, Version=2.7.0.40, Culture=neutral"
                                   );

            Ruby = new LangSetup(new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" }, "IronRuby",
                                 "IronRuby.Runtime.RubyContext", "IronRuby, Version=1.1.3.0, Culture=neutral"
                                 );
        }
Пример #5
0
        public void ReadConfiguration_EmptyTypeName()
        {
            LangSetup py2 = new LangSetup(LangSetup.Python.Names, LangSetup.Python.Extensions, LangSetup.Python.DisplayName,
                                          "", LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var    eng        = new ScriptRuntime(srs).GetEngine("py");

            Assert.AreEqual(LangSetup.Python.Names[0], eng.Setup.DisplayName);
        }
Пример #6
0
        public void ReadConfiguration_EmptyExtensions()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, new[] { "", "" }, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var    runtime    = new ScriptRuntime(srs);

            Assert.AreEqual(5, runtime.GetEngine("py").Execute("2+3"));
        }
Пример #7
0
        public void ReadConfiguration_IncorrectType()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, py1.Extensions, py1.DisplayName,
                                          "IronPython.Runtime.PythonBuffer", py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr  = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");

            Assert.Fail("some exception should have been thrown");
        }
Пример #8
0
        public void ReadConfiguration_MissingAssembly()
        {
            LangSetup lang = new LangSetup(new[] { "SomeName" }, new[] { ".sn" }, "Somename",
                                           "SomeLang.Runtime.LangContext",
                                           "SomeLang, Version=8.0.0.5050, Culture=neutral, PublicKeyToken=31345fgsd4344e35");

            string configFile = GetTempConfigFile(new[] { lang });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            //this should throw..error message should be meaningful
            var sr = new ScriptRuntime(srs);

            Assert.Fail("some exception should have been thrown");
        }
Пример #9
0
        public void ReadConfiguration_DuplicateNames()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(LangSetup.Ruby.Names, py1.Extensions, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2, LangSetup.Ruby });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(2, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.Fail("some exception should have been thrown");
        }
Пример #10
0
        public void ReadConfiguration_Multi_SameTypeDifferentName()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(new[] { "NewPython" }, py1.Extensions, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py1, py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);
            Assert.AreEqual("NewPython", sr.Setup.LanguageSetups[0].Names[0]);
        }
Пример #11
0
        public void ReadConfiguration_DuplicateEmptyExtensions()
        {
            LangSetup rb1 = new LangSetup(LangSetup.Ruby.Names, new[] { "", "" }, LangSetup.Ruby.DisplayName,
                                          LangSetup.Ruby.TypeName, LangSetup.Ruby.AssemblyString);

            LangSetup py2 = new LangSetup(LangSetup.Python.Names, new[] { "", "" }, LangSetup.Python.DisplayName,
                                          LangSetup.Python.TypeName, LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { rb1, py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr   = new ScriptRuntime(srs);
            var eng  = sr.GetEngine("py");
            var eng2 = sr.GetEngine("rb");

            Assert.AreEqual(5, eng.Execute("2+3"));
        }
Пример #12
0
        internal string GetTempConfigFile(LangSetup[] langs)
        {
            string xmlPrefix = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
            "<configuration>" +
              "<configSections>"+
            "<section name=\"microsoft.scripting\" type=\"Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting, Version=1.1.0.30, Culture=neutral, PublicKeyToken=31bf3856ad364e35\" requirePermission=\"false\" />"+
              "</configSections>"+

              "<microsoft.scripting>"+
            "<languages>";

            string xmlSuffix ="</languages>"+
              "</microsoft.scripting>"+
            "</configuration>";

            StringBuilder ret = new StringBuilder();
            Array.ForEach(langs, lang => ret.AppendLine(lang.ToString()));

            string contents = xmlPrefix + ret.ToString() + xmlSuffix;

            return TestHelpers.CreateTempSourceFile( contents, ".config");
        }
Пример #13
0
        public void ReadConfiguration_DuplicateEmptyExtensions()
        {
            LangSetup rb1 = new LangSetup(LangSetup.Ruby.Names, new[] { "", "" }, LangSetup.Ruby.DisplayName,
                    LangSetup.Ruby.TypeName, LangSetup.Ruby.AssemblyString);

            LangSetup py2 = new LangSetup(LangSetup.Python.Names, new[] { "", "" }, LangSetup.Python.DisplayName,
                                LangSetup.Python.TypeName, LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { rb1, py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");
            var eng2 = sr.GetEngine("rb");

            Assert.AreEqual(5, eng.Execute("2+3"));
        }
Пример #14
0
        public void ReadConfiguration_DuplicateExtensions()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, LangSetup.Ruby.Extensions, py1.DisplayName,
                                py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2, LangSetup.Ruby });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            Assert.AreEqual(2, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");
            Assert.Fail("some exception should have been thrown");
        }
Пример #15
0
        public void ReadConfiguration_MisMatchedTypeAssembly()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, py1.Extensions, py1.DisplayName,
                                LangSetup.Ruby.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2});
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");
            Assert.Fail("some exception should have been thrown");
        }
Пример #16
0
        public void ReadConfiguration_NullDisplayName()
        {
            LangSetup py2 = new LangSetup(LangSetup.Python.Names, LangSetup.Python.Extensions, null,
                                LangSetup.Python.TypeName, LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var eng = new ScriptRuntime(srs).GetEngine("py");

            Assert.AreEqual("", eng.Setup.DisplayName);
        }
Пример #17
0
        public void ReadConfiguration_Multi_SameTypeDifferentName()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup( new[]{"NewPython"}, py1.Extensions, py1.DisplayName,
                                py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py1, py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);
            Assert.AreEqual("NewPython", sr.Setup.LanguageSetups[0].Names[0]);
        }
Пример #18
0
        public void ReadConfiguration_Multi_SameNameDifferentType()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup( py1.Names, py1.Extensions, py1.DisplayName,
                                LangSetup.Ruby.TypeName, LangSetup.Ruby.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py1, py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            Assert.AreEqual(2, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
            Assert.Fail("some exception should have been thrown");
        }
Пример #19
0
        public void ReadConfiguration_MissingAssembly()
        {
            LangSetup lang = new LangSetup(new[]{"SomeName"}, new[]{".sn"}, "Somename",
                    "SomeLang.Runtime.LangContext",
                    "SomeLang, Version=8.0.0.5050, Culture=neutral, PublicKeyToken=31345fgsd4344e35");

            string configFile = GetTempConfigFile(new[] { lang});
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);

            //this should throw..error message should be meaningful
            var sr = new ScriptRuntime(srs);
            Assert.Fail("some exception should have been thrown");
        }
Пример #20
0
        public void ReadConfiguration_EmptyExtensions()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, new[]{"",""}, py1.DisplayName,
                                py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var runtime = new ScriptRuntime(srs);

            Assert.AreEqual(5, runtime.GetEngine("py").Execute("2+3"));
        }
Пример #21
0
 static LangSetup()
 {
     Python = new LangSetup(new[] { "IronPython", "Python", "py" }, new[] { ".py" }, "IronPython 3.0",
                            "IronPython.Runtime.PythonContext", "IronPython, Version=2.9.0.0, Culture=neutral"
                            );
 }