Permalink
Browse files

Support using root and absolute options together

* Add failing test for root + absolute option
* root fixes and more tests
* cleanup root tests

Fix #294
  • Loading branch information...
1 parent 12be3fc commit b2aa29bc066de1593d78864158e6a1adafd06e3c @phated phated committed with Sep 20, 2016
Showing with 36 additions and 5 deletions.
  1. +5 −1 common.js
  2. +1 −1 glob.js
  3. +30 −3 test/root.js
View
@@ -103,7 +103,11 @@ function setopts (self, pattern, options) {
if (process.platform === "win32")
self.root = self.root.replace(/\\/g, "/")
- self.cwdAbs = makeAbs(self, self.cwd)
+ // TODO: is an absolute `cwd` supposed to be resolved against `root`?
+ // e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
+ self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd)
+ if (process.platform === "win32")
+ self.cwdAbs = self.cwdAbs.replace(/\\/g, "/")
self.nomount = !!options.nomount
// disable comments and negation in Minimatch.
View
@@ -465,7 +465,7 @@ Glob.prototype._emitMatch = function (index, e) {
return
}
- var abs = this._makeAbs(e)
+ var abs = isAbsolute(e) ? e : this._makeAbs(e)
if (this.mark)
e = this._mark(e)
View
@@ -20,7 +20,7 @@ function cacheCheck(g, t) {
t.test('.', function (t) {
var g = glob('/b*/**', { root: '.' }, function (er, matches) {
t.ifError(er)
- t.like(matches, [])
+ t.same(matches, [])
cacheCheck(g, t)
t.end()
})
@@ -36,7 +36,7 @@ t.test('a', function (t) {
return path.join(path.resolve('a'), m).replace(/\\/g, '/')
})
- t.like(matches, wanted)
+ t.same(matches, wanted)
cacheCheck(g, t)
t.end()
})
@@ -45,10 +45,37 @@ t.test('a', function (t) {
t.test('root=a, cwd=a/b', function (t) {
var g = glob('/b*/**', { root: 'a', cwd: path.resolve('a/b') }, function (er, matches) {
t.ifError(er)
- t.like(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
+ t.same(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
return path.join(path.resolve('a'), m).replace(/\\/g, '/')
}))
cacheCheck(g, t)
t.end()
})
})
+
+t.test('combined with absolute option', function(t) {
+ var g = glob('/b*/**', { root: path.resolve('a'), absolute: true }, function (er, matches) {
+ t.ifError(er)
+ t.same(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
+ return path.join(path.resolve('a'), m).replace(/\\/g, '/')
+ }))
+ cacheCheck(g, t)
+ t.end()
+ })
+})
+
+t.test('cwdAbs when root=a, absolute=true', function(t) {
+ var g = glob('/b*/**', { root: path.resolve('a'), absolute: true }, function (er, matches) {
+ t.ifError(er)
+ t.same(g.cwdAbs, process.cwd().replace(/\\/g, '/'))
+ t.end()
+ })
+})
+
+t.test('cwdAbs when root=a, absolute=true, cwd=__dirname', function(t) {
+ var g = glob('/b*/**', { root: path.resolve('a'), absolute: true, cwd: __dirname }, function (er, matches) {
+ t.ifError(er)
+ t.same(g.cwdAbs, __dirname.replace(/\\/g, '/'))
+ t.end()
+ })
+})

0 comments on commit b2aa29b

Please sign in to comment.