Inheritance: TestFilter
コード例 #1
0
ファイル: AndFilterTests.cs プロジェクト: rojac07/nunit
        public void MatchTest()
        {
            var filter = new AndFilter(new CategoryFilter("Dummy"), new IdFilter(_dummyFixture.Id));

            Assert.That(filter.Match(_dummyFixture));
            Assert.False(filter.Match(_anotherFixture));
        }
コード例 #2
0
ファイル: AndFilterTests.cs プロジェクト: rojac07/nunit
        public void ExplicitMatchTest()
        {
            var filter = new AndFilter(new CategoryFilter("Dummy"), new IdFilter(_dummyFixture.Id));

            Assert.That(filter.IsExplicitMatch(_topLevelSuite));
            Assert.That(filter.IsExplicitMatch(_dummyFixture));
            Assert.False(filter.IsExplicitMatch(_dummyFixture.Tests[0]));

            Assert.False(filter.Match(_anotherFixture));
        }
コード例 #3
0
ファイル: AndFilterTests.cs プロジェクト: yyjdelete/nunit
        public void CombineTest(IEnumerable <bool> inputBooleans, bool expectedResult,
                                MockTestFilter.MatchFunction matchFunction)
        {
            var filters = new List <MockTestFilter>();

            foreach (var inputBool in inputBooleans)
            {
                var strictFilter = new MockTestFilter(_dummyFixture, matchFunction, inputBool);
                Assert.AreEqual(inputBool, ExecuteMatchFunction(strictFilter, matchFunction));

                filters.Add(strictFilter);
            }

            var  filter           = new AndFilter(filters.ToArray());
            bool calculatedResult = ExecuteMatchFunction(filter, matchFunction);

            Assert.AreEqual(expectedResult, calculatedResult);
        }
コード例 #4
0
        public void TestNestedAndFilters()
        {
            var filter = new AndFilter(
                new CategoryFilter("Dummy"),
                new PropertyFilter("Priority", "High"));

            Assert.That(filter.Match(_dummyFixture));
            Assert.That(filter.IsExplicitMatch(_dummyFixture));

            Assert.False(filter.Match(_anotherFixture));
            Assert.False(filter.IsExplicitMatch(_anotherFixture));

            Assert.False(filter.Match(_yetAnotherFixture));
            Assert.False(filter.IsExplicitMatch(_yetAnotherFixture));

            Assert.False(filter.Match(_explicitFixture));
            Assert.False(filter.IsExplicitMatch(_explicitFixture));
        }
コード例 #5
0
        private TestFilter GetTerm()
        {
            TestFilter prim = GetPrimitive();

            if (token != "+" && token != "-")
            {
                return(prim);
            }

            AndFilter filter = new AndFilter(prim);

            while (token == "+" || token == "-")
            {
                string tok = token;
                GetToken();
                prim = GetPrimitive();
                filter.Add(tok == "-" ? new NotFilter(prim) : prim);
            }

            return(filter);
        }
コード例 #6
0
ファイル: TestFilter.cs プロジェクト: jhsiegel/nunit
        private static TestFilter FromXml(TNode node)
        {
            switch (node.Name)
            {
                case "filter":
                case "and":
                    var andFilter = new AndFilter();
                    foreach (var childNode in node.ChildNodes)
                        andFilter.Add(FromXml(childNode));
                    return andFilter;

                case "or":
                    var orFilter = new OrFilter();
                    foreach (var childNode in node.ChildNodes)
                        orFilter.Add(FromXml(childNode));
                    return orFilter;

                case "not":
                    return new NotFilter(FromXml(node.FirstChild));

                case "id":
                    var idFilter = new IdFilter();
                    if (node.Value != null)
                        foreach (string id in node.Value.Split(COMMA))
                            idFilter.Add(id);
                    return idFilter;

                case "tests":
                    var testFilter = new SimpleNameFilter();
                    foreach (var childNode in node.SelectNodes("test"))
                        testFilter.Add(childNode.Value);
                    return testFilter;

                case "cat":
                    var catFilter = new CategoryFilter();
                    if (node.Value != null)
                        foreach (string cat in node.Value.Split(COMMA))
                            catFilter.AddCategory(cat);
                    return catFilter;

                default:
                    throw new ArgumentException("Invalid filter element: " + node.Name, "xmlNode");
            }
        }
