Skip to content

Commit

Permalink
Sandbox every test
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Jan 4, 2015
1 parent 7e57858 commit 27fbde6
Show file tree
Hide file tree
Showing 40 changed files with 569 additions and 312 deletions.
9 changes: 6 additions & 3 deletions LibGit2Sharp.Tests/ArchiveFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class ArchiveFixture : BaseFixture
[Fact]
public void CanArchiveATree()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var tree = repo.Lookup<Tree>("581f9824ecaf824221bd36edf5430f2739a7c4f5");

Expand All @@ -36,7 +37,8 @@ public void CanArchiveATree()
[Fact]
public void CanArchiveACommit()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var commit = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");

Expand All @@ -61,7 +63,8 @@ public void CanArchiveACommit()
[Fact]
public void ArchivingANullTreeOrCommitThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<ArgumentNullException>(() => repo.ObjectDatabase.Archive((Commit)null, null));
Assert.Throws<ArgumentNullException>(() => repo.ObjectDatabase.Archive((Tree)null, null));
Expand Down
15 changes: 10 additions & 5 deletions LibGit2Sharp.Tests/BlameFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ private static void AssertCorrectHeadBlame(BlameHunkCollection blame)
[Fact]
public void CanBlameSimply()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
AssertCorrectHeadBlame(repo.Blame("README"));
}
Expand All @@ -31,7 +32,8 @@ public void CanBlameSimply()
[Fact]
public void CanBlameFromADifferentCommit()
{
using (var repo = new Repository(MergedTestRepoWorkingDirPath))
string path = SandboxMergedTestRepo();
using (var repo = new Repository(path))
{
// File doesn't exist at HEAD
Assert.Throws<LibGit2SharpException>(() => repo.Blame("ancestor-only.txt"));
Expand All @@ -44,7 +46,8 @@ public void CanBlameFromADifferentCommit()
[Fact]
public void ValidatesLimits()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var blame = repo.Blame("README");

Expand All @@ -56,7 +59,8 @@ public void ValidatesLimits()
[Fact]
public void CanBlameFromVariousTypes()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = "HEAD" }));
AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = repo.Head }));
Expand All @@ -68,7 +72,8 @@ public void CanBlameFromVariousTypes()
[Fact]
public void CanStopBlame()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
// $ git blame .\new.txt
// 9fd738e8 (Scott Chacon 2010-05-24 10:19:19 -0700 1) my new file
Expand Down
15 changes: 10 additions & 5 deletions LibGit2Sharp.Tests/BlobFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public class BlobFixture : BaseFixture
[Fact]
public void CanGetBlobAsText()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");

Expand Down Expand Up @@ -86,7 +87,8 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
[Fact]
public void CanGetBlobSize()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
Assert.Equal(10, blob.Size);
Expand All @@ -96,7 +98,8 @@ public void CanGetBlobSize()
[Fact]
public void CanLookUpBlob()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
Assert.NotNull(blob);
Expand All @@ -106,7 +109,8 @@ public void CanLookUpBlob()
[Fact]
public void CanReadBlobStream()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");

Expand Down Expand Up @@ -208,7 +212,8 @@ public void CanStageAFileGeneratedFromABlobContentStream()
[Fact]
public void CanTellIfTheBlobContentLooksLikeBinary()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
Assert.Equal(false, blob.IsBinary);
Expand Down
78 changes: 52 additions & 26 deletions LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ public void CreatingABranchTriggersTheCreationOfADirectReference()
[Fact]
public void CreatingABranchFromANonCommitObjectThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
const string name = "sorry-dude-i-do-not-do-blobs-nor-trees";
Assert.Throws<InvalidSpecificationException>(() => repo.CreateBranch(name, "refs/tags/point_to_blob"));
Expand All @@ -250,7 +251,8 @@ public void CreatingABranchFromANonCommitObjectThrows()
[Fact]
public void CreatingBranchWithUnknownNamedTargetThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", "my_old_branch"));
}
Expand All @@ -259,7 +261,8 @@ public void CreatingBranchWithUnknownNamedTargetThrows()
[Fact]
public void CreatingBranchWithUnknownShaTargetThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", Constants.UnknownSha));
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", Constants.UnknownSha.Substring(0, 7)));
Expand All @@ -269,7 +272,8 @@ public void CreatingBranchWithUnknownShaTargetThrows()
[Fact]
public void CreatingBranchWithBadParamsThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<ArgumentNullException>(() => repo.Branches.Add(null, repo.Head.CanonicalName));
Assert.Throws<ArgumentException>(() => repo.Branches.Add(string.Empty, repo.Head.CanonicalName));
Expand All @@ -282,7 +286,8 @@ public void CreatingBranchWithBadParamsThrows()
[Fact]
public void CanListAllBranches()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Equal(expectedBranches, SortedBranches(repo.Branches, b => b.Name));

