|
5 | 5 | @TestOn('vm')
|
6 | 6 | library;
|
7 | 7 |
|
| 8 | +import 'dart:io'; |
| 9 | + |
8 | 10 | import 'package:io/io.dart';
|
9 | 11 | import 'package:path/path.dart' as p;
|
10 | 12 | import 'package:test/test.dart';
|
@@ -33,6 +35,82 @@ void main() {
|
33 | 35 | throwsArgumentError,
|
34 | 36 | );
|
35 | 37 | });
|
| 38 | + |
| 39 | + group('links', () { |
| 40 | + const linkTarget = 'link_target'; |
| 41 | + const linkSource = 'link_source'; |
| 42 | + const linkContent = 'link_content.txt'; |
| 43 | + late String targetPath; |
| 44 | + setUp(() async { |
| 45 | + await _create(); |
| 46 | + await d |
| 47 | + .dir(linkTarget, [d.file(linkContent, 'original content')]).create(); |
| 48 | + targetPath = p.join(d.sandbox, linkTarget); |
| 49 | + await Link(p.join(d.sandbox, _parentDir, linkSource)).create(targetPath); |
| 50 | + }); |
| 51 | + |
| 52 | + test('are shallow copied with deepCopyLinks: false in copyPath', () async { |
| 53 | + await copyPath( |
| 54 | + deepCopyLinks: false, |
| 55 | + p.join(d.sandbox, _parentDir), |
| 56 | + p.join(d.sandbox, _copyDir)); |
| 57 | + |
| 58 | + final expectedLink = Link(p.join(d.sandbox, _copyDir, linkSource)); |
| 59 | + expect(await expectedLink.exists(), isTrue); |
| 60 | + expect(await expectedLink.target(), targetPath); |
| 61 | + }); |
| 62 | + |
| 63 | + test('are shallow copied with deepCopyLinks: false in copyPathSync', |
| 64 | + () async { |
| 65 | + copyPathSync( |
| 66 | + deepCopyLinks: false, |
| 67 | + p.join(d.sandbox, _parentDir), |
| 68 | + p.join(d.sandbox, _copyDir)); |
| 69 | + |
| 70 | + final expectedLink = Link(p.join(d.sandbox, _copyDir, linkSource)); |
| 71 | + expect(await expectedLink.exists(), isTrue); |
| 72 | + expect(await expectedLink.target(), targetPath); |
| 73 | + }); |
| 74 | + |
| 75 | + test('are deep copied by default in copyPath', () async { |
| 76 | + await copyPath( |
| 77 | + p.join(d.sandbox, _parentDir), p.join(d.sandbox, _copyDir)); |
| 78 | + |
| 79 | + final expectedDir = Directory(p.join(d.sandbox, _copyDir, linkSource)); |
| 80 | + final expectedFile = |
| 81 | + File(p.join(d.sandbox, _copyDir, linkSource, linkContent)); |
| 82 | + expect(await expectedDir.exists(), isTrue); |
| 83 | + expect(await expectedFile.exists(), isTrue); |
| 84 | + |
| 85 | + expect(await expectedFile.readAsString(), 'original content', |
| 86 | + reason: 'The file behind the link was copied with invalid content'); |
| 87 | + |
| 88 | + await expectedFile.writeAsString('new content'); |
| 89 | + final originalFile = |
| 90 | + File(p.join(d.sandbox, _parentDir, linkSource, linkContent)); |
| 91 | + expect(await originalFile.readAsString(), 'original content', |
| 92 | + reason: 'The file behind the link should not change'); |
| 93 | + }); |
| 94 | + |
| 95 | + test('are deep copied by default in copyPathSync', () async { |
| 96 | + copyPathSync(p.join(d.sandbox, _parentDir), p.join(d.sandbox, _copyDir)); |
| 97 | + |
| 98 | + final expectedDir = Directory(p.join(d.sandbox, _copyDir, linkSource)); |
| 99 | + final expectedFile = |
| 100 | + File(p.join(d.sandbox, _copyDir, linkSource, linkContent)); |
| 101 | + expect(await expectedDir.exists(), isTrue); |
| 102 | + expect(await expectedFile.exists(), isTrue); |
| 103 | + |
| 104 | + expect(await expectedFile.readAsString(), 'original content', |
| 105 | + reason: 'The file behind the link was copied with invalid content'); |
| 106 | + |
| 107 | + await expectedFile.writeAsString('new content'); |
| 108 | + final originalFile = |
| 109 | + File(p.join(d.sandbox, _parentDir, linkSource, linkContent)); |
| 110 | + expect(await originalFile.readAsString(), 'original content', |
| 111 | + reason: 'The file behind the link should not change'); |
| 112 | + }); |
| 113 | + }); |
36 | 114 | }
|
37 | 115 |
|
38 | 116 | const _parentDir = 'parent';
|
|
0 commit comments