|
| 1 | +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +library lock_file_test; |
| 6 | + |
| 7 | +import 'dart:io'; |
| 8 | + |
| 9 | +import 'package:pathos/path.dart' as path; |
| 10 | +import 'package:scheduled_test/scheduled_test.dart'; |
| 11 | + |
| 12 | +import '../lib/src/entrypoint.dart'; |
| 13 | +import '../lib/src/io.dart'; |
| 14 | +import '../lib/src/system_cache.dart'; |
| 15 | +import 'descriptor.dart' as d; |
| 16 | +import 'test_pub.dart'; |
| 17 | + |
| 18 | +var root; |
| 19 | +var entrypoint; |
| 20 | + |
| 21 | +main() { |
| 22 | + initConfig(); |
| 23 | + |
| 24 | + group('not in a git repo', () { |
| 25 | + setUp(() { |
| 26 | + d.appDir([]).create(); |
| 27 | + scheduleEntrypoint(); |
| 28 | + }); |
| 29 | + |
| 30 | + |
| 31 | + integration('lists files recursively', () { |
| 32 | + d.dir(appPath, [ |
| 33 | + d.file('file1.txt', 'contents'), |
| 34 | + d.file('file2.txt', 'contents'), |
| 35 | + d.dir('subdir', [ |
| 36 | + d.file('subfile1.txt', 'subcontents'), |
| 37 | + d.file('subfile2.txt', 'subcontents') |
| 38 | + ]) |
| 39 | + ]).create(); |
| 40 | + |
| 41 | + schedule(() { |
| 42 | + expect(entrypoint.packageFiles(), completion(unorderedEquals([ |
| 43 | + path.join(root, 'pubspec.yaml'), |
| 44 | + path.join(root, 'file1.txt'), |
| 45 | + path.join(root, 'file2.txt'), |
| 46 | + path.join(root, 'subdir', 'subfile1.txt'), |
| 47 | + path.join(root, 'subdir', 'subfile2.txt') |
| 48 | + ]))); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + commonTests(); |
| 53 | + }); |
| 54 | + |
| 55 | + group('with git', () { |
| 56 | + setUp(() { |
| 57 | + ensureGit(); |
| 58 | + d.git(appPath, [d.appPubspec([])]).create(); |
| 59 | + scheduleEntrypoint(); |
| 60 | + }); |
| 61 | + |
| 62 | + integration("includes files that are or aren't checked in", () { |
| 63 | + d.dir(appPath, [ |
| 64 | + d.file('file1.txt', 'contents'), |
| 65 | + d.file('file2.txt', 'contents'), |
| 66 | + d.dir('subdir', [ |
| 67 | + d.file('subfile1.txt', 'subcontents'), |
| 68 | + d.file('subfile2.txt', 'subcontents') |
| 69 | + ]) |
| 70 | + ]).create(); |
| 71 | + |
| 72 | + schedule(() { |
| 73 | + expect(entrypoint.packageFiles(), completion(unorderedEquals([ |
| 74 | + path.join(root, 'pubspec.yaml'), |
| 75 | + path.join(root, 'file1.txt'), |
| 76 | + path.join(root, 'file2.txt'), |
| 77 | + path.join(root, 'subdir', 'subfile1.txt'), |
| 78 | + path.join(root, 'subdir', 'subfile2.txt') |
| 79 | + ]))); |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + integration("ignores files that are gitignored", () { |
| 84 | + d.dir(appPath, [ |
| 85 | + d.file('.gitignore', '*.txt'), |
| 86 | + d.file('file1.txt', 'contents'), |
| 87 | + d.file('file2.text', 'contents'), |
| 88 | + d.dir('subdir', [ |
| 89 | + d.file('subfile1.txt', 'subcontents'), |
| 90 | + d.file('subfile2.text', 'subcontents') |
| 91 | + ]) |
| 92 | + ]).create(); |
| 93 | + |
| 94 | + schedule(() { |
| 95 | + expect(entrypoint.packageFiles(), completion(unorderedEquals([ |
| 96 | + path.join(root, 'pubspec.yaml'), |
| 97 | + path.join(root, '.gitignore'), |
| 98 | + path.join(root, 'file2.text'), |
| 99 | + path.join(root, 'subdir', 'subfile2.text') |
| 100 | + ]))); |
| 101 | + }); |
| 102 | + }); |
| 103 | + |
| 104 | + commonTests(); |
| 105 | + }); |
| 106 | +} |
| 107 | + |
| 108 | +void scheduleEntrypoint() { |
| 109 | + schedule(() { |
| 110 | + root = path.join(sandboxDir, appPath); |
| 111 | + entrypoint = new Entrypoint(root, new SystemCache.withSources(root)); |
| 112 | + }, 'initializing entrypoint'); |
| 113 | + |
| 114 | + currentSchedule.onComplete.schedule(() { |
| 115 | + entrypoint = null; |
| 116 | + }, 'nulling entrypoint'); |
| 117 | +} |
| 118 | + |
| 119 | +void commonTests() { |
| 120 | + integration('ignores broken symlinks', () { |
| 121 | + // Windows requires us to symlink to a directory that actually exists. |
| 122 | + d.dir(appPath, [d.dir('target')]).create(); |
| 123 | + scheduleSymlink(path.join(appPath, 'target'), path.join(appPath, 'link')); |
| 124 | + schedule(() => deleteEntry(path.join(sandboxDir, appPath, 'target'))); |
| 125 | + |
| 126 | + schedule(() { |
| 127 | + expect(entrypoint.packageFiles(), |
| 128 | + completion(equals([path.join(root, 'pubspec.yaml')]))); |
| 129 | + }); |
| 130 | + }); |
| 131 | + |
| 132 | + integration('ignores pubspec.lock files', () { |
| 133 | + d.dir(appPath, [ |
| 134 | + d.file('pubspec.lock'), |
| 135 | + d.dir('subdir', [d.file('pubspec.lock')]) |
| 136 | + ]).create(); |
| 137 | + |
| 138 | + schedule(() { |
| 139 | + expect(entrypoint.packageFiles(), |
| 140 | + completion(equals([path.join(root, 'pubspec.yaml')]))); |
| 141 | + }); |
| 142 | + }); |
| 143 | + |
| 144 | + integration('ignores packages directories', () { |
| 145 | + d.dir(appPath, [ |
| 146 | + d.dir('packages', [d.file('file.txt', 'contents')]), |
| 147 | + d.dir('subdir', [ |
| 148 | + d.dir('packages', [d.file('subfile.txt', 'subcontents')]), |
| 149 | + ]) |
| 150 | + ]).create(); |
| 151 | + |
| 152 | + schedule(() { |
| 153 | + expect(entrypoint.packageFiles(), |
| 154 | + completion(equals([path.join(root, 'pubspec.yaml')]))); |
| 155 | + }); |
| 156 | + }); |
| 157 | + |
| 158 | + integration('allows pubspec.lock directories', () { |
| 159 | + d.dir(appPath, [ |
| 160 | + d.dir('pubspec.lock', [ |
| 161 | + d.file('file.txt', 'contents'), |
| 162 | + ]) |
| 163 | + ]).create(); |
| 164 | + |
| 165 | + schedule(() { |
| 166 | + expect(entrypoint.packageFiles(), completion(unorderedEquals([ |
| 167 | + path.join(root, 'pubspec.yaml'), |
| 168 | + path.join(root, 'pubspec.lock', 'file.txt') |
| 169 | + ]))); |
| 170 | + }); |
| 171 | + }); |
| 172 | + |
| 173 | + group('and "beneath"', () { |
| 174 | + integration('only lists files beneath the given root', () { |
| 175 | + d.dir(appPath, [ |
| 176 | + d.file('file1.txt', 'contents'), |
| 177 | + d.file('file2.txt', 'contents'), |
| 178 | + d.dir('subdir', [ |
| 179 | + d.file('subfile1.txt', 'subcontents'), |
| 180 | + d.file('subfile2.txt', 'subcontents'), |
| 181 | + d.dir('subsubdir', [ |
| 182 | + d.file('subsubfile1.txt', 'subsubcontents'), |
| 183 | + d.file('subsubfile2.txt', 'subsubcontents'), |
| 184 | + ]) |
| 185 | + ]) |
| 186 | + ]).create(); |
| 187 | + |
| 188 | + schedule(() { |
| 189 | + expect(entrypoint.packageFiles(beneath: path.join(root, 'subdir')), |
| 190 | + completion(unorderedEquals([ |
| 191 | + path.join(root, 'subdir', 'subfile1.txt'), |
| 192 | + path.join(root, 'subdir', 'subfile2.txt'), |
| 193 | + path.join(root, 'subdir', 'subsubdir', 'subsubfile1.txt'), |
| 194 | + path.join(root, 'subdir', 'subsubdir', 'subsubfile2.txt') |
| 195 | + ]))); |
| 196 | + }); |
| 197 | + }); |
| 198 | + |
| 199 | + integration("doesn't care if the root is blacklisted", () { |
| 200 | + d.dir(appPath, [ |
| 201 | + d.file('file1.txt', 'contents'), |
| 202 | + d.file('file2.txt', 'contents'), |
| 203 | + d.dir('packages', [ |
| 204 | + d.file('subfile1.txt', 'subcontents'), |
| 205 | + d.file('subfile2.txt', 'subcontents'), |
| 206 | + d.dir('subsubdir', [ |
| 207 | + d.file('subsubfile1.txt', 'subsubcontents'), |
| 208 | + d.file('subsubfile2.txt', 'subsubcontents') |
| 209 | + ]) |
| 210 | + ]) |
| 211 | + ]).create(); |
| 212 | + |
| 213 | + schedule(() { |
| 214 | + expect(entrypoint.packageFiles(beneath: path.join(root, 'packages')), |
| 215 | + completion(unorderedEquals([ |
| 216 | + path.join(root, 'packages', 'subfile1.txt'), |
| 217 | + path.join(root, 'packages', 'subfile2.txt'), |
| 218 | + path.join(root, 'packages', 'subsubdir', 'subsubfile1.txt'), |
| 219 | + path.join(root, 'packages', 'subsubdir', 'subsubfile2.txt') |
| 220 | + ]))); |
| 221 | + }); |
| 222 | + }); |
| 223 | + }); |
| 224 | +} |
0 commit comments