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
|
using System;
using System.Globalization;
using System.IO;
using NUnit.Framework;
using NAnt.Core;
using NAnt.Core.Tasks;
using Tests.NAnt.Core;
namespace Tests.NAnt.SourceControl.Tasks {
[TestFixture]
public class CvsTaskTest : BuildTestBase {
private string destination;
private readonly string MODULE = "sharpcvslib";
private readonly string OVERRIDE_DIR = "sharpcvslib-new";
private readonly string CHECK_FILE = "SharpCvsLib.sln";
private readonly string CVSROOT =
":pserver:anonymous@goliath.sporadicism.com:/cvsroot/sharpcvslib";
private readonly string CHECKOUT = @"<?xml version='1.0'?>
<project>
<cvs command='{0}'
cvsroot='{1}'
module='{2}'
destination='{3}'
usesharpcvslib='{4}' />
</project>";
private readonly string CHECKOUT_WITH_COMMAND_OPTIONS = @"<?xml version='1.0'?>
<project>
<cvs command='{0}'
cvsroot='{1}'
module='{2}'
destination='{3}'
usesharpcvslib='{4}'>
<commandoptions>
<option name='-d' value='{5}' />
<option name='-r' value='{6}' />
</commandoptions>
</cvs>
</project>";
private readonly string GENERIC_COMMANDLINE = @"<?xml version='1.0'?>
<project>
<cvs command='{0}'
cvsroot='{1}'
module='{2}'
destination='{3}'
usesharpcvslib='{4}' />
</project>";
#region Override implementation of BuildTestBase
/// <summary>
/// Run the checkout command so we have something to update.
/// </summary>
[SetUp]
protected override void SetUp () {
base.SetUp ();
}
/// <summary>
/// Remove the directory created by the checkout/ update.
/// </summary>
[TearDown]
protected override void TearDown () {
base.TearDown();
}
#endregion Override implementation of BuildTestBase
/// <summary>
/// Test that the checkout command executes successfully.
/// </summary>
[Test]
[Category("InetAccess")]
public void TestCheckout () {
this.destination = this.TempDirName;
string checkoutPath = Path.Combine(this.destination, this.MODULE);
string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE);
object[] args = {"co", CVSROOT, MODULE, this.destination, true};
this.RunBuild(FormatBuildFile(CHECKOUT, args), Level.Info);
Assert.IsTrue(File.Exists(checkFilePath), "The check file should not be there.");
}
/// <summary>
/// Test that the checkout command executes successfully with non-sharpcvslib binary.
/// </summary>
[Test]
[Category("InetAccess")]
public void TestCheckout_NotSharpcvslib () {
this.destination = this.TempDirName;
string checkoutPath = Path.Combine(this.destination, this.MODULE);
string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE);
object[] args = {"co", CVSROOT, MODULE, this.destination, false};
this.RunBuild(FormatBuildFile(CHECKOUT, args), Level.Info);
Assert.IsTrue(File.Exists(checkFilePath), "The check file should not be there.");
}
/// <summary>
/// Test that the checkout command executes successfully with non-sharpcvslib binary.
/// </summary>
[Test]
[Category("InetAccess")]
public void TestCheckout_CommandOptions_NoSharpCvsLib () {
this.destination = this.TempDirName;
string checkoutPath = Path.Combine(this.destination, this.OVERRIDE_DIR);
string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE);
object[] args = {"co", CVSROOT, MODULE, this.destination, false, this.OVERRIDE_DIR, "HEAD"};
this.RunBuild(FormatBuildFile(CHECKOUT_WITH_COMMAND_OPTIONS, args), Level.Info);
Assert.IsTrue(File.Exists(checkFilePath), "The check file should not be there.");
}
/// <summary>
/// Test that the checkout command executes successfully with non-sharpcvslib binary.
/// </summary>
// TODO: Get this unit test working
/* public void TestCheckout_CommandOptions_SharpCvsLib () {
this.destination = this.TempDirName;
string checkoutPath = Path.Combine(this.destination, this.OVERRIDE_DIR);
string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE);
object[] args = {"co", CVSROOT, MODULE, this.destination, true, this.OVERRIDE_DIR, "HEAD"};
string result =
this.RunBuild(FormatBuildFile(CHECKOUT_WITH_COMMAND_OPTIONS, args), Level.Debug);
System.Console.WriteLine(result);
Assertion.Assert("The check file should not be there.",
File.Exists(checkFilePath));
}
*/
[Test]
[Category("InetAccess")]
public void TestCheckout_CommandLine_Sharpcvslib () {
this.destination = this.TempDirName;
string checkoutPath = Path.Combine(this.destination, this.OVERRIDE_DIR);
string checkFilePath = Path.Combine(checkoutPath, this.CHECK_FILE);
object[] checkoutArgs = {"co", CVSROOT, MODULE, this.destination, true};
string resultCheckout =
this.RunBuild(FormatBuildFile(GENERIC_COMMANDLINE, checkoutArgs), Level.Info);
System.Console.WriteLine(resultCheckout);
Directory.Delete(Path.Combine(this.destination, "build"));
object[] updateArgs = {"update -dP", CVSROOT, MODULE, this.destination, true};
this.RunBuild(FormatBuildFile(GENERIC_COMMANDLINE, updateArgs), Level.Info);
Assert.IsTrue(File.Exists(checkFilePath), "The check file should not be there.");
}
/// <summary>
/// Test that the time necessary to perform a checkout with both binaries
/// is equal.
/// </summary>
[Test]
[Category("InetAccess")]
public void TestTimeCheckout () {
long sharpCvsLibTime = DoCheckout(true);
long cvsPathTime = DoCheckout(false);
Assert.IsTrue(sharpCvsLibTime < cvsPathTime, "Sharpcvslib time: "
+ sharpCvsLibTime + "; time for the cvs executable in the path"
+ " variable: " + cvsPathTime);
}
#region Private Instance Methods
private string FormatBuildFile(string baseFile, object[] args) {
return string.Format(CultureInfo.InvariantCulture, baseFile, args);
}
private long DoCheckout (bool useSharpCvsLib) {
DateTime start = DateTime.Now;
this.destination = this.TempDirName;
object[] checkoutArgs = {"co", CVSROOT, MODULE, this.destination, useSharpCvsLib};
string resultCheckout =
this.RunBuild(FormatBuildFile(GENERIC_COMMANDLINE, checkoutArgs), Level.Info);
System.Console.WriteLine(resultCheckout);
DateTime end = DateTime.Now;
// cleanup for next checkout test
Directory.Delete(Path.Combine(this.destination, MODULE), true);
return end.Subtract(start).Ticks;
}
#endregion Private Instance Methods
}
}
|