コード例 #7
0
ファイル: TextUI.cs プロジェクト: Powerino73/paradox
        /// <summary>
        /// Execute a test run based on the aruments passed
        /// from Main.
        /// </summary>
        /// <param name="args">An array of arguments</param>
        public void Execute(string[] args)
        {
            // NOTE: Execute must be directly called from the
            // test assembly in order for the mechanism to work.
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (commandLineOptions.OutFile != null)
                this.writer = new StreamWriter(commandLineOptions.OutFile);

            if (!commandLineOptions.NoHeader)
                WriteHeader(this.writer);

            if (commandLineOptions.ShowHelp)
                writer.Write(commandLineOptions.HelpText);
            else if (commandLineOptions.Error)
            {
                writer.WriteLine(commandLineOptions.ErrorMessage);
                writer.WriteLine(commandLineOptions.HelpText);
            }
            else
            {
                WriteRuntimeEnvironment(this.writer);

                if (commandLineOptions.Wait && commandLineOptions.OutFile != null)
                    writer.WriteLine("Ignoring /wait option - only valid for Console");

                // We only have one commandline option that has to be passed
                // to the runner, so we do it here for convenience.
                var runnerSettings = new Dictionary<string, object>();
                Randomizer.InitialSeed = commandLineOptions.InitialSeed;

                TestFilter filter = commandLineOptions.TestCount > 0
                    ? new SimpleNameFilter(commandLineOptions.Tests)
                    : TestFilter.Empty;

                try
                {
                    foreach (string name in commandLineOptions.Parameters)
                        assemblies.Add(Assembly.Load(name));

                    if (assemblies.Count == 0)
                        assemblies.Add(callingAssembly);

                    // TODO: For now, ignore all but first assembly
                    Assembly assembly = assemblies[0];

                    //Randomizer.InitialSeed = commandLineOptions.InitialSeed;

                    if (runner.Load(assembly, runnerSettings) == null)
                    {
                        var assemblyName = AssemblyHelper.GetAssemblyName(assembly);
                        Console.WriteLine("No tests found in assembly {0}", assemblyName.Name);
                        return;
                    }

                    if (commandLineOptions.Explore)
                        ExploreTests();
                    else
                    {
                        if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty)
                        {
                            TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter;

                            if (filter.IsEmpty)
                                filter = includeFilter;
                            else
                                filter = new AndFilter(filter, includeFilter);
                        }

                        if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty)
                        {
                            TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter);

                            if (filter.IsEmpty)
                                filter = excludeFilter;
                            else if (filter is AndFilter)
                                ((AndFilter)filter).Add(excludeFilter);
                            else
                                filter = new AndFilter(filter, excludeFilter);
                        }

                        RunTests(filter);
                    }
                }
                catch (FileNotFoundException ex)
                {
                    writer.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.ToString());
                }
                finally
                {
                    if (commandLineOptions.OutFile == null)
                    {
                        if (commandLineOptions.Wait)
                        {
                            Console.WriteLine("Press Enter key to continue . . .");
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        writer.Close();
                    }
                }
            }
        }
コード例 #8
0
        static void ChainCategoryFilter(IEnumerable <string> categories, bool negate, ref TestFilter chain)
        {
            bool gotCategories = false;
            if (categories != null) {
                var filter = new CategoryFilter ();
                foreach (string c in categories) {
                    Log.Info (TAG, "  {0}", c);
                    filter.AddCategory (c);
                    gotCategories = true;
                }

                chain = new AndFilter (chain, negate ? (TestFilter)new NotFilter (filter) : (TestFilter)filter);
            }

            if (!gotCategories)
                Log.Info (TAG, "  none");
        }
コード例 #9
0
        internal void AddTestFilters(IEnumerable<string> included, IEnumerable<string> excluded)
        {
            TestFilter filter = TestFilter.Empty;

            Log.Info (TAG, "Configuring test categories to include:");
            ChainCategoryFilter (included, false, ref filter);

            Log.Info (TAG, "Configuring test categories to exclude:");
            ChainCategoryFilter (excluded, true, ref filter);

            if (filter.IsEmpty)
                return;

            if (Filter == null)
                Filter = filter;
            else
                Filter = new AndFilter (Filter, filter);
        }
コード例 #10
0
ファイル: AndFilterTests.cs プロジェクト: yyjdelete/nunit
        public void IsNotEmpty()
        {
            var filter = new AndFilter(new CategoryFilter("Dummy"), new IdFilter(_dummyFixture.Id));

            Assert.False(filter.IsEmpty);
        }
コード例 #11
0
ファイル: AndFilterTests.cs プロジェクト: nunit/nunit
        public void CombineTest(IEnumerable<bool> inputBooleans, bool expectedResult,
            MockTestFilter.MatchFunction matchFunction)
        {
            var filters = new List<MockTestFilter>();
            foreach (var inputBool in inputBooleans)
            {
                var strictFilter = new MockTestFilter(_dummyFixture, matchFunction, inputBool);
                Assert.AreEqual(inputBool, ExecuteMatchFunction(strictFilter, matchFunction));

                filters.Add(strictFilter);
            }

            var filter = new AndFilter(filters.ToArray());
            bool calculatedResult = ExecuteMatchFunction(filter, matchFunction);
            Assert.AreEqual(expectedResult, calculatedResult);
        }
