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; }
/// <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; }
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 bool HelpNeeded(CmdLineHandler clh) { return clh.Count == 0 || clh.HasOption("?") || clh.HasOption("help"); }
private static void SetUpRegexSelector(CmdLineHandler clh, IRecipe recipe) { if(clh.HasOption("pattern")) { var selector = new RegexSelector { Pattern = clh.GetOptionValueFor( "pattern" ) }; recipe.RegisterSelector(selector); } }
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); } }
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 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; }