Skip to content

Commit d041175

Browse files
committed
test cleanup
1 parent 15fe5bd commit d041175

File tree

1 file changed

+118
-59
lines changed

1 file changed

+118
-59
lines changed

test/git_dir_test.dart

Lines changed: 118 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ void main() {
2222
final gitDir = await _createTempGitDir();
2323

2424
await _doDescriptorGitCommit(
25-
gitDir, initialMasterBranchContent, 'master files');
25+
gitDir,
26+
initialMasterBranchContent,
27+
'master files',
28+
);
2629

2730
// get the treeSha for the new lib directory
2831
final branch = await gitDir.currentBranch();
@@ -31,7 +34,10 @@ void main() {
3134

3235
// sha for the new commit
3336
final newSha = await gitDir.createOrUpdateBranch(
34-
'test', commit.treeSha, 'copy of master');
37+
'test',
38+
commit.treeSha,
39+
'copy of master',
40+
);
3541

3642
// validate there is one commit on 'test'
3743
// validate that the one commit has the right treeSha
@@ -45,34 +51,33 @@ void main() {
4551

4652
// do another update from the subtree sha
4753
final nextCommit = await gitDir.createOrUpdateBranch(
48-
'test', libTreeEntry.sha, 'just the lib content');
54+
'test',
55+
libTreeEntry.sha,
56+
'just the lib content',
57+
);
4958

5059
final testCommitCount = await gitDir.commitCount('test');
5160
expect(testCommitCount, 2);
5261

5362
treeItems = await gitDir.lsTree(nextCommit);
5463
expect(treeItems, hasLength(2));
5564

56-
expect(treeItems.map((tree) => tree.name),
57-
unorderedEquals(['foo.txt', 'bar.txt']));
65+
expect(
66+
treeItems.map((tree) => tree.name),
67+
unorderedEquals(['foo.txt', 'bar.txt']),
68+
);
5869
});
5970

6071
group('init', () {
6172
test('allowContent:false with content fails', () async {
62-
final value = _createTempDir();
73+
File(p.join(d.sandbox, 'testfile.txt')).writeAsStringSync('test content');
6374

64-
File(p.join(value.path, 'testfile.txt'))
65-
.writeAsStringSync('test content');
66-
67-
expect(GitDir.init(value.path), throwsArgumentError);
75+
expect(GitDir.init(d.sandbox), throwsArgumentError);
6876
});
6977

7078
group('existing git dir', () {
71-
String dir;
72-
7379
setUp(() async {
74-
final value = await _createTempGitDir();
75-
dir = value.path;
80+
await _createTempGitDir();
7681
});
7782

7883
test('isWorkingTreeClean', () async {
@@ -87,16 +92,23 @@ void main() {
8792
});
8893

8994
test('fails for sub directories', () async {
90-
expect(() => GitDir.fromExisting(p.join(d.sandbox, 'sub')),
91-
throwsArgumentError);
95+
expect(
96+
() => GitDir.fromExisting(p.join(d.sandbox, 'sub')),
97+
throwsArgumentError,
98+
);
9299
});
93100

94101
test('succeeds for sub directories with `allowSubdirectory`', () async {
95-
final gitDir = await GitDir.fromExisting(p.join(d.sandbox, 'sub'),
96-
allowSubdirectory: true);
97-
98-
expect(gitDir.path, d.sandbox,
99-
reason: 'The created `GitDir` will point to the root.');
102+
final gitDir = await GitDir.fromExisting(
103+
p.join(d.sandbox, 'sub'),
104+
allowSubdirectory: true,
105+
);
106+
107+
expect(
108+
gitDir.path,
109+
d.sandbox,
110+
reason: 'The created `GitDir` will point to the root.',
111+
);
100112
});
101113
});
102114

@@ -106,11 +118,11 @@ void main() {
106118
});
107119

108120
test('with allowContent:false fails', () {
109-
expect(GitDir.init(dir), throwsArgumentError);
121+
expect(GitDir.init(d.sandbox), throwsArgumentError);
110122
});
111123

112124
test('with allowContent:true fails', () {
113-
expect(GitDir.init(dir, allowContent: true), throwsArgumentError);
125+
expect(GitDir.init(d.sandbox, allowContent: true), throwsArgumentError);
114126
});
115127
});
116128
});
@@ -137,12 +149,16 @@ void main() {
137149
expect(hashes.keys, unorderedEquals(paths));
138150

139151
expect(paths[0], endsWith('file1.txt'));
140-
expect(hashes,
141-
containsPair(paths[0], 'dd954e7a4e1a62ff90c5a0709dce5928716535c1'));
152+
expect(
153+
hashes,
154+
containsPair(paths[0], 'dd954e7a4e1a62ff90c5a0709dce5928716535c1'),
155+
);
142156

143157
expect(paths[1], endsWith('file2.txt'));
144-
expect(hashes,
145-
containsPair(paths[1], 'db00fd65b218578127ea51f3dffac701f12f486a'));
158+
expect(
159+
hashes,
160+
containsPair(paths[1], 'db00fd65b218578127ea51f3dffac701f12f486a'),
161+
);
146162
});
147163
}
148164

