* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / nunit20 / util / ConsoleOptions.cs
1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
3 '
4 ' Copyright  2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright  2000-2002 Philip A. Craig
6 '
7 ' This software is provided 'as-is', without any express or implied warranty. In no 
8 ' event will the authors be held liable for any damages arising from the use of this 
9 ' software.
10
11 ' Permission is granted to anyone to use this software for any purpose, including 
12 ' commercial applications, and to alter it and redistribute it freely, subject to the 
13 ' following restrictions:
14 '
15 ' 1. The origin of this software must not be misrepresented; you must not claim that 
16 ' you wrote the original software. If you use this software in a product, an 
17 ' acknowledgment (see the following) in the product documentation is required.
18 '
19 ' Portions Copyright  2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright  2000-2002 Philip A. Craig
21 '
22 ' 2. Altered source versions must be plainly marked as such, and must not be 
23 ' misrepresented as being the original software.
24 '
25 ' 3. This notice may not be removed or altered from any source distribution.
26 '
27 '***********************************************************************************/
28 #endregion
29
30 namespace NUnit.Util
31 {
32         using System;
33         using Codeblast;
34
35         public class ConsoleOptions : CommandLineOptions
36         {
37                 [Option(Description = "Fixture to test")]
38                 public string fixture;
39
40                 [Option(Description = "Project configuration to load")]
41                 public string config;
42
43                 [Option(Description = "Name of XML output file")]
44                 public string xml;
45
46                 [Option(Description = "Name of transform file")]
47                 public string transform;
48
49                 [Option(Description = "Display XML to the console")]
50                 public bool xmlConsole;
51
52                 [Option(Short="out", Description = "File to receive test output")]
53                 public string output;
54
55                 [Option(Description = "File to receive test error output")]
56                 public string err;
57
58                 [Option(Description = "Label each test in stdOut")]
59                 public bool labels = false;
60
61                 [Option(Description = "List of categories to include")]
62                 public string include;
63
64                 [Option(Description = "List of categories to exclude")]
65                 public string exclude;
66
67 //              [Option(Description = "Run in a separate process")]
68 //              public bool process;
69
70 //              [Option(Description = "Run in a separate AppDomain")]
71 //              public bool domain;
72
73 //              [Option(Description = "Disable shadow copy when running in separate domain")]
74                 [Option(Description = "Disable shadow copy")]
75                 public bool noshadow;
76
77                 [Option (Description = "Run tests on a separate thread")]
78                 public bool thread;
79
80                 [Option(Description = "Wait for input before closing console window")]
81                 public bool wait = false;
82
83                 [Option(Description = "Do not display the logo")]
84                 public bool nologo = false;
85
86                 [Option(Short="?", Description = "Display help")]
87                 public bool help = false;
88
89                 private bool isInvalid = false; 
90
91                 public ConsoleOptions(String[] args) : base(args) 
92                 {}
93
94                 protected override void InvalidOption(string name)
95                 {
96                         isInvalid = true;
97                 }
98
99                 public bool Validate()
100                 {
101                         if(isInvalid) return false; 
102
103                         if(HasInclude && HasExclude) return false;
104
105                         if(NoArgs) return true; 
106
107                         if(IsFixture) return true; 
108
109                         if(ParameterCount >= 1) return true; 
110
111                         return false;
112                 }
113
114                 public bool IsAssembly 
115                 {
116                         get 
117                         {
118                                 return ParameterCount >= 1 && !IsFixture;
119                         }
120                 }
121
122                 public bool IsTestProject
123                 {
124                         get
125                         {
126                                 return ParameterCount == 1 && NUnitProject.CanLoadAsProject( (string)Parameters[0] );
127                         }
128                 }
129
130                 public bool IsFixture 
131                 {
132                         get 
133                         {
134                                 return ParameterCount >= 1 && 
135                                         ((fixture != null) && (fixture.Length > 0));
136                         }
137                 }
138
139                 public bool IsXml 
140                 {
141                         get 
142                         {
143                                 return (xml != null) && (xml.Length != 0);
144                         }
145                 }
146
147                 public bool isOut
148                 {
149                         get 
150                         {
151                                 return (output != null) && (output.Length != 0);
152                         }
153                 }
154
155                 public bool isErr
156                 {
157                         get 
158                         {
159                                 return (err != null) && (err.Length != 0);
160                         }
161                 }
162
163                 public bool IsTransform 
164                 {
165                         get 
166                         {
167                                 return (transform != null) && (transform.Length != 0);
168                         }
169                 }
170
171                 public bool HasInclude 
172                 {
173                         get 
174                         {
175                                 return include != null && include.Length != 0;
176                         }
177                 }
178
179                 public bool HasExclude 
180                 {
181                         get 
182                         {
183                                 return exclude != null && exclude.Length != 0;
184                         }
185                 }
186
187                 public string[] IncludedCategories
188                 {
189                         get
190                         {
191                                 if (HasInclude)
192                                         return include.Split( new char[] {';', ','});
193
194                                 return null;
195                         }
196                 }
197
198                 public string[] ExcludedCategories
199                 {
200                         get
201                         {
202                                 if (HasExclude)
203                                         return exclude.Split( new char[] {';', ','});
204
205                                 return null;
206                         }
207                 }
208
209                 public override void Help()
210                 {
211                         Console.WriteLine();
212                         Console.WriteLine( "NUNIT-CONSOLE [inputfiles] [options]" );
213                         Console.WriteLine();
214                         Console.WriteLine( "Runs a set of NUnit tests from the console." );
215                         Console.WriteLine();
216                         Console.WriteLine( "You may specify one or more assemblies or a single" );
217                         Console.WriteLine( "project file of type .nunit." );
218                         Console.WriteLine();
219                         Console.WriteLine( "Options:" );
220                         base.Help();
221                         Console.WriteLine();
222                         Console.WriteLine( "Options that take values may use an equal sign, a colon" );
223                         Console.WriteLine( "or a space to separate the option from its value." );
224                         Console.WriteLine();
225                 }
226         }
227 }