Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private static void RunConsole(string[] args)
        {
            HConsoleHelper.InitConsoleHandles();

            CmdLineHandler.HandleCommandLine(args);

            HConsoleHelper.ReleaseConsoleHandles();
        }
Exemplo n.º 3
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);
     }
 }
Exemplo n.º 4
0
 public void CreateCmdLineHandler() {
    _clh = new CmdLineHandler();
    _clh.AcceptOption("assembly", true);
    _clh.AcceptOption("recipe", true);
    _clh.AcceptOption("autorun", false);
    _clh.AcceptOption("xml", true);
    _clh.AcceptOption("optionalValue", false);
    _clh.AcceptOption("?", false);
 }
Exemplo n.º 5
0
 public void CreateCmdLineHandler()
 {
     _clh = new CmdLineHandler();
     _clh.AcceptOption("assembly", true);
     _clh.AcceptOption("recipe", true);
     _clh.AcceptOption("autorun", false);
     _clh.AcceptOption("xml", true);
     _clh.AcceptOption("optionalValue", false);
     _clh.AcceptOption("?", false);
 }
Exemplo n.º 6
0
 private static void SetUpRegexSelector(CmdLineHandler clh, IRecipe recipe)
 {
     if (clh.HasOption("pattern"))
     {
         var selector = new RegexSelector {
             Pattern = clh.GetOptionValueFor("pattern")
         };
         recipe.RegisterSelector(selector);
     }
 }
Exemplo n.º 7
0
        public void DirTest()
        {
            var resultFile = ".\\images.xaml";

            if (File.Exists(resultFile))
            {
                File.Delete(resultFile);
            }
            CmdLineHandler.HandleCommandLine("BuildDict /inputdir:\"..\\..\\TestFiles\\\" /outputname:images /outputdir:.").Should().Be(0);
            File.Exists(resultFile).Should().BeTrue();
        }
Exemplo n.º 8
0
        private static void SetUpCommandLineOptions(CmdLineHandler clh)
        {
            clh.AcceptOption("testCategory", true);
            clh.AcceptOption("tc", true);

            clh.AcceptOption("fixtureCategory", true);
            clh.AcceptOption("fc", true);

            clh.AcceptOption("pattern", true);
            clh.AcceptOption("assembly", true);
            clh.AcceptOption("recipe", true);
            clh.AcceptOption("xml", false);
            clh.AcceptOption("?", false);
            clh.AcceptOption("help", false);
            clh.AcceptOption("waitfordebugger", false);
        }
