Skip to content

Commit 27fbde6

Browse files
committed
Sandbox every test
Fix libgit2#826
1 parent 7e57858 commit 27fbde6

40 files changed

+569
-312
lines changed

LibGit2Sharp.Tests/ArchiveFixture.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public class ArchiveFixture : BaseFixture
1111
[Fact]
1212
public void CanArchiveATree()
1313
{
14-
using (var repo = new Repository(BareTestRepoPath))
14+
string path = SandboxBareTestRepo();
15+
using (var repo = new Repository(path))
1516
{
1617
var tree = repo.Lookup<Tree>("581f9824ecaf824221bd36edf5430f2739a7c4f5");
1718

@@ -36,7 +37,8 @@ public void CanArchiveATree()
3637
[Fact]
3738
public void CanArchiveACommit()
3839
{
39-
using (var repo = new Repository(BareTestRepoPath))
40+
string path = SandboxBareTestRepo();
41+
using (var repo = new Repository(path))
4042
{
4143
var commit = repo.Lookup<Commit>("4c062a6361ae6959e06292c1fa5e2822d9c96345");
4244

@@ -61,7 +63,8 @@ public void CanArchiveACommit()
6163
[Fact]
6264
public void ArchivingANullTreeOrCommitThrows()
6365
{
64-
using (var repo = new Repository(BareTestRepoPath))
66+
string path = SandboxBareTestRepo();
67+
using (var repo = new Repository(path))
6568
{
6669
Assert.Throws<ArgumentNullException>(() => repo.ObjectDatabase.Archive((Commit)null, null));
6770
Assert.Throws<ArgumentNullException>(() => repo.ObjectDatabase.Archive((Tree)null, null));

LibGit2Sharp.Tests/BlameFixture.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ private static void AssertCorrectHeadBlame(BlameHunkCollection blame)
2222
[Fact]
2323
public void CanBlameSimply()
2424
{
25-
using (var repo = new Repository(BareTestRepoPath))
25+
string path = SandboxBareTestRepo();
26+
using (var repo = new Repository(path))
2627
{
2728
AssertCorrectHeadBlame(repo.Blame("README"));
2829
}
@@ -31,7 +32,8 @@ public void CanBlameSimply()
3132
[Fact]
3233
public void CanBlameFromADifferentCommit()
3334
{
34-
using (var repo = new Repository(MergedTestRepoWorkingDirPath))
35+
string path = SandboxMergedTestRepo();
36+
using (var repo = new Repository(path))
3537
{
3638
// File doesn't exist at HEAD
3739
Assert.Throws<LibGit2SharpException>(() => repo.Blame("ancestor-only.txt"));
@@ -44,7 +46,8 @@ public void CanBlameFromADifferentCommit()
4446
[Fact]
4547
public void ValidatesLimits()
4648
{
47-
using (var repo = new Repository(BareTestRepoPath))
49+
string path = SandboxBareTestRepo();
50+
using (var repo = new Repository(path))
4851
{
4952
var blame = repo.Blame("README");
5053

@@ -56,7 +59,8 @@ public void ValidatesLimits()
5659
[Fact]
5760
public void CanBlameFromVariousTypes()
5861
{
59-
using (var repo = new Repository(BareTestRepoPath))
62+
string path = SandboxBareTestRepo();
63+
using (var repo = new Repository(path))
6064
{
6165
AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = "HEAD" }));
6266
AssertCorrectHeadBlame(repo.Blame("README", new BlameOptions {StartingAt = repo.Head }));
@@ -68,7 +72,8 @@ public void CanBlameFromVariousTypes()
6872
[Fact]
6973
public void CanStopBlame()
7074
{
71-
using (var repo = new Repository(BareTestRepoPath))
75+
string path = SandboxBareTestRepo();
76+
using (var repo = new Repository(path))
7277
{
7378
// $ git blame .\new.txt
7479
// 9fd738e8 (Scott Chacon 2010-05-24 10:19:19 -0700 1) my new file

LibGit2Sharp.Tests/BlobFixture.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class BlobFixture : BaseFixture
1212
[Fact]
1313
public void CanGetBlobAsText()
1414
{
15-
using (var repo = new Repository(BareTestRepoPath))
15+
string path = SandboxBareTestRepo();
16+
using (var repo = new Repository(path))
1617
{
1718
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
1819

@@ -86,7 +87,8 @@ public void CanGetBlobAsTextWithVariousEncodings(string encodingName, int expect
8687
[Fact]
8788
public void CanGetBlobSize()
8889
{
89-
using (var repo = new Repository(BareTestRepoPath))
90+
string path = SandboxBareTestRepo();
91+
using (var repo = new Repository(path))
9092
{
9193
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
9294
Assert.Equal(10, blob.Size);
@@ -96,7 +98,8 @@ public void CanGetBlobSize()
9698
[Fact]
9799
public void CanLookUpBlob()
98100
{
99-
using (var repo = new Repository(BareTestRepoPath))
101+
string path = SandboxBareTestRepo();
102+
using (var repo = new Repository(path))
100103
{
101104
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
102105
Assert.NotNull(blob);
@@ -106,7 +109,8 @@ public void CanLookUpBlob()
106109
[Fact]
107110
public void CanReadBlobStream()
108111
{
109-
using (var repo = new Repository(BareTestRepoPath))
112+
string path = SandboxBareTestRepo();
113+
using (var repo = new Repository(path))
110114
{
111115
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
112116

@@ -208,7 +212,8 @@ public void CanStageAFileGeneratedFromABlobContentStream()
208212
[Fact]
209213
public void CanTellIfTheBlobContentLooksLikeBinary()
210214
{
211-
using (var repo = new Repository(BareTestRepoPath))
215+
string path = SandboxBareTestRepo();
216+
using (var repo = new Repository(path))
212217
{
213218
var blob = repo.Lookup<Blob>("a8233120f6ad708f843d861ce2b7228ec4e3dec6");
214219
Assert.Equal(false, blob.IsBinary);

LibGit2Sharp.Tests/BranchFixture.cs

+52-26
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ public void CreatingABranchTriggersTheCreationOfADirectReference()
238238
[Fact]
239239
public void CreatingABranchFromANonCommitObjectThrows()
240240
{
241-
using (var repo = new Repository(BareTestRepoPath))
241+
string path = SandboxBareTestRepo();
242+
using (var repo = new Repository(path))
242243
{
243244
const string name = "sorry-dude-i-do-not-do-blobs-nor-trees";
244245
Assert.Throws<InvalidSpecificationException>(() => repo.CreateBranch(name, "refs/tags/point_to_blob"));
@@ -250,7 +251,8 @@ public void CreatingABranchFromANonCommitObjectThrows()
250251
[Fact]
251252
public void CreatingBranchWithUnknownNamedTargetThrows()
252253
{
253-
using (var repo = new Repository(BareTestRepoPath))
254+
string path = SandboxBareTestRepo();
255+
using (var repo = new Repository(path))
254256
{
255257
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", "my_old_branch"));
256258
}
@@ -259,7 +261,8 @@ public void CreatingBranchWithUnknownNamedTargetThrows()
259261
[Fact]
260262
public void CreatingBranchWithUnknownShaTargetThrows()
261263
{
262-
using (var repo = new Repository(BareTestRepoPath))
264+
string path = SandboxBareTestRepo();
265+
using (var repo = new Repository(path))
263266
{
264267
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", Constants.UnknownSha));
265268
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", Constants.UnknownSha.Substring(0, 7)));
@@ -269,7 +272,8 @@ public void CreatingBranchWithUnknownShaTargetThrows()
269272
[Fact]
270273
public void CreatingBranchWithBadParamsThrows()
271274
{
272-
using (var repo = new Repository(BareTestRepoPath))
275+
string path = SandboxBareTestRepo();
276+
using (var repo = new Repository(path))
273277
{
274278
Assert.Throws<ArgumentNullException>(() => repo.Branches.Add(null, repo.Head.CanonicalName));
275279
Assert.Throws<ArgumentException>(() => repo.Branches.Add(string.Empty, repo.Head.CanonicalName));
@@ -282,7 +286,8 @@ public void CreatingBranchWithBadParamsThrows()
282286
[Fact]
283287
public void CanListAllBranches()
284288
{
285-
using (var repo = new Repository(BareTestRepoPath))
289+
string path = SandboxBareTestRepo();
290+
using (var repo = new Repository(path))
286291
{
287292
Assert.Equal(expectedBranches, SortedBranches(repo.Branches, b => b.Name));
288293

@@ -312,7 +317,8 @@ public void CanListBranchesWithRemoteAndLocalBranchWithSameShortName()
312317
[Fact]
313318
public void CanListAllBranchesWhenGivenWorkingDir()
314319
{
315-
using (var repo = new Repository(StandardTestRepoWorkingDirPath))
320+
string path = SandboxStandardTestRepo();
321+
using (var repo = new Repository(path))
316322
{
317323
var expectedWdBranches = new[]
318324
{
@@ -328,7 +334,8 @@ public void CanListAllBranchesWhenGivenWorkingDir()
328334
[Fact]
329335
public void CanListAllBranchesIncludingRemoteRefs()
330336
{
331-
using (var repo = new Repository(StandardTestRepoPath))
337+
string path = SandboxStandardTestRepo();
338+
using (var repo = new Repository(path))
332339
{
333340
var expectedBranchesIncludingRemoteRefs = new[]
334341
{
@@ -352,7 +359,8 @@ public void CanListAllBranchesIncludingRemoteRefs()
352359
[Fact]
353360
public void CanResolveRemote()
354361
{
355-
using (var repo = new Repository(StandardTestRepoPath))
362+
string path = SandboxStandardTestRepo();
363+
using (var repo = new Repository(path))
356364
{
357365
Branch master = repo.Branches["master"];
358366
Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
@@ -362,7 +370,8 @@ public void CanResolveRemote()
362370
[Fact]
363371
public void RemoteAndUpstreamBranchCanonicalNameForNonTrackingBranchIsNull()
364372
{
365-
using (var repo = new Repository(StandardTestRepoPath))
373+
string path = SandboxStandardTestRepo();
374+
using (var repo = new Repository(path))
366375
{
367376
Branch test = repo.Branches["i-do-numbers"];
368377
Assert.Null(test.Remote);
@@ -374,7 +383,8 @@ public void RemoteAndUpstreamBranchCanonicalNameForNonTrackingBranchIsNull()
374383
public void QueryRemoteForLocalTrackingBranch()
375384
{
376385
// There is not a Remote to resolve for a local tracking branch.
377-
using (var repo = new Repository(StandardTestRepoPath))
386+
string path = SandboxStandardTestRepo();
387+
using (var repo = new Repository(path))
378388
{
379389
Branch trackLocal = repo.Branches["track-local"];
380390
Assert.Null(trackLocal.Remote);
@@ -384,7 +394,8 @@ public void QueryRemoteForLocalTrackingBranch()
384394
[Fact]
385395
public void QueryUpstreamBranchCanonicalNameForLocalTrackingBranch()
386396
{
387-
using (var repo = new Repository(StandardTestRepoPath))
397+
string path = SandboxStandardTestRepo();
398+
using (var repo = new Repository(path))
388399
{
389400
Branch trackLocal = repo.Branches["track-local"];
390401
Assert.Equal("refs/heads/master", trackLocal.UpstreamBranchCanonicalName);
@@ -394,7 +405,8 @@ public void QueryUpstreamBranchCanonicalNameForLocalTrackingBranch()
394405
[Fact]
395406
public void QueryRemoteForRemoteBranch()
396407
{
397-
using (var repo = new Repository(StandardTestRepoPath))
408+
string path = SandboxStandardTestRepo();
409+
using (var repo = new Repository(path))
398410
{
399411
var master = repo.Branches["origin/master"];
400412
Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
@@ -452,7 +464,8 @@ public void QueryAmbigousRemoteForRemoteBranch()
452464
[Fact]
453465
public void CanLookupABranchByItsCanonicalName()
454466
{
455-
using (var repo = new Repository(BareTestRepoPath))
467+
string path = SandboxBareTestRepo();
468+
using (var repo = new Repository(path))
456469
{
457470
Branch branch = repo.Branches["refs/heads/br2"];
458471
Assert.NotNull(branch);
@@ -470,7 +483,8 @@ public void CanLookupABranchByItsCanonicalName()
470483
[Fact]
471484
public void CanLookupLocalBranch()
472485
{
473-
using (var repo = new Repository(BareTestRepoPath))
486+
string path = SandboxBareTestRepo();
487+
using (var repo = new Repository(path))
474488
{
475489
Branch master = repo.Branches["master"];
476490
Assert.NotNull(master);
@@ -501,7 +515,8 @@ public void CanLookupABranchWhichNameIsMadeOfNon7BitsAsciiCharacters()
501515
[Fact]
502516
public void LookingOutABranchByNameWithBadParamsThrows()
503517
{
504-
using (var repo = new Repository(BareTestRepoPath))
518+
string path = SandboxBareTestRepo();
519+
using (var repo = new Repository(path))
505520
{
506521
Branch branch;
507522
Assert.Throws<ArgumentNullException>(() => branch = repo.Branches[null]);
@@ -587,7 +602,8 @@ public void TrackingInformationIsEmptyForBranchTrackingPrunedRemoteBranch()
587602
[Fact]
588603
public void TrackingInformationIsEmptyForNonTrackingBranch()
589604
{
590-
using (var repo = new Repository(BareTestRepoPath))
605+
string path = SandboxBareTestRepo();
606+
using (var repo = new Repository(path))
591607
{
592608
Branch branch = repo.Branches["test"];
593609
Assert.False(branch.IsTracking);
@@ -603,7 +619,8 @@ public void TrackingInformationIsEmptyForNonTrackingBranch()
603619
[Fact]
604620
public void CanGetTrackingInformationForTrackingBranch()
605621
{
606-
using (var repo = new Repository(StandardTestRepoPath))
622+
string path = SandboxStandardTestRepo();
623+
using (var repo = new Repository(path))
607624
{
608625
Branch master = repo.Branches["master"];
609626
Assert.True(master.IsTracking);
@@ -619,7 +636,8 @@ public void CanGetTrackingInformationForTrackingBranch()
619636
[Fact]
620637
public void CanGetTrackingInformationForLocalTrackingBranch()
621638
{
622-
using (var repo = new Repository(StandardTestRepoPath))
639+
string path = SandboxStandardTestRepo();
640+
using (var repo = new Repository(path))
623641
{
624642
var branch = repo.Branches["track-local"];
625643
Assert.True(branch.IsTracking);
@@ -635,7 +653,8 @@ public void CanGetTrackingInformationForLocalTrackingBranch()
635653
[Fact]
636654
public void RenamingARemoteTrackingBranchThrows()
637655
{
638-
using (var repo = new Repository(StandardTestRepoPath))
656+
string path = SandboxStandardTestRepo();
657+
using (var repo = new Repository(path))
639658
{
640659
Branch master = repo.Branches["refs/remotes/origin/master"];
641660
Assert.True(master.IsRemote);
@@ -647,7 +666,8 @@ public void RenamingARemoteTrackingBranchThrows()
647666
[Fact]
648667
public void CanWalkCommitsFromAnotherBranch()
649668
{
650-
using (var repo = new Repository(BareTestRepoPath))
669+
string path = SandboxBareTestRepo();
670+
using (var repo = new Repository(path))
651671
{
652672
Branch master = repo.Branches["test"];
653673
Assert.Equal(2, master.Commits.Count());
@@ -813,7 +833,8 @@ public void CanUnsetTrackedBranch()
813833
[Fact]
814834
public void CanWalkCommitsFromBranch()
815835
{
816-
using (var repo = new Repository(BareTestRepoPath))
836+
string path = SandboxBareTestRepo();
837+
using (var repo = new Repository(path))
817838
{
818839
Branch master = repo.Branches["master"];
819840
Assert.Equal(7, master.Commits.Count());
@@ -871,7 +892,8 @@ public void CanRemoveANonExistingBranch(string branchName, bool isRemote)
871892
[Fact]
872893
public void RemovingABranchWhichIsTheCurrentHeadThrows()
873894
{
874-
using (var repo = new Repository(BareTestRepoPath))
895+
string path = SandboxBareTestRepo();
896+
using (var repo = new Repository(path))
875897
{
876898
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Remove(repo.Head.Name));
877899
}
@@ -880,7 +902,8 @@ public void RemovingABranchWhichIsTheCurrentHeadThrows()
880902
[Fact]
881903
public void RemovingABranchWithBadParamsThrows()
882904
{
883-
using (var repo = new Repository(BareTestRepoPath))
905+
string path = SandboxBareTestRepo();
906+
using (var repo = new Repository(path))
884907
{
885908
Assert.Throws<ArgumentException>(() => repo.Branches.Remove(string.Empty));
886909
Assert.Throws<ArgumentNullException>(() => repo.Branches.Remove(null));
@@ -890,7 +913,8 @@ public void RemovingABranchWithBadParamsThrows()
890913
[Fact]
891914
public void OnlyOneBranchIsTheHead()
892915
{
893-
using (var repo = new Repository(BareTestRepoPath))
916+
string path = SandboxBareTestRepo();
917+
using (var repo = new Repository(path))
894918
{
895919
Branch head = null;
896920

@@ -957,7 +981,8 @@ public void CanRenameABranch()
957981
[Fact]
958982
public void BlindlyRenamingABranchOverAnExistingOneThrows()
959983
{
960-
using (var repo = new Repository(BareTestRepoPath))
984+
string path = SandboxBareTestRepo();
985+
using (var repo = new Repository(path))
961986
{
962987
Assert.Throws<NameConflictException>(() => repo.Branches.Rename("br2", "test"));
963988
}
@@ -1068,7 +1093,8 @@ public void TrackedBranchExistsFromDefaultConfigInEmptyClone()
10681093
[Fact]
10691094
public void RemoteBranchesDoNotTrackAnything()
10701095
{
1071-
using (var repo = new Repository(StandardTestRepoPath))
1096+
string path = SandboxStandardTestRepo();
1097+
using (var repo = new Repository(path))
10721098
{
10731099
var branches = repo.Branches.Where(b => b.IsRemote);
10741100

0 commit comments

Comments
 (0)