/// <param name="options">The options to use when running the test</param> public TextRunner(TextUI textUI, NUnitLiteOptions options) { _textUI = textUI; _options = options; if (!Directory.Exists(_options.WorkDirectory)) { Directory.CreateDirectory(_options.WorkDirectory); } #if !NETCF if (_options.TeamCity) { _teamCity = new TeamCityEventListener(); } #endif }
/// <param name="options">The options to use when running the test</param> public TextRunner(TextUI textUI, NUnitLiteOptions options) { _textUI = textUI; _options = options; if (!Directory.Exists(_options.WorkDirectory)) Directory.CreateDirectory(_options.WorkDirectory); #if !NETCF if (_options.TeamCity) _teamCity = new TeamCityEventListener(); #endif }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public int Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. _options = new ConsoleOptions(args); _workDirectory = _options.WorkDirectory; if (_workDirectory == null) { _workDirectory = NUnit.Env.DefaultWorkDirectory; } else if (!Directory.Exists(_workDirectory)) { Directory.CreateDirectory(_workDirectory); } #if !SILVERLIGHT #if !NETCF if (_options.TeamCity) { _teamCity = new TeamCityEventListener(); } #endif if (_options.OutFile != null) { _outWriter = new ExtendedTextWriter(new StreamWriter(Path.Combine(_workDirectory, _options.OutFile))); Console.SetOut(_outWriter); ColorConsole.Enabled = false; } if (_options.ErrFile != null) { _errWriter = new StreamWriter(Path.Combine(_workDirectory, _options.ErrFile)); Console.SetError(_errWriter); } #endif if (_options.NoColor) { ColorConsole.Enabled = false; } if (!_options.NoHeader) { WriteHeader(_outWriter); } if (_options.ShowHelp) { WriteHelpText(); return(OK); } if (_options.ErrorMessages.Count > 0) { foreach (string line in _options.ErrorMessages) { _outWriter.WriteLine(line); } _options.WriteOptionDescriptions(_outWriter); return(INVALID_ARG); } Assembly callingAssembly = Assembly.GetCallingAssembly(); // We must call this before creating the runner so that any internal logging is initialized var level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), _options.InternalTraceLevel ?? "Off", true); #if NETCF // NETCF: Try to unify InitializeInternalTrace(callingAssembly.GetName().CodeBase, level); #else InitializeInternalTrace(callingAssembly.Location, level); #endif _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); _outWriter.WriteLine(ColorStyle.SectionHeader, "Test Files:"); DisplayRequestedOptions(_outWriter); WriteRuntimeEnvironment(_outWriter); if (_options.WaitBeforeExit && _options.OutFile != null) { _outWriter.WriteLine("Ignoring /wait option - only valid for Console"); } var runSettings = MakeRunSettings(_options); TestFilter filter = CreateTestFilter(_options); try { foreach (string name in _options.InputFiles) #if NETCF { _assemblies.Add(name.IndexOf(',') != -1 || (name.IndexOf('\\') == -1 && !Path.HasExtension(name)) ? Assembly.Load(name) : Assembly.LoadFrom(name)); } #else { _assemblies.Add(Assembly.Load(name)); } #endif 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, runSettings) != null) { return(_options.Explore ? ExploreTests() : RunTests(filter)); } var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return(OK); } catch (FileNotFoundException ex) { _outWriter.WriteLine(ColorStyle.Error, ex.Message); return(FILE_NOT_FOUND); } catch (Exception ex) { _outWriter.WriteLine(ColorStyle.Error, ex.ToString()); return(UNEXPECTED_ERROR); } finally { if (_options.OutFile == null) { if (_options.WaitBeforeExit) { _outWriter.WriteLine(ColorStyle.Label, "Press Enter key to continue . . ."); Console.ReadLine(); } } else { _outWriter.Close(); } if (_options.ErrFile != null) { _errWriter.Close(); } } }
/// <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. _options = new CommandLineOptions(args); _workDirectory = _options.WorkDirectory; if (_workDirectory == null) _workDirectory = Environment.CurrentDirectory; else if (!Directory.Exists(_workDirectory)) Directory.CreateDirectory(_workDirectory); #if !SILVERLIGHT if (_options.DisplayTeamCityServiceMessages) _teamCity = new TeamCityEventListener(); if (_options.OutFile != null) { _outWriter = new StreamWriter(Path.Combine(_workDirectory, _options.OutFile)); Console.SetOut(_outWriter); } if (_options.ErrFile != null) { _errWriter = new StreamWriter(Path.Combine(_workDirectory, _options.ErrFile)); Console.SetError(_errWriter); } #endif if (!_options.NoHeader) WriteHeader(_outWriter); if (_options.ShowHelp) _outWriter.Write(_options.HelpText); else if (_options.ErrorMessages.Count > 0) { foreach(string line in _options.ErrorMessages) _outWriter.WriteLine(line); _outWriter.WriteLine(_options.HelpText); } else { Assembly callingAssembly = Assembly.GetCallingAssembly(); // We must call this before creating the runner so that any internal logging is initialized InternalTraceLevel level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), _options.InternalTraceLevel, true); InitializeInternalTrace(callingAssembly.Location, level); _runner = new NUnitLiteTestAssemblyRunner(new DefaultTestAssemblyBuilder()); DisplayRequestedOptions(_outWriter); WriteRuntimeEnvironment(_outWriter); if (_options.Wait && _options.OutFile != null) _outWriter.WriteLine("Ignoring /wait option - only valid for Console"); var runSettings = MakeRunSettings(_options); TestFilter filter = CreateTestFilter(_options); try { foreach (string name in _options.InputFiles) _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, runSettings) == null) { var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (_options.Explore) ExploreTests(); else { RunTests(filter); } } catch (FileNotFoundException ex) { _outWriter.WriteLine(ex.Message); } catch (Exception ex) { _outWriter.WriteLine(ex.ToString()); } finally { if (_options.OutFile == null) { if (_options.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { _outWriter.Close(); } if (_options.ErrFile != null) _errWriter.Close(); } } }
/// <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. _options = new CommandLineOptions(args); _workDirectory = _options.WorkDirectory; if (_workDirectory == null) { _workDirectory = Environment.CurrentDirectory; } else if (!Directory.Exists(_workDirectory)) { Directory.CreateDirectory(_workDirectory); } #if !SILVERLIGHT if (_options.DisplayTeamCityServiceMessages) { _teamCity = new TeamCityEventListener(); } if (_options.OutFile != null) { _outWriter = new StreamWriter(Path.Combine(_workDirectory, _options.OutFile)); Console.SetOut(_outWriter); } if (_options.ErrFile != null) { _errWriter = new StreamWriter(Path.Combine(_workDirectory, _options.ErrFile)); Console.SetError(_errWriter); } #endif if (!_options.NoHeader) { WriteHeader(_outWriter); } if (_options.ShowHelp) { _outWriter.Write(_options.HelpText); } else if (_options.ErrorMessages.Count > 0) { foreach (string line in _options.ErrorMessages) { _outWriter.WriteLine(line); } _outWriter.WriteLine(_options.HelpText); } else { Assembly callingAssembly = Assembly.GetCallingAssembly(); // We must call this before creating the runner so that any internal logging is initialized InternalTraceLevel level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), _options.InternalTraceLevel, true); InitializeInternalTrace(callingAssembly.Location, level); _runner = new NUnitLiteTestAssemblyRunner(new DefaultTestAssemblyBuilder()); DisplayRequestedOptions(_outWriter); WriteRuntimeEnvironment(_outWriter); if (_options.Wait && _options.OutFile != null) { _outWriter.WriteLine("Ignoring /wait option - only valid for Console"); } var runSettings = MakeRunSettings(_options); TestFilter filter = CreateTestFilter(_options); try { foreach (string name in _options.InputFiles) { _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, runSettings) == null) { var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return; } if (_options.Explore) { ExploreTests(); } else { RunTests(filter); } } catch (FileNotFoundException ex) { _outWriter.WriteLine(ex.Message); } catch (Exception ex) { _outWriter.WriteLine(ex.ToString()); } finally { if (_options.OutFile == null) { if (_options.Wait) { Console.WriteLine("Press Enter key to continue . . ."); Console.ReadLine(); } } else { _outWriter.Close(); } if (_options.ErrFile != null) { _errWriter.Close(); } } } }