Skip to content

Commit

Permalink
root fixes and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Sep 20, 2016
1 parent 2adbb21 commit 450c46d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion common.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ 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)
self.nomount = !!options.nomount

// disable comments and negation in Minimatch.
Expand Down
2 changes: 1 addition & 1 deletion glob.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions test/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,19 @@ t.test('combined with absolute option', function(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())
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)
t.end()
})
})

0 comments on commit 450c46d

Please sign in to comment.