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 {
48 private TempFileCollection tfc;
49 private WindowsIdentity winid;
53 public void FixtureSetUp ()
55 int platform = (int) Environment.OSVersion.Platform;
56 posix = (platform == 4) || (platform == 128);
57 errcode = (posix ? 2 : 1);
58 cmd = "ping"; // available everywhere
59 cd = Environment.CurrentDirectory;
60 temp = Path.GetTempPath ();
61 tfc = new TempFileCollection ();
62 winid = WindowsIdentity.GetCurrent ();
67 public void FixtureTearDown ()
77 [ExpectedException (typeof (ExternalException))]
78 public void ExecWait_NullCmd ()
80 Executor.ExecWait (null, new TempFileCollection ());
84 [ExpectedException (typeof (NullReferenceException))]
85 public void ExecWait_NullTempFileCollection ()
87 Executor.ExecWait (cmd, null);
91 [ExpectedException (typeof (ExternalException))]
92 [Category ("NotWorking")]
93 public void ExecWait ()
95 // why does it fail ? any case that works ?
96 Executor.ExecWait (cmd, tfc);
100 public void ExecWaitWithCapture ()
102 string output = null;
104 TempFileCollection tfc = new TempFileCollection ();
105 Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (cmd, tfc, ref output, ref error), "ErrorCode");
106 Assert.IsTrue (File.Exists (output), "output");
107 Assert.IsTrue (output.StartsWith (temp), "output-path");
108 Assert.IsTrue (File.Exists (error), "error");
109 Assert.IsTrue (error.StartsWith (temp), "error-path");
110 Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
114 public void ExecWaitWithCapture_CurrentDir ()
116 string output = null;
118 TempFileCollection tfc = new TempFileCollection ();
119 Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (cmd, cd, tfc, ref output, ref error), "ErrorCode");
120 Assert.IsTrue (File.Exists (output), "output");
121 Assert.IsTrue (output.StartsWith (temp), "output-path");
122 Assert.IsTrue (File.Exists (error), "error");
123 Assert.IsTrue (error.StartsWith (temp), "error-path");
124 // output/error file are relative to temp path
125 Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
129 public void ExecWaitWithCapture_Token ()
131 string output = null;
133 TempFileCollection tfc = new TempFileCollection ();
134 Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (token, cmd, tfc, ref output, ref error), "ErrorCode");
135 Assert.IsTrue (File.Exists (output), "output");
136 Assert.IsTrue (output.StartsWith (temp), "output-path");
137 Assert.IsTrue (File.Exists (error), "error");
138 Assert.IsTrue (error.StartsWith (temp), "error-path");
139 Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");
143 public void ExecWaitWithCapture_Token_CurrentDir ()
145 string output = null;
147 TempFileCollection tfc = new TempFileCollection ();
148 Assert.AreEqual (errcode, Executor.ExecWaitWithCapture (token, cmd, cd, tfc, ref output, ref error), "ErrorCode");
149 Assert.IsTrue (File.Exists (output), "output");
150 Assert.IsTrue (output.StartsWith (temp), "output-path");
151 Assert.IsTrue (File.Exists (error), "error");
152 Assert.IsTrue (error.StartsWith (temp), "error-path");
153 // output/error file are relative to temp path
154 Assert.IsTrue (tfc.Count >= 2, "TempFileCollection");