コード例 #12
0
ファイル: TestFilter.cs プロジェクト: NameNIL/iOS4Unity
        public static TestFilter FromXml(string xmlText)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlText);
            XmlNode topNode = doc.FirstChild;

            if (topNode.Name != "filter")
                throw new Exception("Expected filter element at top level");

            // Initially, an empty filter
            TestFilter result = TestFilter.Empty;
            bool isEmptyResult = true;

            XmlNodeList testNodes = topNode.SelectNodes("tests/test");
            XmlNodeList includeNodes = topNode.SelectNodes("include/category");
            XmlNodeList excludeNodes = topNode.SelectNodes("exclude/category");

            if (testNodes.Count > 0)
            {
                SimpleNameFilter nameFilter = new SimpleNameFilter();
                foreach (XmlNode testNode in topNode.SelectNodes("tests/test"))
                    nameFilter.Add(testNode.InnerText);

                result = nameFilter;
                isEmptyResult = false;
            }

            if (includeNodes.Count > 0)
            {
                //CategoryFilter includeFilter = new CategoryFilter();
                //foreach (XmlNode includeNode in includeNodes)
                //    includeFilter.AddCategory(includeNode.InnerText);

                // Temporarily just look at the first element
                XmlNode includeNode = includeNodes[0];
                TestFilter includeFilter = new CategoryExpression(includeNode.InnerText).Filter;

                if (isEmptyResult)
                    result = includeFilter;
                else
                    result = new AndFilter(result, includeFilter);
                isEmptyResult = false;
            }

            if (excludeNodes.Count > 0)
            {
                CategoryFilter categoryFilter = new CategoryFilter();
                foreach (XmlNode excludeNode in excludeNodes)
                    categoryFilter.AddCategory(excludeNode.InnerText);
                TestFilter excludeFilter = new NotFilter(categoryFilter);

                if (isEmptyResult)
                    result = excludeFilter;
                else
                    result = new AndFilter(result, excludeFilter);
                isEmptyResult = false;
            }

            return result;
        }
コード例 #13
0
ファイル: TestFilterTests.cs プロジェクト: JohanLarsson/nunit
        public void AndFilter_Constructor()
        {
            var filter = new AndFilter(new CategoryFilter("Dummy"), new IdFilter(dummyFixture.Id));

            Assert.False(filter.IsEmpty);
            Assert.That(filter.Match(dummyFixture));
            Assert.False(filter.Match(anotherFixture));
        }
コード例 #14
0
ファイル: TextUI.cs プロジェクト: yudhitech/xamarin-android
        /// <summary>
        /// Execute a test run based on the aruments passed
        /// from Main.
        /// </summary>
        /// <param name="args">An array of arguments</param>
        public void Execute(string[] args)
        {
            // NOTE: Execute must be directly called from the
            // test assembly in order for the mechanism to work.
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (commandLineOptions.OutFile != null)
                this.writer = new StreamWriter(commandLineOptions.OutFile);

            if (!commandLineOptions.NoHeader)
                WriteHeader(this.writer);

            if (commandLineOptions.ShowHelp)
                writer.Write(commandLineOptions.HelpText);
            else if (commandLineOptions.Error)
            {
                writer.WriteLine(commandLineOptions.ErrorMessage);
                writer.WriteLine(commandLineOptions.HelpText);
            }
            else
            {
                WriteRuntimeEnvironment(this.writer);

                if (commandLineOptions.Wait && commandLineOptions.OutFile != null)
                    writer.WriteLine("Ignoring /wait option - only valid for Console");

            #if SILVERLIGHT
                IDictionary loadOptions = new System.Collections.Generic.Dictionary<string, string>();
            #else
                IDictionary loadOptions = new Hashtable();
            #endif
                //if (options.Load.Count > 0)
                //    loadOptions["LOAD"] = options.Load;

                //IDictionary runOptions = new Hashtable();
                //if (commandLineOptions.TestCount > 0)
                //    runOptions["RUN"] = commandLineOptions.Tests;

                ITestFilter filter = commandLineOptions.TestCount > 0
                    ? new SimpleNameFilter(commandLineOptions.Tests)
                    : TestFilter.Empty;

                try
                {
                    foreach (string name in commandLineOptions.Parameters)
                        assemblies.Add(Assembly.Load(name));

                    if (assemblies.Count == 0)
                        assemblies.Add(callingAssembly);

                    // TODO: For now, ignore all but first assembly
                    Assembly assembly = assemblies[0] as Assembly;

                    Randomizer.InitialSeed = commandLineOptions.InitialSeed;

                    if (!runner.Load(assembly, loadOptions))
                    {
                        AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(assembly);
                        Console.WriteLine("No tests found in assembly {0}", assemblyName.Name);
                        return;
                    }

                    if (commandLineOptions.Explore)
                        ExploreTests();
                    else
                    {
                        if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty)
                        {
                            TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter;

                            if (filter.IsEmpty)
                                filter = includeFilter;
                            else
                                filter = new AndFilter(filter, includeFilter);
                        }

                        if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty)
                        {
                            TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter);

                            if (filter.IsEmpty)
                                filter = excludeFilter;
                            else if (filter is AndFilter)
                                ((AndFilter)filter).Add(excludeFilter);
                            else
                                filter = new AndFilter(filter, excludeFilter);
                        }

                        RunTests(filter);
                    }
                }
                catch (FileNotFoundException ex)
                {
                    writer.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    writer.WriteLine(ex.ToString());
                }
                finally
                {
                    if (commandLineOptions.OutFile == null)
                    {
                        if (commandLineOptions.Wait)
                        {
                            Console.WriteLine("Press Enter key to continue . . .");
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        writer.Close();
                    }
                }
            }
        }
