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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
|
// PackagingTests.cs
//
// Author:
// Lluis Sanchez Gual <lluis@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.Diagnostics;
using System.IO;
using NUnit.Framework;
using UnitTests;
using MonoDevelop.Core;
using MonoDevelop.Projects;
using MonoDevelop.Deployment.Targets;
using MonoDevelop.Autotools;
namespace MonoDevelop.Deployment
{
[TestFixture]
[Ignore ("Most of these tests fail and no-one is maintaining this addin at the moment")]
public class PackagingTests: TestBase
{
string tarDir = null;
int packId = 0;
#region Binaries package
[Test]
public void ConsoleProjectBins ()
{
string[] binFiles = new string[] {
"ConsoleProject.exe",
"ConsoleProject.exe.mdb",
"consoleproject"
};
RunTestBinariesPackage ("console-project/ConsoleProject.sln", binFiles);
}
[Test]
public void ConsoleProjectWithLibsMdpBins ()
{
string[] binFiles = new string[] {
"console-with-libs-mdp.exe",
"console-with-libs-mdp.exe.mdb",
"console-with-libs-mdp",
"library1.dll",
"library1.dll.mdb",
"library1.pc",
"library2.dll",
"library2.pc",
"library2.dll.mdb"
};
RunTestBinariesPackage ("console-with-libs-mdp/console-with-libs-mdp.mds", binFiles);
}
#endregion
#region Sources package
[Test]
public void ConsoleProjectSources ()
{
RunTestSourcesPackage ("console-project/ConsoleProject.sln");
}
[Test]
public void ConsoleProjectWithLibsMdpSources ()
{
RunTestSourcesPackage ("console-with-libs-mdp/console-with-libs-mdp.mds");
}
[Test]
public void NestedSolutionsMdpSources ()
{
RunTestSourcesPackage ("nested-solutions-mdp/nested-solutions-mdp.mds");
}
#endregion
#region Tarball package
// Console project
string[] filesConsoleProjectTarball = new string[] {
"bin/consoleproject",
"lib/consoleproject/ConsoleProject.exe",
"lib/consoleproject/ConsoleProject.exe.mdb"
};
[Test]
public void ConsoleProjectTarball ()
{
RunTestTarballPackage ("console-project/ConsoleProject.sln", false, "Debug", filesConsoleProjectTarball);
}
[Test]
public void ConsoleProjectTarballAutotools ()
{
RunTestTarballPackage ("console-project/ConsoleProject.sln", true, "Debug", filesConsoleProjectTarball);
}
// ConsoleProjectWithLibsMdpTarball
string[] filesConsoleProjectWithLibsMdpTarball = new string[] {
"bin/console-with-libs-mdp",
"lib/console-with-libs-mdp/console-with-libs-mdp.exe",
"lib/console-with-libs-mdp/console-with-libs-mdp.exe.mdb",
"lib/console-with-libs-mdp/library1.dll",
"lib/console-with-libs-mdp/library1.dll.mdb",
"lib/console-with-libs-mdp/library2.dll",
"lib/console-with-libs-mdp/library2.dll.mdb",
"lib/pkgconfig/library1.pc",
"lib/pkgconfig/library2.pc"
};
[Test]
public void ConsoleProjectWithLibsMdpTarball ()
{
RunTestTarballPackage ("console-with-libs-mdp/console-with-libs-mdp.mds", false, "Debug", filesConsoleProjectWithLibsMdpTarball);
}
[Test]
public void ConsoleProjectWithLibsMdpTarballAutotools ()
{
RunTestTarballPackage ("console-with-libs-mdp/console-with-libs-mdp.mds", true, "Debug", filesConsoleProjectWithLibsMdpTarball);
}
string[] filesNestedSolutionsMdpTarball = new string[] {
"bin/console-project",
"bin/console-project2",
"lib/nested-solutions-mdp/console-project.exe",
"lib/nested-solutions-mdp/console-project.exe.mdb",
"lib/nested-solutions-mdp/console-project2.exe",
"lib/nested-solutions-mdp/console-project2.exe.mdb",
"lib/nested-solutions-mdp/library1.dll",
"lib/nested-solutions-mdp/library1.dll.mdb",
"lib/nested-solutions-mdp/library2.dll",
"lib/nested-solutions-mdp/library2.dll.mdb",
"lib/nested-solutions-mdp/library3.dll",
"lib/nested-solutions-mdp/library3.dll.mdb",
"lib/nested-solutions-mdp/library4.dll",
"lib/nested-solutions-mdp/library4.dll.mdb",
"lib/pkgconfig/library1.pc",
"lib/pkgconfig/library2.pc",
"lib/pkgconfig/library3.pc",
"lib/pkgconfig/library4.pc",
};
[Test]
public void NestedSolutionsMdpTarball ()
{
RunTestTarballPackage ("nested-solutions-mdp/nested-solutions-mdp.mds", false, "Debug", filesNestedSolutionsMdpTarball);
}
[Test]
public void NestedSolutionsMdpTarballAutotools ()
{
RunTestTarballPackage ("nested-solutions-mdp/nested-solutions-mdp.mds", true, "Debug", filesNestedSolutionsMdpTarball);
}
#endregion
#region Support methods
void RunTestBinariesPackage (string solFile, string[] expectedFiles)
{
solFile = Util.GetSampleProject (solFile);
Solution sol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor(), solFile);
BinariesZipPackageBuilder pb = new BinariesZipPackageBuilder ();
pb.SetSolutionItem (sol.RootFolder, sol.GetAllSolutionItems<SolutionItem> ());
pb.TargetFile = GetTempTarFile ("binzip");
pb.Platform = "Linux";
pb.Configuration = "Debug";
if (!DeployService.BuildPackage (Util.GetMonitor (), pb))
Assert.Fail ("Package generation failed");
CheckTarContents (pb.TargetFile, expectedFiles, true);
}
void RunTestSourcesPackage (string solFile)
{
solFile = Util.GetSampleProject (solFile);
Solution sol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor(), solFile);
SourcesZipPackageBuilder pb = new SourcesZipPackageBuilder ();
pb.FileFormat = sol.FileFormat;
pb.SetSolutionItem (sol.RootFolder, sol.GetAllSolutionItems<SolutionItem> ());
pb.TargetFile = GetTempTarFile ("sourceszip");
if (!DeployService.BuildPackage (Util.GetMonitor (), pb))
Assert.Fail ("Package generation failed");
List<string> files = new List<string> ();
foreach (string f in sol.GetItemFiles (true)) {
files.Add (sol.GetRelativeChildPath (f));
}
CheckTarContents (pb.TargetFile, files.ToArray (), true);
}
void RunTestTarballPackage (string solFile, bool autotools, string config, string[] expectedFiles)
{
solFile = Util.GetSampleProject (solFile);
Solution sol = (Solution) Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor(), solFile);
TarballDeployTarget pb = new TarballDeployTarget ();
pb.SetSolutionItem (sol.RootFolder, sol.GetAllSolutionItems<SolutionItem> ());
pb.TargetDir = Util.CreateTmpDir ("tarball-target-dir");
pb.DefaultConfiguration = config;
pb.GenerateFiles = true;
pb.GenerateAutotools = autotools;
if (!DeployService.BuildPackage (Util.GetMonitor (), pb))
Assert.Fail ("Package generation failed");
string tarfile = Directory.GetFiles (pb.TargetDir) [0];
Untar (tarfile, null);
string[] dirs = Directory.GetDirectories (pb.TargetDir);
Assert.AreEqual (1, dirs.Length);
string tarDir = dirs [0];
string prefix = Path.Combine (pb.TargetDir, "install");
if (!Exec (Path.Combine (tarDir, "configure"), "--prefix=" + prefix, tarDir))
Assert.Fail ("Configure script failed");
if (!Exec ("make", "all", tarDir))
Assert.Fail ("Build failed");
if (!Exec ("make", "install", tarDir))
Assert.Fail ("Install failed");
CheckDirContents (prefix, expectedFiles);
}
string GetTempTarFile (string hint)
{
if (tarDir == null)
tarDir = Util.CreateTmpDir ("packages");
return Path.Combine (tarDir, hint + "-" + (packId++) + ".tar.gz");
}
void CheckTarContents (string file, string[] expectedFiles, bool checkInSubdir)
{
Assert.IsTrue (File.Exists (file), "tar file not found");
string dir = Util.CreateTmpDir ("tar-contents");
Untar (file, dir);
if (checkInSubdir) {
string[] dirs = Directory.GetDirectories (dir);
Assert.IsTrue (dirs.Length == 1, "No unique subdir found in tar");
Assert.IsTrue (Directory.GetFiles(dir).Length == 0, "No unique subdir found in tar");
dir = Path.Combine (dir, dirs[0]);
}
CheckDirContents (dir, expectedFiles);
}
void CheckDirContents (string dir, string[] expectedFiles)
{
List<string> validFiles = new List<string> ();
foreach (string f in expectedFiles) {
string tf = Path.Combine (dir, f);
Assert.IsTrue (File.Exists (tf), "Content check: file not found: " + Path.GetFullPath (tf));
validFiles.Add (Path.GetFullPath (tf));
}
CheckValidFiles (dir, validFiles);
}
void CheckValidFiles (string dir, List<string> validFiles)
{
foreach (string f in Directory.GetFiles (dir))
Assert.IsFalse (!validFiles.Contains (Path.GetFullPath(f)), "Content check: extra file: " + Path.GetFullPath(f));
foreach (string d in Directory.GetDirectories (dir))
CheckValidFiles (d, validFiles);
}
void Untar (string file, string dir)
{
if (dir == null)
dir = Path.GetDirectoryName (file);
Exec ("tar", "xvfz " + file + " -C " + dir, null);
}
bool Exec (string file, string args, string workDir)
{
Process proc = new Process ();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.FileName = file;
proc.StartInfo.Arguments = args;
if (workDir != null)
proc.StartInfo.WorkingDirectory = workDir;
proc.Start ();
string sout = proc.StandardOutput.ReadToEnd ();
sout += proc.StandardError.ReadToEnd ();
proc.WaitForExit ();
if (proc.ExitCode == 0)
return true;
else {
Console.WriteLine (sout);
return false;
}
}
}
#endregion
}
|