@@ -197,25 +213,33 @@ Future _testGetCommits() async {
197213
}
198214
}
199215

200-
expect(commitMessageIndex, isNotNull,
201-
reason: 'a matching message should be found');
216+
expect(
217+
commitMessageIndex,
218+
isNotNull,
219+
reason: 'a matching message should be found',
220+
);
202221

203222
expect(indexMap, isNot(contains(commitMessageIndex)));
204223
indexMap[commitMessageIndex] = Tuple(commitSha, commit);
205224
});
206225

207226
indexMap.forEach((index, shaCommitTuple) {
208227
if (index > 0) {
209-
expect(shaCommitTuple.item2.parents,
210-
unorderedEquals([indexMap[index - 1].item1]));
228+
expect(
229+
shaCommitTuple.item2.parents,
230+
unorderedEquals([indexMap[index - 1].item1]),
231+
);
211232
} else {
212233
expect(shaCommitTuple.item2.parents, hasLength(0));
213234
}
214235
});
215236
}
216237

217238
Future _doDescriptorGitCommit(
218-
GitDir gd, Map<String, String> contents, String commitMsg) async {
239+
GitDir gd,
240+
Map<String, String> contents,
241+
String commitMsg,
242+
) async {
219243
await _doDescriptorPopulate(gd.path, contents);
220244

221245
// now add this new file
@@ -272,16 +296,32 @@ Future _testPopulateBranch() async {
272296
_testPopulateBranchEmpty(gd1, testBranchName);
273297

274298
await _testPopulateBranchWithContent(
275-
gd1, testBranchName, testContent1, 'first commit!');
299+
gd1,
300+
testBranchName,
301+
testContent1,
302+
'first commit!',
303+
);
276304

277305
await _testPopulateBranchWithContent(
278-
gd1, testBranchName, testContent2, 'second commit');
306+
gd1,
307+
testBranchName,
308+
testContent2,
309+
'second commit',
310+
);
279311

280312
await _testPopulateBranchWithDupeContent(
281-
gd1, testBranchName, testContent2, 'same content');
313+
gd1,
314+
testBranchName,
315+
testContent2,
316+
'same content',
317+
);
282318

283319
await _testPopulateBranchWithContent(
284-
gd1, testBranchName, testContent1, '3rd commit, content 1');
320+
gd1,
321+
testBranchName,
322+
testContent1,
323+
'3rd commit, content 1',
324+
);
285325

