Beispiel #1
0
    static void Main()
    {
        var setup = new ScriptRuntimeSetup();

        setup.LanguageSetups.Add(
            new LanguageSetup(
                typeof(RubyContext).AssemblyQualifiedName,
                "IronRuby",
                new[] { "IronRuby" },
                new[] { ".rb" }
                )
            );
        var runtime = new ScriptRuntime(setup);
        var engine  = runtime.GetEngine("IronRuby");
        var ec      = Ruby.GetExecutionContext(runtime);

        ec.DefineGlobalVariable("bob", new Person
        {
            Name         = "Bob",
            Age          = 30,
            Weight       = 213,
            FavouriteDay = "1/1/2000"
        });
        var eval = engine.Execute <bool>(
            "return ($bob.Age && 3 && $bob.Weight > 50) || $bob.Age < 3"
            );

        Console.WriteLine(eval);
    }
Beispiel #2
0
        public TestRuntime(Driver /*!*/ driver, TestCase /*!*/ testCase)
        {
            _driver   = driver;
            _testName = testCase.Name;

            if (_driver.IsDebug)
            {
                Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName);
            }

            var           runtimeSetup  = ScriptRuntimeSetup.ReadConfiguration();
            LanguageSetup langaugeSetup = null;

            foreach (var language in runtimeSetup.LanguageSetups)
            {
                if (language.TypeName == typeof(RubyContext).AssemblyQualifiedName)
                {
                    langaugeSetup = language;
                    break;
                }
            }

            // TODO: dynamic modules with symbols are not available in partial trust
            runtimeSetup.DebugMode = !driver.PartialTrust;
            langaugeSetup.Options["InterpretedMode"] = _driver.Interpret;
            langaugeSetup.Options["Verbosity"]       = 2;
            langaugeSetup.Options["Compatibility"]   = testCase.Compatibility;

            _env     = Ruby.CreateRuntime(runtimeSetup);
            _engine  = Ruby.GetEngine(_env);
            _context = Ruby.GetExecutionContext(_engine);
        }
Beispiel #3
0
 private void Initialize()
 {
     Engine       = Ruby.GetEngine(Runtime);
     Context      = Ruby.GetExecutionContext(Engine);
     CurrentScope = Engine.CreateScope();
     Operations   = Engine.CreateOperations();
     LoadAssemblies(typeof(object), typeof(Uri), typeof(Func <object>), typeof(StandardKernel), typeof(IRubyEngine));
     RequireRubyFile("Ninject.Dynamic.initializer.rb", ReaderType.Assembly);
 }
Beispiel #4
0
        public void SetFixture(RubyRuntime data)
        {
            if (_scriptRuntime == null)
            {
                _scriptRuntime = data.CreateRuntime();
            }

            _engine  = _scriptRuntime.GetRubyEngine();
            _context = Ruby.GetExecutionContext(_engine);
        }
Beispiel #5
0
 private void Initialize()
 {
     Engine       = Ruby.GetEngine(Runtime);
     Context      = Ruby.GetExecutionContext(Engine);
     CurrentScope = Engine.CreateScope();
     Operations   = Engine.CreateOperations();
     LoadAssemblies(typeof(object), typeof(Uri), typeof(HttpResponseBase), typeof(MembershipCreateStatus), typeof(RouteTable), typeof(Controller), typeof(RubyController));
     AddLoadPaths();
     DefineReadOnlyGlobalVariable(Constants.ScriptRuntimeVariable, Engine);
     RequireControllerFile();
 }
Beispiel #6
0
        protected override void EstablishContext()
        {
            if (_scriptRuntime == null)
            {
                var rubySetup = Ruby.CreateRubySetup();
                rubySetup.Options["InterpretedMode"] = true;

                var runtimeSetup = new ScriptRuntimeSetup();
                runtimeSetup.LanguageSetups.Add(rubySetup);
                runtimeSetup.DebugMode = true;

                _scriptRuntime = Ruby.CreateRuntime(runtimeSetup);
            }
            _engine  = _scriptRuntime.GetRubyEngine();
            _context = Ruby.GetExecutionContext(_engine);
        }
Beispiel #7
0
        public static int Run(List <string> /*!*/ args)
        {
            if (!ParseArguments(args))
            {
                return(-3);
            }

            int status = 0;

            if (_runTokenizerDriver)
            {
                TokenizerTestDriver driver = new TokenizerTestDriver(Ruby.GetExecutionContext(Ruby.CreateRuntime()));
                if (!driver.ParseArgs(args))
                {
                    return(-3);
                }

                status = driver.RunTests();
            }
            else
            {
                InitializeDomain();
                Driver driver = new Driver();

                if (Manual.TestCode.Trim().Length == 0)
                {
                    status = driver.RunUnitTests(args);
                }
                else
                {
                    driver.RunManualTest();

                    // for case the test is forgotten, this would fail the test suite:
                    status = -2;
                }
            }

            // return failure on bad filter (any real failures throw)
            return(status);
        }