Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LocalCopyTests.cs « MonoDevelop.Projects « UnitTests « tests « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cb113fa442a64963a4e216773e1746898130c9c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// 
// LocalCopyTests.cs
// 
// Author:
//   Michael Hutchinson <mhutchinson@novell.com>
// 
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using UnitTests;
using MonoDevelop.Core;
using System.Linq;
using MonoDevelop.Core.ProgressMonitoring;

namespace MonoDevelop.Projects
{
	
	[TestFixture]
	public class LocalCopyTests : TestBase
	{
		[Test]
		[Platform (Exclude = "Win")]
		public void CheckLocalCopy ()
		{
			string solFile = Util.GetSampleProject ("vs-local-copy", "VSLocalCopyTest.sln");
			
			WorkspaceItem item = Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
			Assert.IsTrue (item is Solution);
			Solution sol = (Solution) item;
			
			AssertCleanBuild (sol, "Debug");
			AssertCleanBuild (sol, "Release");

			string dllDebug = Platform.IsWindows ? ".pdb" : ".dll.mdb";
			string exeDebug = Platform.IsWindows ? ".pdb" : ".exe.mdb";
			
			AssertOutputFiles (sol, "VSLocalCopyTest", "Debug", new string[] {
				"ClassLibrary1.dll",
				"ClassLibrary1" + dllDebug,
				"ClassLibrary2.dll",
				"ClassLibrary2" + dllDebug,
				"ClassLibrary4.dll",
				"ClassLibrary4" + dllDebug,
				"VSLocalCopyTest.exe",
				"VSLocalCopyTest" + exeDebug,
				"TextFile1.txt",
				"TextFile2.txt",
				"app.config",
				"folder/baz.txt",
				"foo/bar.txt",
				"quux.txt",
				"VSLocalCopyTest.exe.config",
			});
			
			//FIXME: all of these should have mdb files in release mode.
			//See [Bug 431451] MD ignores DebugType pdbonly
			AssertOutputFiles (sol, "VSLocalCopyTest", "Release", new string[] {
				"ClassLibrary1.dll",
				"ClassLibrary2.dll",
				"ClassLibrary4.dll",
				"VSLocalCopyTest.exe",
				"TextFile1.txt",
				"TextFile2.txt",
				"app.config",
				"folder/baz.txt",
				"foo/bar.txt",
				"quux.txt",
				"VSLocalCopyTest.exe.config",
			});
			
			AssertOutputFiles (sol, "ClassLibrary1", "Debug", new string[] {
				"ClassLibrary1.dll",
				"ClassLibrary1" + dllDebug,
				"ClassLibrary2.dll",
				"ClassLibrary2" + dllDebug,
				"TextFile1.txt",
				"TextFile2.txt",
				"foo/bar.txt",
			});
			
			AssertOutputFiles (sol, "ClassLibrary1", "Release", new string[] {
				"ClassLibrary1.dll",
				"ClassLibrary2.dll",
				"TextFile1.txt",
				"TextFile2.txt",
				"foo/bar.txt",
			});
			
			AssertOutputFiles (sol, "ClassLibrary2", "Debug", new string[] {
				"ClassLibrary2.dll",
				"ClassLibrary2" + dllDebug,
				"TextFile2.txt"
			});
			
			AssertOutputFiles (sol, "ClassLibrary2", "Release", new string[] {
				"ClassLibrary2.dll",
				"TextFile2.txt"
			});
			
			AssertOutputFiles (sol, "ClassLibrary3", "Debug", new string[] {
				"ClassLibrary3.dll",
				"ClassLibrary3" + dllDebug
			});
			
			AssertOutputFiles (sol, "ClassLibrary3", "Release", new string[] {
				"ClassLibrary3.dll"
			});
			
			AssertOutputFiles (sol, "ClassLibrary4", "Debug", new string[] {
				"ClassLibrary4.dll",
				"ClassLibrary4" + dllDebug
			});
			
			AssertOutputFiles (sol, "ClassLibrary4", "Release", new string[] {
				"ClassLibrary4.dll"
			});
			
			AssertOutputFiles (sol, "ClassLibrary5", "Debug", new string[] {
				"ClassLibrary5.dll",
				"ClassLibrary5" + dllDebug,
			});
			
			AssertOutputFiles (sol, "ClassLibrary5", "Release", new string[] {
				"ClassLibrary5.dll"
			});
		}
				
