3 // - Unit tests for System.CodeDom.Compiler.Executor
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using NUnit.Framework;
33 using System.CodeDom.Compiler;
35 using System.Runtime.InteropServices;
36 using System.Security.Principal;
38 namespace MonoTests.System.CodeDom.Compiler
41 public class ExecutorTest
44 private bool cmdNotFound;
49 private TempFileCollection tfc;
50 private WindowsIdentity winid;
54 public void FixtureSetUp ()
56 cmd = "ping"; // available everywhere
57 cd = Environment.CurrentDirectory;
58 temp = Path.GetTempPath ();
59 tfc = new TempFileCollection ();
60 winid = WindowsIdentity.GetCurrent ();
66 errcode = Executor.ExecWaitWithCapture (cmd, tfc, ref output, ref error);
69 // cmd might not be in the PATH
75 public void FixtureTearDown ()
81 [ExpectedException (typeof (ExternalException))]
82 public void ExecWait_NullCmd ()
84 Executor.ExecWait (null, new TempFileCollection ());
88 [ExpectedException (typeof (NullReferenceException))]
89 public void ExecWait_NullTempFileCollection ()
92 Assert.Ignore ("ping command not found.");
94 Executor.ExecWait (cmd, null);
98 [Category ("NotWorking")] // https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=341293
99 public void ExecWait ()
102 Assert.Ignore ("ping command not found.");
105 Executor.ExecWait (cmd, new TempFileCollection ());
107 } catch (ExternalException ex) {
108 // Cannot execute a program. The command being executed was .
109 Assert.AreEqual (typeof (ExternalException), ex.GetType (), "#2");
110 Assert.AreEqual (2, ex.ErrorCode, "#3");
111 Assert.IsNull (ex.InnerException, "#4");
112 Assert.IsNotNull (ex.Message, "#5");
117 public void ExecWaitWithCapture ()
120 Assert.Ignore ("ping command not found.");
122 string output = null;
124 TempFileCollection tfc = new TempFileCollection ();
125 Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (cmd, tfc, ref output, ref error), "ErrorCode");
126 Assert.IsTrue (File.Exists (output), "output");
127 Assert.IsTrue (output.StartsWith (temp), "output-path");
128 Assert.IsTrue (File.Exists (error), "error");
129 Assert.IsTrue (error.StartsWith (temp), "error-path");
130 Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
134 public void ExecWaitWithCapture_CurrentDir ()
137 Assert.Ignore ("ping command not found.");
139 string output = null;
141 TempFileCollection tfc = new TempFileCollection ();
142 Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (cmd, cd, tfc, ref output, ref error), "ErrorCode");
143 Assert.IsTrue (File.Exists (output), "output");
144 Assert.IsTrue (output.StartsWith (temp), "output-path");
145 Assert.IsTrue (File.Exists (error), "error");
146 Assert.IsTrue (error.StartsWith (temp), "error-path");
147 // output/error file are relative to temp path
148 Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
152 public void ExecWaitWithCapture_Token ()
155 Assert.Ignore ("ping command not found.");
157 string output = null;
159 TempFileCollection tfc = new TempFileCollection ();
160 Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (token, cmd, tfc, ref output, ref error), "ErrorCode");
161 Assert.IsTrue (File.Exists (output), "output");
162 Assert.IsTrue (output.StartsWith (temp), "output-path");
163 Assert.IsTrue (File.Exists (error), "error");
164 Assert.IsTrue (error.StartsWith (temp), "error-path");
165 Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
169 public void ExecWaitWithCapture_Token_CurrentDir ()
172 Assert.Ignore ("ping command not found.");
174 string output = null;
176 TempFileCollection tfc = new TempFileCollection ();
177 Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (token, cmd, cd, tfc, ref output, ref error), "ErrorCode");
178 Assert.IsTrue (File.Exists (output), "output");
179 Assert.IsTrue (output.StartsWith (temp), "output-path");
180 Assert.IsTrue (File.Exists (error), "error");
181 Assert.IsTrue (error.StartsWith (temp), "error-path");
182 // output/error file are relative to temp path
183 Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");