| OLD | NEW | 
|    1 // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file |    1 // Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file | 
|    2 // for details. All rights reserved. Use of this source code is governed by a |    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. |    3 // BSD-style license that can be found in the LICENSE file. | 
|    4  |    4  | 
|    5 import 'dart:async'; |    5 import 'dart:async'; | 
|    6 import 'dart:io'; |    6 import 'dart:io'; | 
|    7  |    7  | 
|    8 import 'package:glob/glob.dart'; |    8 import 'package:glob/glob.dart'; | 
|    9 import 'package:glob/src/utils.dart'; |    9 import 'package:glob/src/utils.dart'; | 
|   10 import 'package:path/path.dart' as p; |   10 import 'package:path/path.dart' as p; | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   48       schedule(() { |   48       schedule(() { | 
|   49         expect(new Glob("non/existent/**").listSync, |   49         expect(new Glob("non/existent/**").listSync, | 
|   50             throwsA(new isInstanceOf<FileSystemException>())); |   50             throwsA(new isInstanceOf<FileSystemException>())); | 
|   51       }); |   51       }); | 
|   52     }); |   52     }); | 
|   53   }); |   53   }); | 
|   54  |   54  | 
|   55   syncAndAsync((list) { |   55   syncAndAsync((list) { | 
|   56     group("literals", () { |   56     group("literals", () { | 
|   57       test("lists a single literal", () { |   57       test("lists a single literal", () { | 
|   58         expect(list("foo/baz/qux"), completion(equals(["foo/baz/qux"]))); |   58         expect(list("foo/baz/qux"), | 
 |   59             completion(equals([p.join("foo", "baz", "qux")]))); | 
|   59       }); |   60       }); | 
|   60  |   61  | 
|   61       test("lists a non-matching literal", () { |   62       test("lists a non-matching literal", () { | 
|   62         expect(list("foo/baz/nothing"), completion(isEmpty)); |   63         expect(list("foo/baz/nothing"), completion(isEmpty)); | 
|   63       }); |   64       }); | 
|   64     }); |   65     }); | 
|   65  |   66  | 
|   66     group("star", () { |   67     group("star", () { | 
|   67       test("lists within filenames but not across directories", () { |   68       test("lists within filenames but not across directories", () { | 
|   68         expect(list("foo/b*"), |   69         expect(list("foo/b*"), completion(unorderedEquals([ | 
|   69             completion(unorderedEquals(["foo/bar", "foo/baz"]))); |   70           p.join("foo", "bar"), | 
 |   71           p.join("foo", "baz") | 
 |   72         ]))); | 
|   70       }); |   73       }); | 
|   71  |   74  | 
|   72       test("lists the empy string", () { |   75       test("lists the empy string", () { | 
|   73         expect(list("foo/bar*"), completion(equals(["foo/bar"]))); |   76         expect(list("foo/bar*"), completion(equals([p.join("foo", "bar")]))); | 
|   74       }); |   77       }); | 
|   75     }); |   78     }); | 
|   76  |   79  | 
|   77     group("double star", () { |   80     group("double star", () { | 
|   78       test("lists within filenames", () { |   81       test("lists within filenames", () { | 
|   79         expect(list("foo/baz/**"), |   82         expect(list("foo/baz/**"), completion(unorderedEquals([ | 
|   80             completion(unorderedEquals(["foo/baz/qux", "foo/baz/bang"]))); |   83           p.join("foo", "baz", "qux"), | 
 |   84           p.join("foo", "baz", "bang") | 
 |   85         ]))); | 
|   81       }); |   86       }); | 
|   82  |   87  | 
|   83       test("lists the empty string", () { |   88       test("lists the empty string", () { | 
|   84         expect(list("foo/bar**"), completion(equals(["foo/bar"]))); |   89         expect(list("foo/bar**"), completion(equals([p.join("foo", "bar")]))); | 
|   85       }); |   90       }); | 
|   86  |   91  | 
|   87       test("lists recursively", () { |   92       test("lists recursively", () { | 
|   88         expect(list("foo/**"), completion(unorderedEquals( |   93         expect(list("foo/**"), completion(unorderedEquals([ | 
|   89             ["foo/bar", "foo/baz", "foo/baz/qux", "foo/baz/bang"]))); |   94           p.join("foo", "bar"), | 
 |   95           p.join("foo", "baz"), | 
 |   96           p.join("foo", "baz", "qux"), | 
 |   97           p.join("foo", "baz", "bang") | 
 |   98         ]))); | 
|   90       }); |   99       }); | 
|   91  |  100  | 
|   92       test("combines with literals", () { |  101       test("combines with literals", () { | 
|   93         expect(list("foo/ba**"), completion(unorderedEquals( |  102         expect(list("foo/ba**"), completion(unorderedEquals([ | 
|   94             ["foo/bar", "foo/baz", "foo/baz/qux", "foo/baz/bang"]))); |  103           p.join("foo", "bar"), | 
 |  104           p.join("foo", "baz"), | 
 |  105           p.join("foo", "baz", "qux"), | 
 |  106           p.join("foo", "baz", "bang") | 
 |  107         ]))); | 
|   95       }); |  108       }); | 
|   96  |  109  | 
|   97       test("lists recursively in the middle of a glob", () { |  110       test("lists recursively in the middle of a glob", () { | 
|   98         d.dir("deep", [ |  111         d.dir("deep", [ | 
|   99           d.dir("a", [ |  112           d.dir("a", [ | 
|  100             d.dir("b", [ |  113             d.dir("b", [ | 
|  101               d.dir("c", [ |  114               d.dir("c", [ | 
|  102                 d.file("d"), |  115                 d.file("d"), | 
|  103                 d.file("long-file") |  116                 d.file("long-file") | 
|  104               ]), |  117               ]), | 
|  105               d.dir("long-dir", [d.file("x")]) |  118               d.dir("long-dir", [d.file("x")]) | 
|  106             ]) |  119             ]) | 
|  107           ]) |  120           ]) | 
|  108         ]).create(); |  121         ]).create(); | 
|  109  |  122  | 
|  110         expect(list("deep/**/?/?"), |  123         expect(list("deep/**/?/?"), completion(unorderedEquals([ | 
|  111             completion(unorderedEquals(["deep/a/b/c", "deep/a/b/c/d"]))); |  124           p.join("deep", "a", "b", "c"), | 
 |  125           p.join("deep", "a", "b", "c", "d") | 
 |  126         ]))); | 
|  112       }); |  127       }); | 
|  113     }); |  128     }); | 
|  114  |  129  | 
|  115     group("any char", () { |  130     group("any char", () { | 
|  116       test("matches a character", () { |  131       test("matches a character", () { | 
|  117         expect(list("foo/ba?"), |  132         expect(list("foo/ba?"), completion(unorderedEquals([ | 
|  118             completion(unorderedEquals(["foo/bar", "foo/baz"]))); |  133           p.join("foo", "bar"), | 
 |  134           p.join("foo", "baz") | 
 |  135         ]))); | 
|  119       }); |  136       }); | 
|  120  |  137  | 
|  121       test("doesn't match a separator", () { |  138       test("doesn't match a separator", () { | 
|  122         expect(list("foo?bar"), completion(isEmpty)); |  139         expect(list("foo?bar"), completion(isEmpty)); | 
|  123       }); |  140       }); | 
|  124     }); |  141     }); | 
|  125  |  142  | 
|  126     group("range", () { |  143     group("range", () { | 
|  127       test("matches a range of characters", () { |  144       test("matches a range of characters", () { | 
|  128         expect(list("foo/ba[a-z]"), |  145         expect(list("foo/ba[a-z]"), completion(unorderedEquals([ | 
|  129             completion(unorderedEquals(["foo/bar", "foo/baz"]))); |  146           p.join("foo", "bar"), | 
 |  147           p.join("foo", "baz") | 
 |  148         ]))); | 
|  130       }); |  149       }); | 
|  131  |  150  | 
|  132       test("matches a specific list of characters", () { |  151       test("matches a specific list of characters", () { | 
|  133         expect(list("foo/ba[rz]"), |  152         expect(list("foo/ba[rz]"), completion(unorderedEquals([ | 
|  134             completion(unorderedEquals(["foo/bar", "foo/baz"]))); |  153           p.join("foo", "bar"), | 
 |  154           p.join("foo", "baz") | 
 |  155         ]))); | 
|  135       }); |  156       }); | 
|  136  |  157  | 
|  137       test("doesn't match outside its range", () { |  158       test("doesn't match outside its range", () { | 
|  138         expect(list("foo/ba[a-x]"), |  159         expect(list("foo/ba[a-x]"), | 
|  139             completion(unorderedEquals(["foo/bar"]))); |  160             completion(unorderedEquals([p.join("foo", "bar")]))); | 
|  140       }); |  161       }); | 
|  141  |  162  | 
|  142       test("doesn't match outside its specific list", () { |  163       test("doesn't match outside its specific list", () { | 
|  143         expect(list("foo/ba[rx]"), |  164         expect(list("foo/ba[rx]"), | 
|  144             completion(unorderedEquals(["foo/bar"]))); |  165             completion(unorderedEquals([p.join("foo", "bar")]))); | 
|  145       }); |  166       }); | 
|  146     }); |  167     }); | 
|  147  |  168  | 
|  148     test("the same file shouldn't be non-recursively listed multiple times", |  169     test("the same file shouldn't be non-recursively listed multiple times", | 
|  149         () { |  170         () { | 
|  150       d.dir("multi", [ |  171       d.dir("multi", [ | 
|  151         d.dir("start-end", [d.file("file")]) |  172         d.dir("start-end", [d.file("file")]) | 
|  152       ]).create(); |  173       ]).create(); | 
|  153  |  174  | 
|  154       expect(list("multi/{start-*/f*,*-end/*e}"), |  175       expect(list("multi/{start-*/f*,*-end/*e}"), | 
|  155           completion(equals(["multi/start-end/file"]))); |  176           completion(equals([p.join("multi", "start-end", "file")]))); | 
|  156     }); |  177     }); | 
|  157  |  178  | 
|  158     test("the same file shouldn't be recursively listed multiple times", () { |  179     test("the same file shouldn't be recursively listed multiple times", () { | 
|  159       d.dir("multi", [ |  180       d.dir("multi", [ | 
|  160         d.dir("a", [ |  181         d.dir("a", [ | 
|  161           d.dir("b", [ |  182           d.dir("b", [ | 
|  162             d.file("file"), |  183             d.file("file"), | 
|  163             d.dir("c", [ |  184             d.dir("c", [ | 
|  164               d.file("file") |  185               d.file("file") | 
|  165             ]) |  186             ]) | 
|  166           ]), |  187           ]), | 
|  167           d.dir("x", [ |  188           d.dir("x", [ | 
|  168             d.dir("y", [ |  189             d.dir("y", [ | 
|  169               d.file("file") |  190               d.file("file") | 
|  170             ]) |  191             ]) | 
|  171           ]) |  192           ]) | 
|  172         ]) |  193         ]) | 
|  173       ]).create(); |  194       ]).create(); | 
|  174  |  195  | 
|  175       expect(list("multi/{*/*/*/file,a/**/file}"), completion(unorderedEquals([ |  196       expect(list("multi/{*/*/*/file,a/**/file}"), completion(unorderedEquals([ | 
|  176         "multi/a/b/file", "multi/a/b/c/file", "multi/a/x/y/file" |  197         p.join("multi", "a", "b", "file"), | 
 |  198         p.join("multi", "a", "b", "c", "file"), | 
 |  199         p.join("multi", "a", "x", "y", "file") | 
|  177       ]))); |  200       ]))); | 
|  178     }); |  201     }); | 
|  179  |  202  | 
|  180     group("with symlinks", () { |  203     group("with symlinks", () { | 
|  181       setUp(() { |  204       setUp(() { | 
|  182         schedule(() { |  205         schedule(() { | 
|  183           return new Link(p.join(sandbox, "dir", "link")) |  206           return new Link(p.join(sandbox, "dir", "link")) | 
|  184               .create(p.join(sandbox, "foo", "baz"), recursive: true); |  207               .create(p.join(sandbox, "foo", "baz"), recursive: true); | 
|  185         }, "symlink foo/baz to dir/link"); |  208         }, "symlink foo/baz to dir/link"); | 
|  186       }); |  209       }); | 
|  187  |  210  | 
|  188       test("follows symlinks by default", () { |  211       test("follows symlinks by default", () { | 
|  189         expect(list("dir/**"), completion(unorderedEquals([ |  212         expect(list("dir/**"), completion(unorderedEquals([ | 
|  190           "dir/link", "dir/link/bang", "dir/link/qux" |  213           p.join("dir", "link"), | 
 |  214           p.join("dir", "link", "bang"), | 
 |  215           p.join("dir", "link", "qux") | 
|  191         ]))); |  216         ]))); | 
|  192       }); |  217       }); | 
|  193  |  218  | 
|  194       test("doesn't follow symlinks with followLinks: false", () { |  219       test("doesn't follow symlinks with followLinks: false", () { | 
|  195         expect(list("dir/**", followLinks: false), |  220         expect(list("dir/**", followLinks: false), | 
|  196             completion(equals(["dir/link"]))); |  221             completion(equals([p.join("dir", "link")]))); | 
|  197       }); |  222       }); | 
|  198  |  223  | 
|  199       test("shouldn't crash on broken symlinks", () { |  224       test("shouldn't crash on broken symlinks", () { | 
|  200         schedule(() { |  225         schedule(() { | 
|  201           return new Directory(p.join(sandbox, "foo")).delete(recursive: true); |  226           return new Directory(p.join(sandbox, "foo")).delete(recursive: true); | 
|  202         }); |  227         }); | 
|  203  |  228  | 
|  204         expect(list("dir/**"), completion(equals(["dir/link"]))); |  229         expect(list("dir/**"), completion(equals([p.join("dir", "link")]))); | 
|  205       }); |  230       }); | 
|  206     }); |  231     }); | 
|  207  |  232  | 
|  208     test("always lists recursively with recursive: true", () { |  233     test("always lists recursively with recursive: true", () { | 
|  209       expect(list("foo", recursive: true), completion(unorderedEquals( |  234       expect(list("foo", recursive: true), completion(unorderedEquals([ | 
|  210           ["foo", "foo/bar", "foo/baz", "foo/baz/qux", "foo/baz/bang"]))); |  235         "foo", | 
 |  236         p.join("foo", "bar"), | 
 |  237         p.join("foo", "baz"), | 
 |  238         p.join("foo", "baz", "qux"), | 
 |  239         p.join("foo", "baz", "bang") | 
 |  240       ]))); | 
|  211     }); |  241     }); | 
|  212  |  242  | 
|  213     test("lists an absolute glob", () { |  243     test("lists an absolute glob", () { | 
|  214       expect(schedule(() { |  244       expect(schedule(() { | 
|  215         var pattern = separatorToForwardSlash( |  245         var pattern = separatorToForwardSlash( | 
|  216             p.absolute(p.join(sandbox, 'foo/baz/**'))); |  246             p.absolute(p.join(sandbox, 'foo/baz/**'))); | 
|  217  |  247  | 
|  218         return list(pattern); |  248         return list(pattern); | 
|  219       }), completion(unorderedEquals(["foo/baz/bang", "foo/baz/qux"]))); |  249       }), completion(unorderedEquals([ | 
 |  250         p.join("foo", "baz", "bang"), | 
 |  251         p.join("foo", "baz", "qux") | 
 |  252       ]))); | 
|  220     }); |  253     }); | 
|  221   }); |  254   }); | 
|  222 } |  255 } | 
|  223  |  256  | 
|  224 typedef Future<List<String>> ListFn(String glob, |  257 typedef Future<List<String>> ListFn(String glob, | 
|  225     {bool recursive, bool followLinks}); |  258     {bool recursive, bool followLinks}); | 
|  226  |  259  | 
|  227 /// Runs [callback] in two groups with two values of [listFn]: one that uses |  260 /// Runs [callback] in two groups with two values of [listFn]: one that uses | 
|  228 /// [Glob.list], one that uses [Glob.listSync]. |  261 /// [Glob.list], one that uses [Glob.listSync]. | 
|  229 void syncAndAsync(callback(ListFn listFn)) { |  262 void syncAndAsync(callback(ListFn listFn)) { | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  263   }, 'creating sandbox'); |  296   }, 'creating sandbox'); | 
|  264  |  297  | 
|  265   currentSchedule.onComplete.schedule(() { |  298   currentSchedule.onComplete.schedule(() { | 
|  266     d.defaultRoot = null; |  299     d.defaultRoot = null; | 
|  267     if (sandbox == null) return null; |  300     if (sandbox == null) return null; | 
|  268     var oldSandbox = sandbox; |  301     var oldSandbox = sandbox; | 
|  269     sandbox = null; |  302     sandbox = null; | 
|  270     return new Directory(oldSandbox).delete(recursive: true); |  303     return new Directory(oldSandbox).delete(recursive: true); | 
|  271   }); |  304   }); | 
|  272 } |  305 } | 
| OLD | NEW |