예제 #1
0
        internal int ExecuteValidCommandLine(CmdLineHandler clh, IRecipe recipe)
        {
            var result = 0;

            SetUpCategorySelector("testCategory", clh, recipe);
            SetUpCategorySelector("fixtureCategory", clh, recipe);
            SetUpRegexSelector(clh, recipe);

            DefaultXmlWriter resultWriter = null;

            if (clh.HasOption("xml"))
            {
                var resultPathName = clh.GetOptionValueFor("xml");
                resultPathName = resultPathName == string.Empty ? "csUnit.results.xml" : resultPathName;
                resultWriter   = new DefaultXmlWriter(recipe, resultPathName);
            }

            recipe.Aborted += RecipeAborted;
            recipe.RunTests(new TestRun(new AllTestsCriterion()));

            recipe.Join();

            if (resultWriter != null)
            {
                resultWriter.Save();
                result = resultWriter.Result;
            }
            if (result == 0 && _recipeAborted)
            {
                Console.Error.WriteLine("Tests Aborted: " + _recipeAbortMessage);
                result = 2;
            }
            return(result);
        }
예제 #2
0
 private static void SetUpCategorySelector(string optionName, CmdLineHandler clh, IRecipe recipe)
 {
     if (clh.HasOption(optionName))
     {
         var selector = new CategorySelector();
         selector.IncludedCategories.Add(clh.GetOptionValueFor(optionName));
         recipe.RegisterSelector(selector);
     }
 }
예제 #3
0
 private static void SetUpRegexSelector(CmdLineHandler clh, IRecipe recipe)
 {
     if (clh.HasOption("pattern"))
     {
         var selector = new RegexSelector {
             Pattern = clh.GetOptionValueFor("pattern")
         };
         recipe.RegisterSelector(selector);
     }
 }
예제 #4
0
        private int Execute(string[] args)
        {
            var result = 0;

            try {
                var clh = new CmdLineHandler();
                SetUpCommandLineOptions(clh);
                clh.Evaluate(args);

                if (!clh.IsValid())
                {
                    PrintUsage();
                    result = 1;
                }
                else if (HelpNeeded(clh))
                {
                    PrintUsage();
                    result = 0;
                }
                else
                {
                    IRecipe recipe = null;
                    if (clh.HasOption("recipe"))
                    {
                        if (clh.HasOption("assembly"))
                        {
                            Console.WriteLine("Option 'recipe' present, ignoring option 'assembly'.");
                        }
                        recipe = RecipeFactory.Load(clh.GetOptionValueFor("recipe"));
                        if (recipe == null)
                        {
                            Console.WriteLine(String.Format(
                                                  "Couldn't read recipe at location '{0}'.",
                                                  clh.GetOptionValueFor("recipe")));
                            result = 1;
                        }
                    }
                    else if (clh.HasOption("assembly"))
                    {
                        var filePathName = clh.GetOptionValueFor("assembly");
                        if (File.Exists(filePathName))
                        {
                            recipe = RecipeFactory.NewRecipe(string.Empty);
                            recipe.AddAssembly(filePathName);
                        }
                        else
                        {
                            Console.WriteLine("Error: Couldn't read assembly at location '{0}'.", filePathName);
                            PrintUsage();
                            result = 1;
                        }
                    }
                    if (recipe != null &&
                        result == 0)
                    {
                        result = ExecuteValidCommandLine(clh, recipe);
                    }
                }
            }
            catch (Exception ex) {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                Console.WriteLine("Internal error: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
                result = 1;
            }
            Console.WriteLine("Done.");
            return(result);
        }
예제 #5
0
 private static bool HelpNeeded(CmdLineHandler clh)
 {
     return(clh.Count == 0 || clh.HasOption("?") || clh.HasOption("help"));
 }