SetProperty() public method

Applies a named property to the test
public SetProperty ( string propName, double propValue ) : TestCaseData
propName string
propValue double
return TestCaseData
Esempio n. 1
0
            public static IEnumerable<TestCaseData> LexerFailureCases()
            {
                var f = TestUtils.GetTestPath(@"IronLua.Tests\Scripts\Lexer01_XXX.lua");

                using (var reader = File.OpenText(f))
                {
                    var snippet = new StringBuilder();
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        if (line.StartsWith("--XX") || line.StartsWith("--::"))
                        {
                            // failure cases
                            var testData = snippet.ToString();
                            var expect = line.TrimStart('-', 'X', ':').Trim();

                            var testCaseData = new TestCaseData(testData, expect);

                            if (line.StartsWith("--XX"))
                                testCaseData.SetProperty("FailureCase", 1);

                            testCaseData.SetName(testData);
                            yield return testCaseData;

                            snippet.Clear();
                        }
                        else if (!line.StartsWith("--"))
                        {
                            snippet.Append(line);
                        }
                    }
                }
            }
Esempio n. 2
0
        private IEnumerable<TestCaseData> BuildTestCases(IEnumerable<TestXml> tests)
        {
            var testCases = new List<TestCaseData>(tests.Count());

            foreach (var test in tests)
            {
                TestCaseData testCaseDataNUnit = new TestCaseData(test);
                testCaseDataNUnit.SetName(test.GetName());
                testCaseDataNUnit.SetDescription(test.Description);
                foreach (var category in test.Categories)
                    testCaseDataNUnit.SetCategory(CategoryHelper.Format(category));
                foreach (var property in test.Traits)
                    testCaseDataNUnit.SetProperty(property.Name, property.Value);

                //Assign auto-categories
                if (EnableAutoCategories)
                {
                    foreach (var system in test.Systems)
                        foreach (var category in system.GetAutoCategories())
                            testCaseDataNUnit.SetCategory(CategoryHelper.Format(category));
                }
                //Assign auto-categories
                if (EnableGroupAsCategory)
                {
                    foreach (var groupName in test.GroupNames)
                        testCaseDataNUnit.SetCategory(CategoryHelper.Format(groupName));
                }

                testCases.Add(testCaseDataNUnit);
            }
            return testCases;
        }
Esempio n. 3
0
        public static IEnumerable<TestCaseData> GenerateTests()
        {
            var file = Directory.GetFiles(@"..\..\..\Unit Tests\Script-Tests", "*.zip").First();
            var zipfile = new ZipFile(file);

            var includeBuilder = new StringBuilder();
            includeBuilder.AppendLine(File.ReadAllText(Path.Combine(@"..\..\..\Unit Tests\Script-Tests", @"harness\cth.js")));
            includeBuilder.AppendLine(File.ReadAllText(Path.Combine(@"..\..\..\Unit Tests\Script-Tests", @"harness\sta.js")));
            includeBuilder.AppendLine(File.ReadAllText(Path.Combine(@"..\..\..\Unit Tests\Script-Tests", @"harness\ed.js")));
            var includes = includeBuilder.ToString();

            var skippedTests = XDocument.Load(Path.Combine(@"..\..\..\Unit Tests\Script-Tests", @"config\excludelist.xml"))
                .Element("excludeList")
                .Elements("test")
                .Select(t => new { Name = t.Attribute("id").Value, Reason = t.Value }).ToList();

            Regex r = new Regex("^ \\* @([a-z]+)(.*?)$", RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);

            for (int i = 0; i < zipfile.Count; i++)
            {
                var zf = zipfile[i];
                if (zf.IsFile && zf.Name.EndsWith(".js"))
                {
                    string content;
                    using (var sr = new StreamReader(zipfile.GetInputStream(zf)))
                        content = sr.ReadToEnd();

                    var isNegative = content.Contains("@negative");
                    string negativeType = null;
                    if (isNegative)
                    {
                        var negativeStart = content.IndexOf("@negative ") + "@negative ".Length;
                        if (negativeStart != -1 + "@negative ".Length)
                        {
                            negativeType = content.Substring(negativeStart, content.IndexOfAny(new char[] { '\r', '\n' }, negativeStart) - negativeStart).Trim();
                            if (string.IsNullOrWhiteSpace(negativeType))
                                negativeType = null;
                        }
                    }
                    var forceStrictMode = content.Contains("@onlyStrict");

                    var fn = Path.GetFileName(zf.Name);
                    string name = fn.Substring(0, fn.Length - 3);
                    var tcd = new TestCaseData(includes, content, forceStrictMode, isNegative, negativeType).SetName(name.Replace("_", "__").Replace('.', '_'));
                    if (skippedTests.Any(t => t.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        tcd = tcd.Ignore(skippedTests.First(t => t.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Reason);
                    }
                    else
                    {
                        tcd = tcd.SetProperty("_NOTIGNORED", "TRUE");
                    }

                    tcd = tcd.SetProperty("@_name", zf.Name.Substring(0, zf.Name.Length - 3)).SetProperty("@_negativeType", negativeType);

                    foreach (Match match in r.Matches(content))
                    {
                        if (match.Groups[2].Length > 0)
                            tcd = tcd.SetProperty("_" + match.Groups[1].Value.ToUpper(), match.Groups[2].Value.Trim());
                        else
                            tcd = tcd.SetProperty("_" + match.Groups[1].Value.ToUpper(), "TRUE");
                    }

                    yield return tcd;
                }
            }
        }