Ejemplo n.º 1
0
        protected override ITestResult ExecuteTest(IContext ctx, string test)
        {
            var errors = new StringBuilder();
            string score = null;

            ctx.SetFunction(
                "NotifyResult",
                new Action<string, string>((name, result) => { })
            );
            ctx.SetFunction(
                "NotifyError",
                new Action<string, object>((name, error) => errors.AppendLine(name + ": " + error.ToString()))
            );
            ctx.SetFunction(
                "NotifyScore",
                new Action<string>(p => score = p)
            );

            try
            {
                ctx.ExecuteFile(test);
                ctx.Execute(@"
                    BenchmarkSuite.RunSuites({
                        NotifyResult: NotifyResult,
                        NotifyError: NotifyError,
                        NotifyScore: NotifyScore
                });");
            }
            catch (Exception ex)
            {
                errors.AppendLine("Exception: " + ex.GetBaseException().Message);
            }

            if (errors.Length > 0)
                return new TestError(errors.ToString());

            return new TestResult(Double.Parse(score, CultureInfo.InvariantCulture));
        }