286326
_testPopulateBranchEmpty(gd1, testBranchName);
287327
}
@@ -313,13 +353,17 @@ Future<Tuple<Commit, int>> _testPopulateBranchCore(
313353

314354
Directory tempDir;
315355
try {
316-
final commit = await gitDir.updateBranch(branchName, (td) {
317-
// strictly speaking, users of this API should not hold on to the TempDir
318-
// but this is for testing
319-
tempDir = td;
320-
321-
return _doDescriptorPopulate(tempDir.path, contents);
322-
}, commitMessage);
356+
final commit = await gitDir.updateBranch(
357+
branchName,
358+
(td) {
359+
// strictly speaking, users of this API should not hold on to TempDir
360+
// but this is for testing
361+
tempDir = td;
362+
363+
return _doDescriptorPopulate(tempDir.path, contents);
364+
},
365+
commitMessage,
366+
);
323367

324368
return Tuple(commit, originalCommitCount);
325369
} finally {
@@ -333,14 +377,21 @@ Future _testPopulateBranchWithContent(GitDir gitDir, String branchName,
333377
Map<String, String> contents, String commitMessage) async {
334378
// figure out how many commits exist for the provided branch
335379
final pair = await _testPopulateBranchCore(
336-
gitDir, branchName, contents, commitMessage);
380+
gitDir,
381+
branchName,
382+
contents,
383+
commitMessage,
384+
);
337385

338386
final returnedCommit = pair.item1;
339387
final originalCommitCount = pair.item2;
340388

341389
if (originalCommitCount == 0) {
342-
expect(returnedCommit.parents, isEmpty,
343-
reason: 'This should be the first commit');
390+
expect(
391+
returnedCommit.parents,
392+
isEmpty,
393+
reason: 'This should be the first commit',
394+
);
344395
} else {
345396
expect(returnedCommit.parents, hasLength(1));
346397
}
@@ -354,8 +405,11 @@ Future _testPopulateBranchWithContent(GitDir gitDir, String branchName,
354405

355406
final commit = await gitDir.commitFromRevision(branchRef.reference);
356407

357-
expect(commit.content, returnedCommit.content,
358-
reason: 'content of queried commit should what was returned');
408+
expect(
409+
commit.content,
410+
returnedCommit.content,
411+
reason: 'content of queried commit should what was returned',
412+
);
359413

360414
final entries = await gitDir.lsTree(commit.treeSha);
361415

@@ -369,14 +423,21 @@ Future _testPopulateBranchWithDupeContent(GitDir gitDir, String branchName,
369423
Map<String, String> contents, String commitMessage) async {
370424
// figure out how many commits exist for the provided branch
371425
final pair = await _testPopulateBranchCore(
372-
gitDir, branchName, contents, commitMessage);
426+
gitDir,
427+
branchName,
428+
contents,
429+
commitMessage,
430+
);
373431

374432
final returnedCommit = pair.item1;
375433
final originalCommitCount = pair.item2;
376434

377435
expect(returnedCommit, isNull);
378-
expect(originalCommitCount, greaterThan(0),
379-
reason: 'must have had some original content');
436+
expect(
437+
originalCommitCount,
438+
greaterThan(0),
439+
reason: 'must have had some original content',
440+
);
380441

381442
// new check to see if things are updated it gd1
382443
final br = await gitDir.branchReference(branchName);
@@ -385,13 +446,11 @@ Future _testPopulateBranchWithDupeContent(GitDir gitDir, String branchName,
385446

386447
final newCommitCount = await gitDir.commitCount(br.reference);
387448

388-
expect(newCommitCount, originalCommitCount,
389-
reason: 'no change in commit count');
449+
expect(
450+
newCommitCount,
451+
originalCommitCount,
452+
reason: 'no change in commit count',
453+
);
390454
}
391455

392-
Directory _createTempDir() => Directory(d.sandbox);
393-
394-
Future<GitDir> _createTempGitDir() async {
395-
final dir = _createTempDir();
396-
return GitDir.init(dir.path);
397-
}
456+
Future<GitDir> _createTempGitDir() => GitDir.init(d.sandbox);

0 commit comments

Comments
 (0)