2 // show that it does the same thing by default as the shell.
3 var tap = require("tap")
4 , child_process = require("child_process")
5 , bashResults = require("./bash-results.json")
6 , globs = Object.keys(bashResults)
7 , glob = require("../")
8 , path = require("path")
10 // run from the root of the project
11 // this is usually where you're at anyway, but be sure.
12 process.chdir(path.resolve(__dirname, ".."))
14 function alphasort (a, b) {
17 return a > b ? 1 : a < b ? -1 : 0
20 globs.forEach(function (pattern) {
21 var expect = bashResults[pattern]
22 // anything regarding the symlink thing will fail on windows, so just skip it
23 if (process.platform === "win32" &&
24 expect.some(function (m) {
25 return /\/symlink\//.test(m)
29 tap.test(pattern, function (t) {
30 glob(pattern, function (er, matches) {
34 // sort and unmark, just to match the shell results
35 matches = cleanResults(matches)
37 t.deepEqual(matches, expect, pattern)
42 tap.test(pattern + " sync", function (t) {
43 var matches = cleanResults(glob.sync(pattern))
45 t.deepEqual(matches, expect, "should match shell")
50 function cleanResults (m) {
51 // normalize discrepancies in ordering, duplication,
52 // and ending slashes.
53 return m.map(function (m) {
54 return m.replace(/\/+/g, "/").replace(/\/$/, "")
55 }).sort(alphasort).reduce(function (set, f) {
56 if (f !== set[set.length - 1]) set.push(f)
58 }, []).sort(alphasort).map(function (f) {
60 return (process.platform !== 'win32') ? f
61 : f.replace(/^[a-zA-Z]:[\/\\]+/, '/').replace(/[\\\/]+/g, '/')