Skip to content

Commit f0f5a46

Browse files
committed
Merge pull request #968 from libgit2/no-more-check-function
No more check function
2 parents f8f6f4e + e0a3814 commit f0f5a46

File tree

6 files changed

+201
-252
lines changed

6 files changed

+201
-252
lines changed

LibGit2Sharp.Tests/FilterFixture.cs

Lines changed: 7 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using System.Linq;
54
using LibGit2Sharp.Tests.TestHelpers;
65
using Xunit;
76

@@ -11,12 +10,10 @@ public class FilterFixture : BaseFixture
1110
{
1211
private const int GitPassThrough = -30;
1312

14-
readonly Func<FilterSource, IEnumerable<string>, int> checkPassThrough = (source, attr) => GitPassThrough;
1513
readonly Func<Stream, Stream, int> successCallback = (reader, writer) => 0;
16-
readonly Func<FilterSource, IEnumerable<string>, int> checkSuccess = (source, attr) => 0;
1714

1815
private const string FilterName = "the-filter";
19-
readonly List<string> attributes = new List<string>{"test"};
16+
readonly List<FilterAttribute> attributes = new List<FilterAttribute> { new FilterAttribute("test") };
2017

2118
[Fact]
2219
public void CanRegisterFilterWithSingleAttribute()
@@ -55,101 +52,6 @@ public void SameFilterIsEqual()
5552
Assert.Equal(filter, filter);
5653
}
5754

58-
[Fact]
59-
public void CheckCallbackNotMadeWhenFileStagedAndFilterNotRegistered()
60-
{
61-
bool called = false;
62-
Func<FilterSource, IEnumerable<string>, int> callback = (source, attr) =>
63-
{
64-
called = true;
65-
return GitPassThrough;
66-
};
67-
68-
string repoPath = InitNewRepository();
69-
70-
new FakeFilter(FilterName + 4, attributes, callback);
71-
72-
using (var repo = CreateTestRepository(repoPath))
73-
{
74-
StageNewFile(repo);
75-
}
76-
77-
Assert.False(called);
78-
}
79-
80-
[Fact]
81-
public void CheckCallbackMadeWhenFileStaged()
82-
{
83-
bool called = false;
84-
Func<FilterSource, IEnumerable<string>, int> checkCallBack = (source, attr) =>
85-
{
86-
called = true;
87-
return GitPassThrough;
88-
};
89-
string repoPath = InitNewRepository();
90-
91-
var filter = new FakeFilter(FilterName + 5, attributes, checkCallBack);
92-
93-
var filterRegistration = GlobalSettings.RegisterFilter(filter);
94-
using (var repo = CreateTestRepository(repoPath))
95-
{
96-
StageNewFile(repo);
97-
Assert.True(called);
98-
}
99-
100-
GlobalSettings.DeregisterFilter(filterRegistration);
101-
}
102-
103-
[Fact]
104-
public void ApplyCallbackMadeWhenCheckCallbackReturnsZero()
105-
{
106-
bool called = false;
107-
108-
Func<Stream, Stream, int> applyCallback = (reader, writer) =>
109-
{
110-
called = true;
111-
return 0; //successCallback
112-
};
113-
114-
string repoPath = InitNewRepository();
115-
var filter = new FakeFilter(FilterName + 6, attributes, checkSuccess, applyCallback);
116-
117-
var filterRegistration = GlobalSettings.RegisterFilter(filter);
118-
using (var repo = CreateTestRepository(repoPath))
119-
{
120-
StageNewFile(repo);
121-
}
122-
123-
GlobalSettings.DeregisterFilter(filterRegistration);
124-
125-
Assert.True(called);
126-
}
127-
128-
[Fact]
129-
public void ApplyCallbackNotMadeWhenCheckCallbackReturnsPassThrough()
130-
{
131-
bool called = false;
132-
133-
Func<Stream, Stream, int> applyCallback = (reader, writer) =>
134-
{
135-
called = true;
136-
return 0;
137-
};
138-
139-
string repoPath = InitNewRepository();
140-
var filter = new FakeFilter(FilterName + 7, attributes, checkPassThrough, applyCallback);
141-
142-
var filterRegistration = GlobalSettings.RegisterFilter(filter);
143-
using (var repo = CreateTestRepository(repoPath))
144-
{
145-
StageNewFile(repo);
146-
}
147-
148-
GlobalSettings.DeregisterFilter(filterRegistration);
149-
150-
Assert.False(called);
151-
}
152-
15355
[Fact]
15456
public void InitCallbackNotMadeWhenFilterNeverUsed()
15557
{
@@ -161,7 +63,6 @@ public void InitCallbackNotMadeWhenFilterNeverUsed()
16163
};
16264