		static void AssertOutputFiles (Solution solution, string projectName, string configuration, string[] expectedFiles)
		{
			foreach (Project proj in solution.GetAllProjects ()) {
				if (proj.Name == projectName) {
					AssertOutputFiles (proj, configuration, expectedFiles);
					return;
				}
			}
			Assert.Fail ("Did not find project '{0}'", projectName);
		}
		
		static void AssertOutputFiles (Project project, string configuration, string[] expectedFiles)
		{
			string directory = Path.GetDirectoryName (project.GetOutputFileName ((SolutionConfigurationSelector)configuration));
			Assert.IsFalse (string.IsNullOrEmpty (directory), "Project '{0} has no output directory", project);
			List<string> files = new List<string> (Directory.GetFiles (directory, "*", SearchOption.AllDirectories));
			
			for (int i = 0; i < files.Count; i++)
				files[i] = files[i].Substring (directory.Length + 1);
			
			foreach (string expectedFile in expectedFiles)
				Assert.IsTrue (files.Remove (expectedFile), "Did not find file '{0}' in '{1}'",
				               expectedFile, directory);
			
			Assert.IsTrue (files.Count == 0, "There are unexpected files in the directory {0}: {1}", directory, Join (files));
		}
		
		static string Join (List<string> list)
		{
			if (list.Count < 1)
				return String.Empty;
			string [] arr = new string [list.Count + list.Count - 1];
			string comma = ", ";
			for (int i = 0; i < arr.Length; i++)
				arr[i] = (i % 2 == 0)? list [i / 2] : comma;
			return String.Concat (arr);
		}
		
		static void AssertCleanBuild (Solution sol, string configuration)
		{
			BuildResult cr = sol.Build (Util.GetMonitor (), configuration);
			Assert.IsNotNull (cr);
			Assert.AreEqual (0, cr.ErrorCount);

			// Warning check disabled due to bug #15121
			// Assert.AreEqual (0, cr.WarningCount); 
		}

		[Test]
		[Ignore ("Check for build warnings disabled due to a bug in xbuild (BXC 15121)")]
		public void CheckLocalCopyBuildWarnings ()
		{
			// See commented assert in AssertCleanBuild
		}

		[Test]
		[Platform (Exclude = "Win")]
		public void LocalCopyDefault ()
		{
			string solFile = Util.GetSampleProject ("local-copy-package", "ConsoleProject.sln");

			WorkspaceItem item = Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile);
			Solution sol = (Solution) item;
			var p = (DotNetProject)sol.Items [0];

			var ar = p.References.First (r => r.Reference.Contains ("gtk"));
			Assert.AreEqual (false, ar.LocalCopy);
			ar.LocalCopy = true;
			Assert.AreEqual (true, ar.LocalCopy);

			ar = p.References.First (r => r.Reference.Contains ("System.Data"));
			Assert.AreEqual (false, ar.LocalCopy);
			ar.LocalCopy = true;
			Assert.AreEqual (true, ar.LocalCopy);

			ar = p.References.First (r => r.Reference.Contains ("LibProject"));
			Assert.AreEqual (true, ar.LocalCopy);
			ar.LocalCopy = false;
			Assert.AreEqual (false, ar.LocalCopy);

			ar = p.References.First (r => r.Reference.Contains ("Xwt"));
			Assert.AreEqual (true, ar.LocalCopy);
			ar.LocalCopy = false;
			Assert.AreEqual (false, ar.LocalCopy);

			sol.Save (new NullProgressMonitor ());
			sol.Build (new NullProgressMonitor (), "Debug");

			string exeDebug = Platform.IsWindows ? ".pdb" : ".exe.mdb";

			AssertOutputFiles (sol, "ConsoleProject", "Debug", new string[] {
				"ConsoleProject.exe",
				"ConsoleProject" + exeDebug,
				"System.Data.dll",
				"gtk-sharp.dll"
			});

			string projectXml1 = Util.GetXmlFileInfoset (p.FileName.ParentDirectory.Combine ("ConsoleProject.csproj.saved"));
			string projectXml2 = Util.GetXmlFileInfoset (p.FileName);
			Assert.AreEqual (projectXml1, projectXml2);
		}
	}
}