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); }
private static void RunConsole(string[] args) { HConsoleHelper.InitConsoleHandles(); CmdLineHandler.HandleCommandLine(args); HConsoleHelper.ReleaseConsoleHandles(); }
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); } }
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); }
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); }
private static void SetUpRegexSelector(CmdLineHandler clh, IRecipe recipe) { if (clh.HasOption("pattern")) { var selector = new RegexSelector { Pattern = clh.GetOptionValueFor("pattern") }; recipe.RegisterSelector(selector); } }
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(); }
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); }
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); }
/// <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; }
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" ] ); }
public void Handler_uses_environment_if_no_cmdline_provided() { var args = new CmdLineHandler(); }
public void Value_is_empty_if_no_value_in_string() { var args = new CmdLineHandler( new[] { "--test=" } ); Assert.Equal( "", args.Settings[ "test" ] ); }
public void Value_can_be_retrieved_in_long_format() { var args = new CmdLineHandler( new[] { "--test=yes" } ); Assert.Equal( "yes", args.Settings[ "test" ] ); }
public void EmptyArgsTest2() { CmdLineHandler.HandleCommandLine("").Should().NotBe(0); }
public void Handler_trims_leading_spaces_in_long_format() { var args = new CmdLineHandler( new[] { " --test=foo" } ); Assert.Equal( "foo", args.Settings[ "test" ] ); }
public void Handler_uses_environment_if_no_cmdline_provided() { var args = new CmdLineHandler(); }
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); }
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"]); }
public void Value_can_contain_embedded_equals() { var args = new CmdLineHandler( new[] { "--test=foo=bar" } ); Assert.Equal( "foo=bar", args.Settings[ "test" ] ); }
public void Value_is_true_if_no_assignment_after_key() { var args = new CmdLineHandler(new[] { "--test" }); Assert.Equal("true", args.Settings["test"]); }
public void Value_is_empty_if_no_value_in_string() { var args = new CmdLineHandler(new[] { "--test=" }); Assert.Equal("", args.Settings["test"]); }
public void Value_can_be_retrieved_in_short_format_with_slash() { var args = new CmdLineHandler(new[] { "/test:yes" }); Assert.Equal("yes", args.Settings["test"]); }
private static bool HelpNeeded(CmdLineHandler clh) { return(clh.Count == 0 || clh.HasOption("?") || clh.HasOption("help")); }
public void Handler_trims_leading_spaces_in_long_format() { var args = new CmdLineHandler(new[] { " --test=foo" }); Assert.Equal("foo", args.Settings["test"]); }
public void Handler_trims_trailing_spaces_in_short_format() { var args = new CmdLineHandler( new[] { "-t:foo " } ); Assert.Equal( "foo", args.Settings[ "t" ] ); }
public void Value_can_be_retrieved_in_long_format() { var args = new CmdLineHandler(new[] { "--test=yes" }); Assert.Equal("yes", args.Settings["test"]); }
public void EmptyArgsTest1() { string arg = null; CmdLineHandler.HandleCommandLine(arg).Should().Be(0); }
public void Handler_trims_trailing_spaces_in_short_format() { var args = new CmdLineHandler(new[] { "-t:foo " }); Assert.Equal("foo", args.Settings["t"]); }
public void HelpTest() { CmdLineHandler.HandleCommandLine("-H").Should().Be(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" ] ); }
public void Value_can_contain_embedded_equals() { var args = new CmdLineHandler(new[] { "--test=foo=bar" }); Assert.Equal("foo=bar", args.Settings["test"]); }
public void Value_is_true_if_no_assignment_after_key() { var args = new CmdLineHandler( new[] { "--test" } ); Assert.Equal( "true", args.Settings[ "test" ] ); }