16365
var filter = new FakeFilter(FilterName + 11, attributes,
164-
checkSuccess,
16566
successCallback,
16667
successCallback,
16768
initializeCallback);
@@ -184,7 +85,6 @@ public void InitCallbackMadeWhenUsingTheFilter()
18485
};
18586

18687
var filter = new FakeFilter(FilterName + 12, attributes,
187-
checkSuccess,
18888
successCallback,
18989
successCallback,
19090
initializeCallback);
@@ -202,68 +102,6 @@ public void InitCallbackMadeWhenUsingTheFilter()
202102
GlobalSettings.DeregisterFilter(filterRegistration);
203103
}
204104

205-
[Fact]
206-
public void WhenStagingFileCheckIsCalledWithCleanForCorrectPath()
207-
{
208-
string repoPath = InitNewRepository();
209-
210-
var calledWithMode = FilterMode.Smudge;
211-
string actualPath = string.Empty;
212-
IEnumerable<string> actualAttributes = Enumerable.Empty<string>();
213-
Func<FilterSource, IEnumerable<string>, int> callback = (source, attr) =>
214-
{
215-
calledWithMode = source.SourceMode;
216-
actualPath = source.Path;
217-
actualAttributes = attr;
218-
return GitPassThrough;
219-
};
220-
221-
var filter = new FakeFilter(FilterName + 13, attributes, callback);
222-
223-
var filterRegistration = GlobalSettings.RegisterFilter(filter);
224-
225-
using (var repo = CreateTestRepository(repoPath))
226-
{
227-
FileInfo expectedFile = StageNewFile(repo);
228-
229-
Assert.Equal(FilterMode.Clean, calledWithMode);
230-
Assert.Equal(expectedFile.Name, actualPath);
231-
Assert.Equal(attributes, actualAttributes);
232-
}
233-
234-
GlobalSettings.DeregisterFilter(filterRegistration);
235-
}
236-
237-
238-
[Fact]
239-
public void WhenCheckingOutAFileFileCheckIsCalledWithSmudgeForCorrectPath()
240-
{
241-
const string branchName = "branch";
242-
string repoPath = InitNewRepository();
243-
244-
var calledWithMode = FilterMode.Clean;
245-
string actualPath = string.Empty;
246-
IEnumerable<string> actualAttributes = Enumerable.Empty<string>();
247-
Func<FilterSource, IEnumerable<string>, int> callback = (source, attr) =>
248-
{
249-
calledWithMode = source.SourceMode;
250-
actualPath = source.Path;
251-
actualAttributes = attr;
252-
return GitPassThrough;
253-
};
254-
255-
var filter = new FakeFilter(FilterName + 14, attributes, callback);
256-
257-
var filterRegistration = GlobalSettings.RegisterFilter(filter);
258-
259-
FileInfo expectedFile = CheckoutFileForSmudge(repoPath, branchName, "hello");
260-
Assert.Equal(FilterMode.Smudge, calledWithMode);
261-
Assert.Equal(expectedFile.FullName, actualPath);
262-
Assert.Equal(attributes, actualAttributes);
263-
264-
GlobalSettings.DeregisterFilter(filterRegistration);
265-
}
266-
267105
[Fact]
268106
public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath()
269107
{
@@ -275,7 +113,7 @@ public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath()
275113
called = true;
276114
return GitPassThrough;
277115
};
278-
var filter = new FakeFilter(FilterName + 15, attributes, checkSuccess, clean);
116+
var filter = new FakeFilter(FilterName + 15, attributes, clean);
279117

