Example #1
0
 private void WorkerThread()
 {
     this.suite = new TestSuite(path => App.GetResourceStream(new Uri("Files/" + path.Replace('\\', '/'), UriKind.Relative)).Stream);
     this.suite.TestFinished += new EventHandler<TestEventArgs>(OnTestFinished);
     this.suite.Start();
     this.StatusTextBlock.Dispatcher.BeginInvoke(() =>
     {
         this.StatusTextBlock.Text = string.Format("{0} success, {1} skipped, {2} failures, {3} total",
             this.suite.SuccessfulTestCount, this.suite.SkippedTestCount, this.suite.FailedTestCount, this.suite.ExecutedTestCount);
     });
 }
Example #2
0
        static void Main(string[] args)
        {
            var timer = System.Diagnostics.Stopwatch.StartNew();
            var engine = new Jurassic.ScriptEngine();
            Console.WriteLine("Start-up time: {0}ms", timer.ElapsedMilliseconds);
            using (var testSuite = new TestSuite(Path.Combine ("..", "..", "..", "Test Suite Files")))
            {
                //testSuite.RunInSandbox = true;
                //testSuite.IncludedTests.Add("12.7-1");
                //testSuite.IncludedTests.Add("15.2.3.14-5-13");

                testSuite.TestFinished += OnTestFinished;
                testSuite.Start();

                Console.WriteLine();
                Console.WriteLine("Finished in {0} minutes, {1} seconds!", (int)timer.Elapsed.TotalMinutes, timer.Elapsed.Seconds);
                Console.WriteLine("Succeeded: {0} ({1:P1})", testSuite.SuccessfulTestCount, testSuite.SuccessfulPercentage);
                Console.WriteLine("Failed: {0} ({1:P1})", testSuite.FailedTestCount, testSuite.FailedPercentage);
                Console.WriteLine("Skipped: {0} ({1:P1})", testSuite.SkippedTestCount, testSuite.SkippedPercentage);
                Console.WriteLine("Total: {0}", testSuite.ExecutedTestCount);
            }
        }
Example #3
0
        /// <summary>
        /// Creates a new test.
        /// </summary>
        /// <param name="suite"> The test suite the test is part of. </param>
        /// <param name="path"> The path of the test script within the container file. </param>
        /// <param name="fileContents"> The contents of the file that defines the test. </param>
        public Test(TestSuite suite, string path, string fileContents)
        {
            if (suite == null)
                throw new ArgumentNullException("suite");
            if (path == null)
                throw new ArgumentNullException("path");
            if (fileContents == null)
                throw new ArgumentNullException("fileContents");
            this.Suite = suite;
            this.Path = path;

            // Extract the test metadata.
            var reader = new StringReader(fileContents);
            string line;

            // Skip past any initial comments.
            while (true)
            {
                line = reader.ReadLine();
                if (line == null || Regex.IsMatch(line, @"^\s*(//.*)?$") == false)
                    break;
            }

            // The comment metadata is optional.
            if (Regex.IsMatch(line, @"^\s*/\*.*$"))
            {
                while (true)
                {

                    line = reader.ReadLine();
                    if (line == null || Regex.IsMatch(line, @"\*/\s*$"))
                        break;

                    // Check if the line contains a property.
                    var propertyMatch = Regex.Match(line, @"^\s*\*?\s*@(\w+)\s*(.*)$");
                    if (propertyMatch.Success)
                    {
                        var propertyName = propertyMatch.Groups[1].Value;
                        var propertyText = propertyMatch.Groups[2].Value;
                        switch (propertyName)
                        {
                            case "description":
                                this.Description = propertyText;
                                break;
                            case "noStrict":
                                if (this.strictMode == StrictMode.Unspecified)
                                    this.strictMode = StrictMode.NonStrictOnly;
                                else
                                    throw new InvalidOperationException(string.Format("Test {0} marked as 'noStrict' and 'onlyStrict'.", this.Path));
                                break;
                            case "onlyStrict":
                                if (this.strictMode == StrictMode.Unspecified)
                                    this.strictMode = StrictMode.StrictOnly;
                                else
                                    throw new InvalidOperationException(string.Format("Test {0} marked as 'noStrict' and 'onlyStrict'.", this.Path));
                                break;
                            case "negative":
                                this.IsNegativeTest = true;
                                if (string.IsNullOrEmpty(propertyText.Trim()) == false)
                                    this.NegativeErrorPattern = propertyText.Trim();
                                break;
                        }
                    }
                }
            }

            // The rest of the file is the script itself.
            this.Script = reader.ReadToEnd();
        }