コード例 #15
0
ファイル: AndFilterTests.cs プロジェクト: rojac07/nunit
        public void IsNotEmpty()
        {
            var filter = new AndFilter(new CategoryFilter("Dummy"), new IdFilter(_dummyFixture.Id));

            Assert.False(filter.IsEmpty);
        }
コード例 #16
0
ファイル: TestFilter.cs プロジェクト: remcomulder/nunit
        /// <summary>
        /// Create a TestFilter from it's TNode representation
        /// </summary>
        public static TestFilter FromXml(TNode node)
        {
            bool isRegex = node.Attributes["re"] == "1";

            switch (node.Name)
            {
                case "filter":
                case "and":
                    var andFilter = new AndFilter();
                    foreach (var childNode in node.ChildNodes)
                        andFilter.Add(FromXml(childNode));
                    return andFilter;

                case "or":
                    var orFilter = new OrFilter();
                    foreach (var childNode in node.ChildNodes)
                        orFilter.Add(FromXml(childNode));
                    return orFilter;

                case "not":
                    return new NotFilter(FromXml(node.FirstChild));

                case "id":
                    return new IdFilter(node.Value); 

                case "test":
                    return new FullNameFilter(node.Value) { IsRegex = isRegex };

                case "name":
                    return new TestNameFilter(node.Value) { IsRegex = isRegex };

                case "method":
                    return new MethodNameFilter(node.Value) { IsRegex = isRegex };

                case "class":
                    return new ClassNameFilter(node.Value) { IsRegex = isRegex };

                case "cat":
                    return new CategoryFilter(node.Value) { IsRegex = isRegex };

                case "prop":
                    string name = node.Attributes["name"];
                    if (name != null)
                        return new PropertyFilter(name, node.Value) { IsRegex = isRegex };
                    break;
            }

            throw new ArgumentException("Invalid filter element: " + node.Name, "xmlNode");
        }
コード例 #17
0
		private TestFilter GetTerm()
		{
			TestFilter prim = GetPrimitive();
			if ( token != "+" && token != "-" )
				return prim;

			AndFilter filter = new AndFilter( prim );
			
			while ( token == "+"|| token == "-" )
			{
				string tok = token;
				GetToken();
				prim = GetPrimitive();
				filter.Add( tok == "-" ? new NotFilter( prim ) : prim );
			}

			return filter;
		}
コード例 #18
0
        private static TestFilter FromXml(XmlNode xmlNode)
        {
            switch (xmlNode.Name)
            {
                case "filter":
                case "and":
                    var andFilter = new AndFilter();
                    foreach (XmlNode childNode in xmlNode.ChildNodes)
                        andFilter.Add(FromXml(childNode));
                    return andFilter;

                case "or":
                    var orFilter = new OrFilter();
                    foreach (System.Xml.XmlNode childNode in xmlNode.ChildNodes)
                        orFilter.Add(FromXml(childNode));
                    return orFilter;

                case "not":
                    return new NotFilter(FromXml(xmlNode.FirstChild));

                case "id":
                    var idFilter = new IdFilter();
                    foreach (string id in xmlNode.InnerText.Split(COMMA))
                        idFilter.Add(int.Parse(id));
                    return idFilter;

                case "tests":
                    var testFilter = new SimpleNameFilter();
                    foreach (XmlNode childNode in xmlNode.SelectNodes("test"))
                        testFilter.Add(childNode.InnerText);
                    return testFilter;

                case "cat":
                    var catFilter = new CategoryFilter();
                    foreach (string cat in xmlNode.InnerText.Split(COMMA))
                        catFilter.AddCategory(cat);
                    return catFilter;

                default:
                    throw new ArgumentException("Invalid filter element: " + xmlNode.Name, "xmlNode");
            }
        }