280118
var filterRegistration = GlobalSettings.RegisterFilter(filter);
281119

@@ -298,7 +136,7 @@ public void CleanFilterWritesOutputToObjectTree()
298136

299137
Func<Stream, Stream, int> cleanCallback = SubstitutionCipherFilter.RotateByThirteenPlaces;
300138

301-
var filter = new FakeFilter(FilterName + 16, attributes, checkSuccess, cleanCallback);
139+
var filter = new FakeFilter(FilterName + 16, attributes, cleanCallback);
302140

303141
var filterRegistration = GlobalSettings.RegisterFilter(filter);
304142

@@ -328,7 +166,7 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
328166

329167
Func<Stream, Stream, int> smudgeCallback = SubstitutionCipherFilter.RotateByThirteenPlaces;
330168

331-
var filter = new FakeFilter(FilterName + 17, attributes, checkSuccess, null, smudgeCallback);
169+
var filter = new FakeFilter(FilterName + 17, attributes, null, smudgeCallback);
332170
var filterRegistration = GlobalSettings.RegisterFilter(filter);
333171

334172
FileInfo expectedFile = CheckoutFileForSmudge(repoPath, branchName, encodedInput);
@@ -361,7 +199,7 @@ public void FilterStreamsAreCoherent()
361199
return GitPassThrough;
362200
};
363201

364-
var filter = new FakeFilter(FilterName + 18, attributes, checkSuccess, assertor, assertor);
202+
var filter = new FakeFilter(FilterName + 18, attributes, assertor, assertor);
365203

366204
var filterRegistration = GlobalSettings.RegisterFilter(filter);
367205

@@ -433,36 +271,28 @@ private Repository CreateTestRepository(string path)
433271

434272
class EmptyFilter : Filter
435273
{
436-
public EmptyFilter(string name, IEnumerable<string> attributes)
274+
public EmptyFilter(string name, IEnumerable<FilterAttribute> attributes)
437275
: base(name, attributes)
438276
{ }
439277
}
440278

441279
class FakeFilter : Filter
442280
{
443-
private readonly Func<FilterSource, IEnumerable<string>, int> checkCallBack;
444281
private readonly Func<Stream, Stream, int> cleanCallback;
445282
private readonly Func<Stream, Stream, int> smudgeCallback;
446283
private readonly Func<int> initCallback;
447284

448-
public FakeFilter(string name, IEnumerable<string> attributes,
449-
Func<FilterSource, IEnumerable<string>, int> checkCallBack = null,
285+
public FakeFilter(string name, IEnumerable<FilterAttribute> attributes,
450286
Func<Stream, Stream, int> cleanCallback = null,
451287
Func<Stream, Stream, int> smudgeCallback = null,
452288
Func<int> initCallback = null)
453289
: base(name, attributes)
454290
{
455-
this.checkCallBack = checkCallBack;
456291
this.cleanCallback = cleanCallback;
457292
this.smudgeCallback = smudgeCallback;
458293
this.initCallback = initCallback;
459294
}
460295

461-
protected override int Check(IEnumerable<string> attributes, FilterSource filterSource)
462-
{
463-
return checkCallBack != null ? checkCallBack(filterSource, attributes) : base.Check(attributes, filterSource);
464-
}
465-
466296
protected override int Clean(string path, Stream input, Stream output)
467297
{
468298
return cleanCallback != null ? cleanCallback(input, output) : base.Clean(path, input, output);

0 commit comments

Comments
 (0)