Skip to content

Commit b4ec78e

Browse files
authored
test: setUp tempDirectory (#880)
1 parent 8d78e61 commit b4ec78e

File tree

1 file changed

+4
-84
lines changed

1 file changed

+4
-84
lines changed

test/src/commands/packages/commands/check/commands/licenses_test.dart

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ void main() {
4040
const allowedArgument = '--allowed';
4141

4242
late Progress progress;
43+
late Directory tempDirectory;
4344

4445
setUpAll(() {
4546
registerFallbackValue('');
4647
});
4748

4849
setUp(() {
4950
progress = _MockProgress();
51+
52+
tempDirectory = Directory.systemTemp.createTempSync();
53+
addTearDown(() => tempDirectory.deleteSync(recursive: true));
5054
});
5155

5256
test(
@@ -103,9 +107,6 @@ void main() {
103107
'''when there is a single hosted direct dependency and license''',
104108
withRunner(
105109
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
106-
final tempDirectory = Directory.systemTemp.createTempSync();
107-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
108-
109110
File(path.join(tempDirectory.path, pubspecLockBasename))
110111
.writeAsStringSync(_validPubspecLockContent);
111112

@@ -134,9 +135,6 @@ void main() {
134135
'''when there are multiple hosted direct dependency and licenses''',
135136
withRunner(
136137
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
137-
final tempDirectory = Directory.systemTemp.createTempSync();
138-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
139-
140138
File(path.join(tempDirectory.path, pubspecLockBasename))
141139
.writeAsStringSync(_validMultiplePubspecLockContent);
142140

@@ -173,9 +171,6 @@ void main() {
173171
'''when both allowed and forbidden are specified but left empty''',
174172
withRunner(
175173
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
176-
final tempDirectory = Directory.systemTemp.createTempSync();
177-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
178-
179174
File(path.join(tempDirectory.path, pubspecLockBasename))
180175
.writeAsStringSync(_validPubspecLockContent);
181176

@@ -217,9 +212,6 @@ void main() {
217212
'when a PubLicenseException is thrown',
218213
withRunner(
219214
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
220-
final tempDirectory = Directory.systemTemp.createTempSync();
221-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
222-
223215
File(path.join(tempDirectory.path, pubspecLockBasename))
224216
.writeAsStringSync(_validMultiplePubspecLockContent);
225217

@@ -266,9 +258,6 @@ void main() {
266258
'when an unknown error is thrown',
267259
withRunner(
268260
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
269-
final tempDirectory = Directory.systemTemp.createTempSync();
270-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
271-
272261
File(path.join(tempDirectory.path, pubspecLockBasename))
273262
.writeAsStringSync(_validMultiplePubspecLockContent);
274263

@@ -316,9 +305,6 @@ void main() {
316305
'when all licenses fail to be retrieved',
317306
withRunner(
318307
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
319-
final tempDirectory = Directory.systemTemp.createTempSync();
320-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
321-
322308
File(path.join(tempDirectory.path, pubspecLockBasename))
323309
.writeAsStringSync(_validMultiplePubspecLockContent);
324310

@@ -418,9 +404,6 @@ void main() {
418404
pubLicense,
419405
printLogs,
420406
) async {
421-
final tempDirectory = Directory.systemTemp.createTempSync();
422-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
423-
424407
File(path.join(tempDirectory.path, pubspecLockBasename))
425408
.writeAsStringSync(_validPubspecLockContent);
426409

@@ -464,9 +447,6 @@ void main() {
464447
pubLicense,
465448
printLogs,
466449
) async {
467-
final tempDirectory = Directory.systemTemp.createTempSync();
468-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
469-
470450
File(path.join(tempDirectory.path, pubspecLockBasename))
471451
.writeAsStringSync(_validPubspecLockContent);
472452

@@ -516,9 +496,6 @@ void main() {
516496
pubLicense,
517497
printLogs,
518498
) async {
519-
final tempDirectory = Directory.systemTemp.createTempSync();
520-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
521-
522499
File(path.join(tempDirectory.path, pubspecLockBasename))
523500
.writeAsStringSync(_validPubspecLockContent);
524501

@@ -567,9 +544,6 @@ void main() {
567544
pubLicense,
568545
printLogs,
569546
) async {
570-
final tempDirectory = Directory.systemTemp.createTempSync();
571-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
572-
573547
File(path.join(tempDirectory.path, pubspecLockBasename))
574548
.writeAsStringSync(_validPubspecLockContent);
575549

@@ -618,9 +592,6 @@ void main() {
618592
pubLicense,
619593
printLogs,
620594
) async {
621-
final tempDirectory = Directory.systemTemp.createTempSync();
622-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
623-
624595
File(path.join(tempDirectory.path, pubspecLockBasename))
625596
.writeAsStringSync(_validPubspecLockContent);
626597

@@ -682,9 +653,6 @@ void main() {
682653
'warns when a license is not recognized',
683654
withRunner(
684655
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
685-
final tempDirectory = Directory.systemTemp.createTempSync();
686-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
687-
688656
File(path.join(tempDirectory.path, pubspecLockBasename))
689657
.writeAsStringSync(_validPubspecLockContent);
690658

@@ -716,9 +684,6 @@ void main() {
716684
'exits when a license is not allowed',
717685
withRunner(
718686
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
719-
final tempDirectory = Directory.systemTemp.createTempSync();
720-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
721-
722687
File(path.join(tempDirectory.path, pubspecLockBasename))
723688
.writeAsStringSync(_validPubspecLockContent);
724689

@@ -745,9 +710,6 @@ void main() {
745710
'when a single license is not allowed',
746711
withRunner(
747712
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
748-
final tempDirectory = Directory.systemTemp.createTempSync();
749-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
750-
751713
File(path.join(tempDirectory.path, pubspecLockBasename))
752714
.writeAsStringSync(_validMultiplePubspecLockContent);
753715

@@ -787,9 +749,6 @@ void main() {
787749
'when a single license is not allowed and forbidden is left empty',
788750
withRunner(
789751
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
790-
final tempDirectory = Directory.systemTemp.createTempSync();
791-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
792-
793752
File(path.join(tempDirectory.path, pubspecLockBasename))
794753
.writeAsStringSync(_validMultiplePubspecLockContent);
795754

@@ -831,9 +790,6 @@ void main() {
831790
'when multiple licenses are not allowed',
832791
withRunner(
833792
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
834-
final tempDirectory = Directory.systemTemp.createTempSync();
835-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
836-
837793
File(path.join(tempDirectory.path, pubspecLockBasename))
838794
.writeAsStringSync(_validMultiplePubspecLockContent);
839795

@@ -880,9 +836,6 @@ void main() {
880836
'warns when a license is not recognized',
881837
withRunner(
882838
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
883-
final tempDirectory = Directory.systemTemp.createTempSync();
884-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
885-
886839
File(path.join(tempDirectory.path, pubspecLockBasename))
887840
.writeAsStringSync(_validPubspecLockContent);
888841

@@ -914,9 +867,6 @@ void main() {
914867
'exits when a license is forbidden',
915868
withRunner(
916869
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
917-
final tempDirectory = Directory.systemTemp.createTempSync();
918-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
919-
920870
File(path.join(tempDirectory.path, pubspecLockBasename))
921871
.writeAsStringSync(_validPubspecLockContent);
922872

@@ -943,9 +893,6 @@ void main() {
943893
'when a single license is forbidden',
944894
withRunner(
945895
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
946-
final tempDirectory = Directory.systemTemp.createTempSync();
947-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
948-
949896
File(path.join(tempDirectory.path, pubspecLockBasename))
950897
.writeAsStringSync(_validMultiplePubspecLockContent);
951898

@@ -985,9 +932,6 @@ void main() {
985932
'when a single license is forbidden and allowed is left empty',
986933
withRunner(
987934
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
988-
final tempDirectory = Directory.systemTemp.createTempSync();
989-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
990-
991935
File(path.join(tempDirectory.path, pubspecLockBasename))
992936
.writeAsStringSync(_validMultiplePubspecLockContent);
993937

@@ -1029,9 +973,6 @@ void main() {
1029973
'when multiple licenses are forbidden',
1030974
withRunner(
1031975
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
1032-
final tempDirectory = Directory.systemTemp.createTempSync();
1033-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
1034-
1035976
File(path.join(tempDirectory.path, pubspecLockBasename))
1036977
.writeAsStringSync(_validMultiplePubspecLockContent);
1037978

@@ -1083,9 +1024,6 @@ void main() {
10831024
'a single package by name',
10841025
withRunner(
10851026
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
1086-
final tempDirectory = Directory.systemTemp.createTempSync();
1087-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
1088-
10891027
File(path.join(tempDirectory.path, pubspecLockBasename))
10901028
.writeAsStringSync(_validMultiplePubspecLockContent);
10911029

@@ -1118,9 +1056,6 @@ void main() {
11181056
'multiple packages by name',
11191057
withRunner(
11201058
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
1121-
final tempDirectory = Directory.systemTemp.createTempSync();
1122-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
1123-
11241059
File(path.join(tempDirectory.path, pubspecLockBasename))
11251060
.writeAsStringSync(_validMultiplePubspecLockContent);
11261061

@@ -1154,9 +1089,6 @@ void main() {
11541089
'when it did not find a pubspec.lock file at the target path',
11551090
withRunner(
11561091
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
1157-
final tempDirectory = Directory.systemTemp.createTempSync();
1158-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
1159-
11601092
when(() => logger.progress(any())).thenReturn(progress);
11611093

11621094
final result = await commandRunner.run(
@@ -1177,9 +1109,6 @@ void main() {
11771109
'when it failed to parse a pubspec.lock file at the target path',
11781110
withRunner(
11791111
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
1180-
final tempDirectory = Directory.systemTemp.createTempSync();
1181-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
1182-
11831112
File(path.join(tempDirectory.path, pubspecLockBasename))
11841113
.writeAsStringSync('');
11851114

@@ -1203,9 +1132,6 @@ void main() {
12031132
'when no dependencies of type are found',
12041133
withRunner(
12051134
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
1206-
final tempDirectory = Directory.systemTemp.createTempSync();
1207-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
1208-
12091135
File(path.join(tempDirectory.path, pubspecLockBasename))
12101136
.writeAsStringSync(_emptyPubspecLockContent);
12111137

@@ -1229,9 +1155,6 @@ void main() {
12291155
'when PubLicense throws a PubLicenseException',
12301156
withRunner(
12311157
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
1232-
final tempDirectory = Directory.systemTemp.createTempSync();
1233-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
1234-
12351158
File(path.join(tempDirectory.path, pubspecLockBasename))
12361159
.writeAsStringSync(_validPubspecLockContent);
12371160

@@ -1263,9 +1186,6 @@ void main() {
12631186
'when PubLicense throws an unknown error',
12641187
withRunner(
12651188
(commandRunner, logger, pubUpdater, pubLicense, printLogs) async {
1266-
final tempDirectory = Directory.systemTemp.createTempSync();
1267-
addTearDown(() => tempDirectory.deleteSync(recursive: true));
1268-
12691189
File(path.join(tempDirectory.path, pubspecLockBasename))
12701190
.writeAsStringSync(_validPubspecLockContent);
12711191

0 commit comments

Comments
 (0)