Exemplo n.º 9
0
        private static CmdLineHandler SetUpCommandLineHandler(string[] args)
        {
            var clh = new CmdLineHandler();

            clh.AcceptOption("autoexit", false);
            clh.AcceptOption("autorun", false);
            clh.AcceptOption("assembly", true);
            clh.AcceptOption("recipe", true);
            clh.AcceptOption("xml", false);
            clh.AcceptOption("?", false);
            clh.AcceptOption("help", false);

            clh.AcceptOption("nodialogs", false);
            // hidden option so we can automatically test invalid command line
            // arguments [23aug09, ml]

            clh.Evaluate(args);
            return(clh);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Default constructor.
        /// </summary>
// ReSharper disable MemberCanBeInternal
        public MainForm(CmdLineHandler clh)
        {
// ReSharper restore MemberCanBeInternal
            // Required for Windows Form Designer support. Must be first call in
            // this method.
            InitializeComponent();

            // Other intialization
            //

            // Create event handlers that are used to monitor testing results
            //
            _testStarted      = OnTestStarted;
            _testFailed       = OnTestFailed;
            _testError        = OnTestError;
            _testSkipped      = OnTestSkipped;
            _testPassed       = OnTestPassed;
            _recipeStarted    = OnRecipeStarted;
            _recipeFinished   = OnRecipeFinished;
            _recipeSaved      = OnRecipeSaved;
            _recipeAborted    = OnRecipeAborted;
            _assemblyAdded    = OnAssemblyAdded;
            _assemblyRemoving = OnAssemblyRemoving;
            _assemblyChanged  = OnAssemblyChanged;

            RecipeFactory.Loaded     += OnRecipeLoaded;
            RecipeFactory.LoadFailed += OnRecipeLoadFailed;
            RecipeFactory.Closing    += OnRecipeClosing;

            // Create a default recipe, which will trigger the RecipeLoaded event, and set
            // the current recipe to the instance that is created here. [ml]
            RecipeFactory.NewRecipe(string.Empty);

            _clh = clh;

            Application.Idle += ApplicationIdle;
        }
Exemplo n.º 11
0
 public void Value_can_be_enclosed_in_quotes_to_embed_spaces()
 {
     var args = new CmdLineHandler( new[] { "--test=\"foo bar\"" } );
     Assert.Equal( "foo bar", args.Settings[ "test" ] );
 }
Exemplo n.º 12
0
 public void Handler_uses_environment_if_no_cmdline_provided()
 {
     var args = new CmdLineHandler();
 }
Exemplo n.º 13
0
 public void Value_is_empty_if_no_value_in_string()
 {
     var args = new CmdLineHandler( new[] { "--test=" } );
     Assert.Equal( "", args.Settings[ "test" ] );
 }
Exemplo n.º 14
0
 public void Value_can_be_retrieved_in_long_format()
 {
     var args = new CmdLineHandler( new[] { "--test=yes" } );
     Assert.Equal( "yes", args.Settings[ "test" ] );
 }
Exemplo n.º 15
0
 public void EmptyArgsTest2()
 {
     CmdLineHandler.HandleCommandLine("").Should().NotBe(0);
 }
Exemplo n.º 16
0
 public void Handler_trims_leading_spaces_in_long_format()
 {
     var args = new CmdLineHandler( new[] { " --test=foo" } );
     Assert.Equal( "foo", args.Settings[ "test" ] );
 }
Exemplo n.º 17
0
 public void Handler_uses_environment_if_no_cmdline_provided()
 {
     var args = new CmdLineHandler();
 }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        public void Value_can_be_enclosed_in_quotes_to_embed_spaces()
        {
            var args = new CmdLineHandler(new[] { "--test=\"foo bar\"" });

            Assert.Equal("foo bar", args.Settings["test"]);
        }
Exemplo n.º 20
0
 public void Value_can_contain_embedded_equals()
 {
     var args = new CmdLineHandler( new[] { "--test=foo=bar" } );
     Assert.Equal( "foo=bar", args.Settings[ "test" ] );
 }
Exemplo n.º 21
0
        public void Value_is_true_if_no_assignment_after_key()
        {
            var args = new CmdLineHandler(new[] { "--test" });

            Assert.Equal("true", args.Settings["test"]);
        }
Exemplo n.º 22
0
        public void Value_is_empty_if_no_value_in_string()
        {
            var args = new CmdLineHandler(new[] { "--test=" });

            Assert.Equal("", args.Settings["test"]);
        }
Exemplo n.º 23
0
        public void Value_can_be_retrieved_in_short_format_with_slash()
        {
            var args = new CmdLineHandler(new[] { "/test:yes" });

            Assert.Equal("yes", args.Settings["test"]);
        }
Exemplo n.º 24
0
 private static bool HelpNeeded(CmdLineHandler clh)
 {
     return(clh.Count == 0 || clh.HasOption("?") || clh.HasOption("help"));
 }
Exemplo n.º 25
0
        public void Handler_trims_leading_spaces_in_long_format()
        {
            var args = new CmdLineHandler(new[] { " --test=foo" });

            Assert.Equal("foo", args.Settings["test"]);
        }
Exemplo n.º 26
0
 public void Handler_trims_trailing_spaces_in_short_format()
 {
     var args = new CmdLineHandler( new[] { "-t:foo " } );
     Assert.Equal( "foo", args.Settings[ "t" ] );
 }
Exemplo n.º 27
0
        public void Value_can_be_retrieved_in_long_format()
        {
            var args = new CmdLineHandler(new[] { "--test=yes" });

            Assert.Equal("yes", args.Settings["test"]);
        }
Exemplo n.º 28
0
        public void EmptyArgsTest1()
        {
            string arg = null;

            CmdLineHandler.HandleCommandLine(arg).Should().Be(0);
        }
Exemplo n.º 29
0
        public void Handler_trims_trailing_spaces_in_short_format()
        {
            var args = new CmdLineHandler(new[] { "-t:foo " });

            Assert.Equal("foo", args.Settings["t"]);
        }
Exemplo n.º 30
0
 public void HelpTest()
 {
     CmdLineHandler.HandleCommandLine("-H").Should().Be(0);
 }
Exemplo n.º 31
0
 public void Value_can_be_retrieved_in_short_format_with_slash()
 {
     var args = new CmdLineHandler( new[] { "/test:yes" } );
     Assert.Equal( "yes", args.Settings[ "test" ] );
 }
Exemplo n.º 32
0
        public void Value_can_contain_embedded_equals()
        {
            var args = new CmdLineHandler(new[] { "--test=foo=bar" });

            Assert.Equal("foo=bar", args.Settings["test"]);
        }
Exemplo n.º 33
0
 public void Value_is_true_if_no_assignment_after_key()
 {
     var args = new CmdLineHandler( new[] { "--test" } );
     Assert.Equal( "true", args.Settings[ "test" ] );
 }