Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: sdk/lib/_internal/pub/test/package_files_test.dart

Issue 15213002: Add unit tests for [Entrypoint.packageFiles] in pub. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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('without git', () {
Bob Nystrom 2013/05/16 18:14:20 I read this as "without git installed". How about
nweiz 2013/05/16 18:40:03 Done.
25 setUp(() {
26 d.appDir([]).create();
27
28 schedule(() {
29 root = path.join(sandboxDir, appPath);
30 entrypoint = new Entrypoint(root, new SystemCache.withSources(root));
31 }, 'initializing entrypoint');
32
33 currentSchedule.onComplete.schedule(() {
34 entrypoint = null;
35 }, 'nulling entrypoint');
Bob Nystrom 2013/05/16 18:14:20 Factor the above 8 lines into a separate function
nweiz 2013/05/16 18:40:03 Done.
36 });
37
38
39 integration('lists files recursively', () {
40 d.dir(appPath, [
41 d.file('file1.txt', 'contents'),
42 d.file('file2.txt', 'contents'),
43 d.dir('subdir', [
44 d.file('subfile1.txt', 'subcontents'),
45 d.file('subfile2.txt', 'subcontents')
46 ])
47 ]).create();
48
49 schedule(() {
50 expect(entrypoint.packageFiles(), completion(unorderedEquals([
51 path.join(root, 'pubspec.yaml'),
52 path.join(root, 'file1.txt'),
53 path.join(root, 'file2.txt'),
54 path.join(root, 'subdir', 'subfile1.txt'),
55 path.join(root, 'subdir', 'subfile2.txt')
56 ])));
57 });
58 });
59
60 commonTests();
61 });
62
63 group('with git', () {
64 setUp(() {
65 ensureGit();
66
67 d.git(appPath, [d.appPubspec([])]).create();
68
69 schedule(() {
70 root = path.join(sandboxDir, appPath);
71 entrypoint = new Entrypoint(root, new SystemCache.withSources(root));
72 }, 'initializing entrypoint');
73
74 currentSchedule.onComplete.schedule(() {
75 entrypoint = null;
76 }, 'nulling entrypoint');
77 });
78
79 integration("includes files that are or aren't checked in", () {
80 d.dir(appPath, [
81 d.file('file1.txt', 'contents'),
82 d.file('file2.txt', 'contents'),
83 d.dir('subdir', [
84 d.file('subfile1.txt', 'subcontents'),
85 d.file('subfile2.txt', 'subcontents')
86 ])
87 ]).create();
88
89 schedule(() {
90 expect(entrypoint.packageFiles(), completion(unorderedEquals([
91 path.join(root, 'pubspec.yaml'),
92 path.join(root, 'file1.txt'),
93 path.join(root, 'file2.txt'),
94 path.join(root, 'subdir', 'subfile1.txt'),
95 path.join(root, 'subdir', 'subfile2.txt')
96 ])));
97 });
98 });
99
100 integration("ignores files that are gitignored", () {
101 d.dir(appPath, [
102 d.file('.gitignore', '*.txt'),
103 d.file('file1.txt', 'contents'),
104 d.file('file2.text', 'contents'),
105 d.dir('subdir', [
106 d.file('subfile1.txt', 'subcontents'),
107 d.file('subfile2.text', 'subcontents')
108 ])
109 ]).create();
110
111 schedule(() {
112 expect(entrypoint.packageFiles(), completion(unorderedEquals([
113 path.join(root, 'pubspec.yaml'),
114 path.join(root, '.gitignore'),
115 path.join(root, 'file2.text'),
116 path.join(root, 'subdir', 'subfile2.text')
117 ])));
118 });
119 });
120
121 commonTests();
122 });
123 }
124
125 void commonTests() {
126 integration('ignores broken symlinks', () {
127 // Windows requires us to symlink to a directory that actually exists.
128 d.dir(appPath, [d.dir('target')]).create();
129 scheduleSymlink(path.join(appPath, 'target'), path.join(appPath, 'link'));
130 schedule(() => deleteEntry(path.join(sandboxDir, appPath, 'target')));
131
132 schedule(() {
133 expect(entrypoint.packageFiles(),
134 completion(equals([path.join(root, 'pubspec.yaml')])));
135 });
136 });
137
138 integration('ignores pubspec.lock files', () {
139 d.dir(appPath, [
140 d.file('pubspec.lock'),
141 d.dir('subdir', [d.file('pubspec.lock')])
142 ]).create();
143
144 schedule(() {
145 expect(entrypoint.packageFiles(),
146 completion(equals([path.join(root, 'pubspec.yaml')])));
147 });
148 });
149
150 integration('ignores packages directories', () {
151 d.dir(appPath, [
152 d.dir('packages', [d.file('file.txt', 'contents')]),
153 d.dir('subdir', [
154 d.dir('packages', [d.file('subfile.txt', 'subcontents')]),
155 ])
156 ]).create();
157
158 schedule(() {
159 expect(entrypoint.packageFiles(),
160 completion(equals([path.join(root, 'pubspec.yaml')])));
161 });
162 });
163
164 integration('allows pubspec.lock directories', () {
165 d.dir(appPath, [
166 d.dir('pubspec.lock', [
167 d.file('file.txt', 'contents'),
168 ])
169 ]).create();
170
171 schedule(() {
172 expect(entrypoint.packageFiles(), completion(unorderedEquals([
173 path.join(root, 'pubspec.yaml'),
174 path.join(root, 'pubspec.lock', 'file.txt')
175 ])));
176 });
177 });
178
179 group('and "beneath"', () {
180 integration('only lists files beneath the given root', () {
181 d.dir(appPath, [
182 d.file('file1.txt', 'contents'),
183 d.file('file2.txt', 'contents'),
184 d.dir('subdir', [
185 d.file('subfile1.txt', 'subcontents'),
186 d.file('subfile2.txt', 'subcontents'),
187 d.dir('subsubdir', [
188 d.file('subsubfile1.txt', 'subsubcontents'),
189 d.file('subsubfile2.txt', 'subsubcontents'),
190 ])
191 ])
192 ]).create();
193
194 schedule(() {
195 expect(entrypoint.packageFiles(beneath: path.join(root, 'subdir')),
196 completion(unorderedEquals([
197 path.join(root, 'subdir', 'subfile1.txt'),
198 path.join(root, 'subdir', 'subfile2.txt'),
199 path.join(root, 'subdir', 'subsubdir', 'subsubfile1.txt'),
200 path.join(root, 'subdir', 'subsubdir', 'subsubfile2.txt')
201 ])));
202 });
203 });
204
205 integration("doesn't care if the root is blacklisted", () {
206 d.dir(appPath, [
207 d.file('file1.txt', 'contents'),
208 d.file('file2.txt', 'contents'),
209 d.dir('packages', [
210 d.file('subfile1.txt', 'subcontents'),
211 d.file('subfile2.txt', 'subcontents'),
212 d.dir('subsubdir', [
213 d.file('subsubfile1.txt', 'subsubcontents'),
214 d.file('subsubfile2.txt', 'subsubcontents')
215 ])
216 ])
217 ]).create();
218
219 schedule(() {
220 expect(entrypoint.packageFiles(beneath: path.join(root, 'packages')),
221 completion(unorderedEquals([
222 path.join(root, 'packages', 'subfile1.txt'),
223 path.join(root, 'packages', 'subfile2.txt'),
224 path.join(root, 'packages', 'subsubdir', 'subsubfile1.txt'),
225 path.join(root, 'packages', 'subsubdir', 'subsubfile2.txt')
226 ])));
227 });
228 });
229 });
230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698