Expand Down Expand Up @@ -312,7 +317,8 @@ public void CanListBranchesWithRemoteAndLocalBranchWithSameShortName()
[Fact]
public void CanListAllBranchesWhenGivenWorkingDir()
{
using (var repo = new Repository(StandardTestRepoWorkingDirPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var expectedWdBranches = new[]
{
Expand All @@ -328,7 +334,8 @@ public void CanListAllBranchesWhenGivenWorkingDir()
[Fact]
public void CanListAllBranchesIncludingRemoteRefs()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var expectedBranchesIncludingRemoteRefs = new[]
{
Expand All @@ -352,7 +359,8 @@ public void CanListAllBranchesIncludingRemoteRefs()
[Fact]
public void CanResolveRemote()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Branch master = repo.Branches["master"];
Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
Expand All @@ -362,7 +370,8 @@ public void CanResolveRemote()
[Fact]
public void RemoteAndUpstreamBranchCanonicalNameForNonTrackingBranchIsNull()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Branch test = repo.Branches["i-do-numbers"];
Assert.Null(test.Remote);
Expand All @@ -374,7 +383,8 @@ public void RemoteAndUpstreamBranchCanonicalNameForNonTrackingBranchIsNull()
public void QueryRemoteForLocalTrackingBranch()
{
// There is not a Remote to resolve for a local tracking branch.
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Branch trackLocal = repo.Branches["track-local"];
Assert.Null(trackLocal.Remote);
Expand All @@ -384,7 +394,8 @@ public void QueryRemoteForLocalTrackingBranch()
[Fact]
public void QueryUpstreamBranchCanonicalNameForLocalTrackingBranch()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Branch trackLocal = repo.Branches["track-local"];
Assert.Equal("refs/heads/master", trackLocal.UpstreamBranchCanonicalName);
Expand All @@ -394,7 +405,8 @@ public void QueryUpstreamBranchCanonicalNameForLocalTrackingBranch()
[Fact]
public void QueryRemoteForRemoteBranch()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var master = repo.Branches["origin/master"];
Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
Expand Down Expand Up @@ -452,7 +464,8 @@ public void QueryAmbigousRemoteForRemoteBranch()
[Fact]
public void CanLookupABranchByItsCanonicalName()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Branch branch = repo.Branches["refs/heads/br2"];
Assert.NotNull(branch);
Expand All @@ -470,7 +483,8 @@ public void CanLookupABranchByItsCanonicalName()
[Fact]
public void CanLookupLocalBranch()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Branch master = repo.Branches["master"];
Assert.NotNull(master);
Expand Down Expand Up @@ -501,7 +515,8 @@ public void CanLookupABranchWhichNameIsMadeOfNon7BitsAsciiCharacters()
[Fact]
public void LookingOutABranchByNameWithBadParamsThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Branch branch;
Assert.Throws<ArgumentNullException>(() => branch = repo.Branches[null]);
Expand Down Expand Up @@ -587,7 +602,8 @@ public void TrackingInformationIsEmptyForBranchTrackingPrunedRemoteBranch()
[Fact]
public void TrackingInformationIsEmptyForNonTrackingBranch()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Branch branch = repo.Branches["test"];
Assert.False(branch.IsTracking);
Expand All @@ -603,7 +619,8 @@ public void TrackingInformationIsEmptyForNonTrackingBranch()
[Fact]
public void CanGetTrackingInformationForTrackingBranch()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Branch master = repo.Branches["master"];
Assert.True(master.IsTracking);
Expand All @@ -619,7 +636,8 @@ public void CanGetTrackingInformationForTrackingBranch()
[Fact]
public void CanGetTrackingInformationForLocalTrackingBranch()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var branch = repo.Branches["track-local"];
Assert.True(branch.IsTracking);
Expand All @@ -635,7 +653,8 @@ public void CanGetTrackingInformationForLocalTrackingBranch()
[Fact]
public void RenamingARemoteTrackingBranchThrows()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Branch master = repo.Branches["refs/remotes/origin/master"];
Assert.True(master.IsRemote);
Expand All @@ -647,7 +666,8 @@ public void RenamingARemoteTrackingBranchThrows()
[Fact]
public void CanWalkCommitsFromAnotherBranch()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Branch master = repo.Branches["test"];
Assert.Equal(2, master.Commits.Count());
Expand Down Expand Up @@ -813,7 +833,8 @@ public void CanUnsetTrackedBranch()
[Fact]
public void CanWalkCommitsFromBranch()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Branch master = repo.Branches["master"];
Assert.Equal(7, master.Commits.Count());
Expand Down Expand Up @@ -871,7 +892,8 @@ public void CanRemoveANonExistingBranch(string branchName, bool isRemote)
[Fact]
public void RemovingABranchWhichIsTheCurrentHeadThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Remove(repo.Head.Name));
}
Expand All @@ -880,7 +902,8 @@ public void RemovingABranchWhichIsTheCurrentHeadThrows()
[Fact]
public void RemovingABranchWithBadParamsThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<ArgumentException>(() => repo.Branches.Remove(string.Empty));
Assert.Throws<ArgumentNullException>(() => repo.Branches.Remove(null));
Expand All @@ -890,7 +913,8 @@ public void RemovingABranchWithBadParamsThrows()
[Fact]
public void OnlyOneBranchIsTheHead()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Branch head = null;

Expand Down Expand Up @@ -957,7 +981,8 @@ public void CanRenameABranch()
[Fact]
public void BlindlyRenamingABranchOverAnExistingOneThrows()
{
using (var repo = new Repository(BareTestRepoPath))
string path = SandboxBareTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<NameConflictException>(() => repo.Branches.Rename("br2", "test"));
}
Expand Down Expand Up @@ -1068,7 +1093,8 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone()
[Fact]
public void RemoteBranchesDoNotTrackAnything()
{
using (var repo = new Repository(StandardTestRepoPath))
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
var branches = repo.Branches.Where(b => b.IsRemote);

Expand Down
Loading

0 comments on commit 27fbde6

Please sign in to comment.