From 3f8913a44ee195628bfedfe17f9f04684e989f5f Mon Sep 17 00:00:00 2001 From: Vlad Filippov Date: Tue, 10 May 2022 07:51:46 -0400 Subject: [PATCH] Fix tests --- lib/grunt/file.js | 2 - test/grunt/file_test.js | 984 ++++++++++++++++++++-------------------- 2 files changed, 492 insertions(+), 494 deletions(-) diff --git a/lib/grunt/file.js b/lib/grunt/file.js index 743b8933..82863f35 100644 --- a/lib/grunt/file.js +++ b/lib/grunt/file.js @@ -295,7 +295,6 @@ file.write = function(filepath, contents, options) { // Handles symlinks by coping them as files or directories. file.copy = function copy(srcpath, destpath, options) { if (file.isLink(srcpath)) { - console.log('srcpath isLink', srcpath); file._copySymbolicLink(srcpath, destpath); } else if (file.isDir(srcpath)) { // Copy a directory, recursively. @@ -454,7 +453,6 @@ file.isPathCwd = function() { }; file._copySymbolicLink = function(srcpath, destpath) { - console.log('_copySymbolicLink'); var destdir = path.join(destpath, '..'); // Use the correct relative path for the symlink if (!grunt.file.isPathAbsolute(srcpath)) { diff --git a/test/grunt/file_test.js b/test/grunt/file_test.js index e4c26491..a298d398 100644 --- a/test/grunt/file_test.js +++ b/test/grunt/file_test.js @@ -422,455 +422,455 @@ exports.file = { done(); }, - // 'read': function(test) { - // test.expect(6); - // test.strictEqual(grunt.file.read('test/fixtures/utf8.txt'), this.string, 'file should be read as utf8 by default.'); - // test.strictEqual(grunt.file.read('test/fixtures/iso-8859-1.txt', {encoding: 'iso-8859-1'}), this.string, 'file should be read using the specified encoding.'); - // test.ok(compareBuffers(grunt.file.read('test/fixtures/octocat.png', {encoding: null}), fs.readFileSync('test/fixtures/octocat.png')), 'file should be read as a buffer if encoding is specified as null.'); - - // test.strictEqual(grunt.file.read('test/fixtures/BOM.txt'), 'foo', 'file should have BOM stripped.'); - // grunt.file.preserveBOM = true; - // test.strictEqual(grunt.file.read('test/fixtures/BOM.txt'), '\ufeff' + 'foo', 'file should have BOM preserved.'); - // grunt.file.preserveBOM = false; - - // grunt.file.defaultEncoding = 'iso-8859-1'; - // test.strictEqual(grunt.file.read('test/fixtures/iso-8859-1.txt'), this.string, 'changing the default encoding should work.'); - // test.done(); - // }, - // 'readJSON': function(test) { - // test.expect(3); - // var obj; - // obj = grunt.file.readJSON('test/fixtures/utf8.json'); - // test.deepEqual(obj, this.object, 'file should be read as utf8 by default and parsed correctly.'); - - // obj = grunt.file.readJSON('test/fixtures/iso-8859-1.json', {encoding: 'iso-8859-1'}); - // test.deepEqual(obj, this.object, 'file should be read using the specified encoding.'); - - // grunt.file.defaultEncoding = 'iso-8859-1'; - // obj = grunt.file.readJSON('test/fixtures/iso-8859-1.json'); - // test.deepEqual(obj, this.object, 'changing the default encoding should work.'); - // test.done(); - // }, - // 'readYAML': function(test) { - // test.expect(5); - // var obj; - // obj = grunt.file.readYAML('test/fixtures/utf8.yaml'); - // test.deepEqual(obj, this.object, 'file should be safely read as utf8 by default and parsed correctly.'); - - // obj = grunt.file.readYAML('test/fixtures/utf8.yaml', null, {unsafeLoad: true}); - // test.deepEqual(obj, this.object, 'file should be unsafely read as utf8 by default and parsed correctly.'); - - // obj = grunt.file.readYAML('test/fixtures/iso-8859-1.yaml', {encoding: 'iso-8859-1'}); - // test.deepEqual(obj, this.object, 'file should be read using the specified encoding.'); - - // test.throws(function() { - // obj = grunt.file.readYAML('test/fixtures/error.yaml'); - // }, function(err) { - // return err.message.indexOf('undefined') === -1; - // }, 'error thrown should not contain undefined.'); - - // grunt.file.defaultEncoding = 'iso-8859-1'; - // obj = grunt.file.readYAML('test/fixtures/iso-8859-1.yaml'); - // test.deepEqual(obj, this.object, 'changing the default encoding should work.'); - // test.done(); - // }, - // 'write': function(test) { - // test.expect(6); - // var tmpfile; - // tmpfile = new Tempfile(); - // grunt.file.write(tmpfile.path, this.string); - // test.strictEqual(fs.readFileSync(tmpfile.path, 'utf8'), this.string, 'file should be written as utf8 by default.'); - // tmpfile.unlinkSync(); - - // tmpfile = new Tempfile(); - // grunt.file.write(tmpfile.path, this.string, {encoding: 'iso-8859-1'}); - // test.strictEqual(grunt.file.read(tmpfile.path, {encoding: 'iso-8859-1'}), this.string, 'file should be written using the specified encoding.'); - // tmpfile.unlinkSync(); - - // tmpfile = new Tempfile(); - // tmpfile.unlinkSync(); - // grunt.file.write(tmpfile.path, this.string, {mode: parseInt('0444', 8)}); - // test.strictEqual(fs.statSync(tmpfile.path).mode & parseInt('0222', 8), 0, 'file should be read only.'); - // fs.chmodSync(tmpfile.path, parseInt('0666', 8)); - // tmpfile.unlinkSync(); - - // grunt.file.defaultEncoding = 'iso-8859-1'; - // tmpfile = new Tempfile(); - // grunt.file.write(tmpfile.path, this.string); - // grunt.file.defaultEncoding = 'utf8'; - // test.strictEqual(grunt.file.read(tmpfile.path, {encoding: 'iso-8859-1'}), this.string, 'changing the default encoding should work.'); - // tmpfile.unlinkSync(); - - // tmpfile = new Tempfile(); - // var octocat = fs.readFileSync('test/fixtures/octocat.png'); - // grunt.file.write(tmpfile.path, octocat); - // test.ok(compareBuffers(fs.readFileSync(tmpfile.path), octocat), 'buffers should always be written as-specified, with no attempt at re-encoding.'); - // tmpfile.unlinkSync(); - - // grunt.option('write', false); - // var filepath = path.join(tmpdir.path, 'should-not-exist.txt'); - // grunt.file.write(filepath, 'test'); - // test.equal(grunt.file.exists(filepath), false, 'file should NOT be created if --no-write was specified.'); - // test.done(); - // }, - // 'copy': function(test) { - // test.expect(4); - // var tmpfile; - // tmpfile = new Tempfile(); - // grunt.file.copy('test/fixtures/utf8.txt', tmpfile.path); - // test.ok(compareFiles(tmpfile.path, 'test/fixtures/utf8.txt'), 'files should just be copied as encoding-agnostic by default.'); - // tmpfile.unlinkSync(); - - // tmpfile = new Tempfile(); - // grunt.file.copy('test/fixtures/iso-8859-1.txt', tmpfile.path); - // test.ok(compareFiles(tmpfile.path, 'test/fixtures/iso-8859-1.txt'), 'files should just be copied as encoding-agnostic by default.'); - // tmpfile.unlinkSync(); - - // tmpfile = new Tempfile(); - // grunt.file.copy('test/fixtures/octocat.png', tmpfile.path); - // test.ok(compareFiles(tmpfile.path, 'test/fixtures/octocat.png'), 'files should just be copied as encoding-agnostic by default.'); - // tmpfile.unlinkSync(); - - // grunt.option('write', false); - // var filepath = path.join(tmpdir.path, 'should-not-exist.txt'); - // grunt.file.copy('test/fixtures/utf8.txt', filepath); - // test.equal(grunt.file.exists(filepath), false, 'file should NOT be created if --no-write was specified.'); - // test.done(); - // }, - // 'copy and process': function(test) { - // test.expect(14); - // var tmpfile; - // tmpfile = new Tempfile(); - // grunt.file.copy('test/fixtures/utf8.txt', tmpfile.path, { - // process: function(src, srcpath, destpath) { - // test.equal(srcpath, 'test/fixtures/utf8.txt', 'srcpath should be passed in, as-specified.'); - // test.equal(destpath, tmpfile.path, 'destpath should be passed in, as-specified.'); - // test.equal(Buffer.isBuffer(src), false, 'when no encoding is specified, use default encoding and process src as a string'); - // test.equal(typeof src, 'string', 'when no encoding is specified, use default encoding and process src as a string'); - // return 'føø' + src + 'bår'; - // } - // }); - // test.equal(grunt.file.read(tmpfile.path), 'føø' + this.string + 'bår', 'file should be saved as properly encoded processed string.'); - // tmpfile.unlinkSync(); - - // tmpfile = new Tempfile(); - // grunt.file.copy('test/fixtures/iso-8859-1.txt', tmpfile.path, { - // encoding: 'iso-8859-1', - // process: function(src) { - // test.equal(Buffer.isBuffer(src), false, 'use specified encoding and process src as a string'); - // test.equal(typeof src, 'string', 'use specified encoding and process src as a string'); - // return 'føø' + src + 'bår'; - // } - // }); - // test.equal(grunt.file.read(tmpfile.path, {encoding: 'iso-8859-1'}), 'føø' + this.string + 'bår', 'file should be saved as properly encoded processed string.'); - // tmpfile.unlinkSync(); - - // tmpfile = new Tempfile(); - // grunt.file.copy('test/fixtures/utf8.txt', tmpfile.path, { - // encoding: null, - // process: function(src) { - // test.ok(Buffer.isBuffer(src), 'when encoding is specified as null, process src as a buffer'); - // return Buffer.from('føø' + src.toString() + 'bår'); - // } - // }); - // test.equal(grunt.file.read(tmpfile.path), 'føø' + this.string + 'bår', 'file should be saved as the buffer returned by process.'); - // tmpfile.unlinkSync(); - - // grunt.file.defaultEncoding = 'iso-8859-1'; - // tmpfile = new Tempfile(); - // grunt.file.copy('test/fixtures/iso-8859-1.txt', tmpfile.path, { - // process: function(src) { - // test.equal(Buffer.isBuffer(src), false, 'use non-utf8 default encoding and process src as a string'); - // test.equal(typeof src, 'string', 'use non-utf8 default encoding and process src as a string'); - // return 'føø' + src + 'bår'; - // } - // }); - // test.equal(grunt.file.read(tmpfile.path), 'føø' + this.string + 'bår', 'file should be saved as properly encoded processed string.'); - // tmpfile.unlinkSync(); - - // var filepath = path.join(tmpdir.path, 'should-not-exist.txt'); - // grunt.file.copy('test/fixtures/iso-8859-1.txt', filepath, { - // process: function() { - // return false; - // } - // }); - // test.equal(grunt.file.exists(filepath), false, 'file should NOT be created if process returns false.'); - // test.done(); - // }, - // 'copy and process, noprocess': function(test) { - // test.expect(4); - // var tmpfile; - // tmpfile = new Tempfile(); - // grunt.file.copy('test/fixtures/utf8.txt', tmpfile.path, { - // noProcess: true, - // process: function(src) { - // return 'føø' + src + 'bår'; - // } - // }); - // test.equal(grunt.file.read(tmpfile.path), this.string, 'file should not have been processed.'); - // tmpfile.unlinkSync(); - - // ['process', 'noprocess', 'othernoprocess'].forEach(function(filename) { - // var filepath = path.join(tmpdir.path, filename); - // grunt.file.copy('test/fixtures/utf8.txt', filepath); - // var tmpfile = new Tempfile(); - // grunt.file.copy(filepath, tmpfile.path, { - // noProcess: ['**/*no*'], - // process: function(src) { - // return 'føø' + src + 'bår'; - // } - // }); - // if (filename === 'process') { - // test.equal(grunt.file.read(tmpfile.path), 'føø' + this.string + 'bår', 'file should have been processed.'); - // } else { - // test.equal(grunt.file.read(tmpfile.path), this.string, 'file should not have been processed.'); - // } - // tmpfile.unlinkSync(); - // }, this); - - // test.done(); - // }, - // 'copy directory recursively': function(test) { - // test.expect(34); - // var copyroot1 = path.join(tmpdir.path, 'copy-dir-1'); - // var copyroot2 = path.join(tmpdir.path, 'copy-dir-2'); - // grunt.file.copy('test/fixtures/expand/', copyroot1); - // grunt.file.recurse('test/fixtures/expand/', function(srcpath, rootdir, subdir, filename) { - // var destpath = path.join(copyroot1, subdir || '', filename); - // test.ok(grunt.file.isFile(srcpath), 'file should have been copied.'); - // test.equal(grunt.file.read(srcpath), grunt.file.read(destpath), 'file contents should be the same.'); - // }); - // grunt.file.mkdir(path.join(copyroot1, 'empty')); - // grunt.file.mkdir(path.join(copyroot1, 'deep/deeper/empty')); - // grunt.file.copy(copyroot1, copyroot2, { - // process: function(contents) { - // return '<' + contents + '>'; - // }, - // }); - // test.ok(grunt.file.isDir(path.join(copyroot2, 'empty')), 'empty directory should have been created.'); - // test.ok(grunt.file.isDir(path.join(copyroot2, 'deep/deeper/empty')), 'empty directory should have been created.'); - // grunt.file.recurse('test/fixtures/expand/', function(srcpath, rootdir, subdir, filename) { - // var destpath = path.join(copyroot2, subdir || '', filename); - // test.ok(grunt.file.isFile(srcpath), 'file should have been copied.'); - // test.equal('<' + grunt.file.read(srcpath) + '>', grunt.file.read(destpath), 'file contents should be processed correctly.'); - // }); - // test.done(); - // }, - // 'delete': function(test) { - // test.expect(2); - // var oldBase = process.cwd(); - // var cwd = path.resolve(tmpdir.path, 'delete', 'folder'); - // grunt.file.mkdir(cwd); - // grunt.file.setBase(tmpdir.path); - - // grunt.file.write(path.join(cwd, 'test.js'), 'var test;'); - // test.ok(grunt.file.delete(cwd), 'should return true after deleting file.'); - // test.equal(grunt.file.exists(cwd), false, 'file should have been deleted.'); - // grunt.file.setBase(oldBase); - // test.done(); - // }, - // 'delete nonexistent file': function(test) { - // test.expect(2); - // this.resetWarnCount(); - // test.ok(!grunt.file.delete('nonexistent'), 'should return false if file does not exist.'); - // test.ok(this.warnCount, 'should issue a warning when deleting non-existent file'); - // test.done(); - // }, - // 'delete outside working directory': function(test) { - // test.expect(4); - // var oldBase = process.cwd(); - // var cwd = path.resolve(tmpdir.path, 'delete', 'folder'); - // var outsidecwd = path.resolve(tmpdir.path, 'delete', 'outsidecwd'); - // grunt.file.mkdir(cwd); - // grunt.file.mkdir(outsidecwd); - // grunt.file.setBase(cwd); - - // grunt.file.write(path.join(outsidecwd, 'test.js'), 'var test;'); - - // this.resetWarnCount(); - // test.equal(grunt.file.delete(path.join(outsidecwd, 'test.js')), false, 'should not delete anything outside the cwd.'); - // test.ok(this.warnCount, 'should issue a warning when deleting outside working directory'); - - // test.ok(grunt.file.delete(path.join(outsidecwd), {force: true}), 'should delete outside cwd when using the --force.'); - // test.equal(grunt.file.exists(outsidecwd), false, 'file outside cwd should have been deleted when using the --force.'); - - // grunt.file.setBase(oldBase); - // test.done(); - // }, - // 'dont delete current working directory': function(test) { - // test.expect(3); - // var oldBase = process.cwd(); - // var cwd = path.resolve(tmpdir.path, 'dontdelete', 'folder'); - // grunt.file.mkdir(cwd); - // grunt.file.setBase(cwd); - - // this.resetWarnCount(); - // test.equal(grunt.file.delete(cwd), false, 'should not delete the cwd.'); - // test.ok(this.warnCount, 'should issue a warning when trying to delete cwd'); - - // test.ok(grunt.file.exists(cwd), 'the cwd should exist.'); - - // grunt.file.setBase(oldBase); - // test.done(); - // }, - // 'dont actually delete with no-write option on': function(test) { - // test.expect(2); - // grunt.option('write', false); - - // var oldBase = process.cwd(); - // var cwd = path.resolve(tmpdir.path, 'dontdelete', 'folder'); - // grunt.file.mkdir(cwd); - // grunt.file.setBase(tmpdir.path); - - // grunt.file.write(path.join(cwd, 'test.js'), 'var test;'); - // test.ok(grunt.file.delete(cwd), 'should return true after not actually deleting file.'); - // test.equal(grunt.file.exists(cwd), true, 'file should NOT be deleted if --no-write was specified.'); - // grunt.file.setBase(oldBase); - - // test.done(); - // }, - // 'mkdir': function(test) { - // test.expect(5); - // test.doesNotThrow(function() { - // grunt.file.mkdir(tmpdir.path); - // }, 'Should not explode if the directory already exists.'); - // test.ok(fs.existsSync(tmpdir.path), 'path should still exist.'); - - // test.doesNotThrow(function() { - // grunt.file.mkdir(path.join(tmpdir.path, 'aa/bb/cc')); - // }, 'Should also not explode, otherwise.'); - // test.ok(path.join(tmpdir.path, 'aa/bb/cc'), 'path should have been created.'); - - // fs.writeFileSync(path.join(tmpdir.path, 'aa/bb/xx'), 'test'); - // test.throws(function() { - // grunt.file.mkdir(path.join(tmpdir.path, 'aa/bb/xx/yy')); - // }, 'Should throw if a path cannot be created (ENOTDIR).'); - - // test.done(); - // }, - // 'recurse': function(test) { - // test.expect(1); - // var rootdir = 'test/fixtures/expand'; - // var expected = {}; - // expected[rootdir + '/css/baz.css'] = [rootdir, 'css', 'baz.css']; - // expected[rootdir + '/css/qux.css'] = [rootdir, 'css', 'qux.css']; - // expected[rootdir + '/deep/deep.txt'] = [rootdir, 'deep', 'deep.txt']; - // expected[rootdir + '/deep/deeper/deeper.txt'] = [rootdir, 'deep/deeper', 'deeper.txt']; - // expected[rootdir + '/deep/deeper/deepest/deepest.txt'] = [rootdir, 'deep/deeper/deepest', 'deepest.txt']; - // expected[rootdir + '/js/bar.js'] = [rootdir, 'js', 'bar.js']; - // expected[rootdir + '/js/foo.js'] = [rootdir, 'js', 'foo.js']; - // expected[rootdir + '/README.md'] = [rootdir, undefined, 'README.md']; - - // var actual = {}; - // grunt.file.recurse(rootdir, function(abspath, rootdir, subdir, filename) { - // actual[abspath] = [rootdir, subdir, filename]; - // }); - - // test.deepEqual(actual, expected, 'paths and arguments should match.'); - // test.done(); - // }, - // 'exists': function(test) { - // test.expect(6); - // test.ok(grunt.file.exists('test/fixtures/octocat.png'), 'files exist.'); - // test.ok(grunt.file.exists('test', 'fixtures', 'octocat.png'), 'should work for paths in parts.'); - // test.ok(grunt.file.exists('test/fixtures'), 'directories exist.'); - // test.ok(grunt.file.exists(path.join(tmpdir.path, 'octocat.png')), 'file links exist.'); - // test.ok(grunt.file.exists(path.join(tmpdir.path, 'expand')), 'directory links exist.'); - // test.equal(grunt.file.exists('test/fixtures/does/not/exist'), false, 'nonexistent files do not exist.'); - // test.done(); - // }, - // 'isLink': function(test) { - // test.expect(8); - // test.equals(grunt.file.isLink('test/fixtures/octocat.png'), false, 'files are not links.'); - // test.equals(grunt.file.isLink('test/fixtures'), false, 'directories are not links.'); - // test.ok(grunt.file.isLink(path.join(tmpdir.path, 'octocat.png')), 'file links are links.'); - // test.ok(grunt.file.isLink(path.join(tmpdir.path, 'expand')), 'directory links are links.'); - // grunt.file.mkdir(path.join(tmpdir.path, 'relative-links')); - // fs.symlinkSync('test/fixtures/octocat.png', path.join(tmpdir.path, 'relative-links/octocat.png'), 'file'); - // fs.symlinkSync('test/fixtures/expand', path.join(tmpdir.path, 'relative-links/expand'), 'file'); - // test.ok(grunt.file.isLink(path.join(tmpdir.path, 'relative-links/octocat.png')), 'relative file links are links.'); - // test.ok(grunt.file.isLink(path.join(tmpdir.path, 'relative-links/expand')), 'relative directory links are links.'); - // test.ok(grunt.file.isLink(tmpdir.path, 'octocat.png'), 'should work for paths in parts.'); - // test.equals(grunt.file.isLink('test/fixtures/does/not/exist'), false, 'nonexistent files are not links.'); - // test.done(); - // }, - // 'isDir': function(test) { - // test.expect(6); - // test.equals(grunt.file.isDir('test/fixtures/octocat.png'), false, 'files are not directories.'); - // test.ok(grunt.file.isDir('test/fixtures'), 'directories are directories.'); - // test.ok(grunt.file.isDir('test', 'fixtures'), 'should work for paths in parts.'); - // test.equals(grunt.file.isDir(path.join(tmpdir.path, 'octocat.png')), false, 'file links are not directories.'); - // test.ok(grunt.file.isDir(path.join(tmpdir.path, 'expand')), 'directory links are directories.'); - // test.equals(grunt.file.isDir('test/fixtures/does/not/exist'), false, 'nonexistent files are not directories.'); - // test.done(); - // }, - // 'isFile': function(test) { - // test.expect(6); - // test.ok(grunt.file.isFile('test/fixtures/octocat.png'), 'files are files.'); - // test.ok(grunt.file.isFile('test', 'fixtures', 'octocat.png'), 'should work for paths in parts.'); - // test.equals(grunt.file.isFile('test/fixtures'), false, 'directories are not files.'); - // test.ok(grunt.file.isFile(path.join(tmpdir.path, 'octocat.png')), 'file links are files.'); - // test.equals(grunt.file.isFile(path.join(tmpdir.path, 'expand')), false, 'directory links are not files.'); - // test.equals(grunt.file.isFile('test/fixtures/does/not/exist'), false, 'nonexistent files are not files.'); - // test.done(); - // }, - // 'isPathAbsolute': function(test) { - // test.expect(6); - // test.ok(grunt.file.isPathAbsolute(path.resolve('/foo')), 'should return true'); - // test.ok(grunt.file.isPathAbsolute(path.resolve('/foo') + path.sep), 'should return true'); - // test.equal(grunt.file.isPathAbsolute('foo'), false, 'should return false'); - // test.ok(grunt.file.isPathAbsolute(path.resolve('test/fixtures/a.js')), 'should return true'); - // test.equal(grunt.file.isPathAbsolute('test/fixtures/a.js'), false, 'should return false'); - // if (win32) { - // test.equal(grunt.file.isPathAbsolute('C:/Users/'), true, 'should return true'); - // } else { - // test.equal(grunt.file.isPathAbsolute('/'), true, 'should return true'); - // } - // test.done(); - // }, - // 'arePathsEquivalent': function(test) { - // test.expect(5); - // test.ok(grunt.file.arePathsEquivalent('/foo'), 'should return true'); - // test.ok(grunt.file.arePathsEquivalent('/foo', '/foo/', '/foo/../foo/'), 'should return true'); - // test.ok(grunt.file.arePathsEquivalent(process.cwd(), '.', './', 'test/..'), 'should return true'); - // test.equal(grunt.file.arePathsEquivalent(process.cwd(), '..'), false, 'should return false'); - // test.equal(grunt.file.arePathsEquivalent('.', '..'), false, 'should return false'); - // test.done(); - // }, - // 'doesPathContain': function(test) { - // test.expect(6); - // test.ok(grunt.file.doesPathContain('/foo', '/foo/bar'), 'should return true'); - // test.ok(grunt.file.doesPathContain('/foo/', '/foo/bar/baz', '/foo/bar', '/foo/whatever'), 'should return true'); - // test.equal(grunt.file.doesPathContain('/foo', '/foo'), false, 'should return false'); - // test.equal(grunt.file.doesPathContain('/foo/xyz', '/foo/xyz/123', '/foo/bar/baz'), false, 'should return false'); - // test.equal(grunt.file.doesPathContain('/foo/xyz', '/foo'), false, 'should return false'); - // test.ok(grunt.file.doesPathContain(process.cwd(), 'test', 'test/fixtures', 'lib'), 'should return true'); - // test.done(); - // }, - // 'isPathCwd': function(test) { - // test.expect(8); - // test.ok(grunt.file.isPathCwd(process.cwd()), 'cwd is cwd'); - // test.ok(grunt.file.isPathCwd('.'), 'cwd is cwd'); - // test.equal(grunt.file.isPathCwd('test'), false, 'subdirectory is not cwd'); - // test.equal(grunt.file.isPathCwd(path.resolve('test')), false, 'subdirectory is not cwd'); - // test.equal(grunt.file.isPathCwd('..'), false, 'parent is not cwd'); - // test.equal(grunt.file.isPathCwd(path.resolve('..')), false, 'parent is not cwd'); - // test.equal(grunt.file.isPathCwd('/'), false, 'root is not cwd (I hope)'); - // test.equal(grunt.file.isPathCwd('nonexistent'), false, 'nonexistent path is not cwd'); - // test.done(); - // }, - // 'isPathInCwd': function(test) { - // test.expect(8); - // test.equal(grunt.file.isPathInCwd(process.cwd()), false, 'cwd is not IN cwd'); - // test.equal(grunt.file.isPathInCwd('.'), false, 'cwd is not IN cwd'); - // test.ok(grunt.file.isPathInCwd('test'), 'subdirectory is in cwd'); - // test.ok(grunt.file.isPathInCwd(path.resolve('test')), 'subdirectory is in cwd'); - // test.equal(grunt.file.isPathInCwd('..'), false, 'parent is not in cwd'); - // test.equal(grunt.file.isPathInCwd(path.resolve('..')), false, 'parent is not in cwd'); - // test.equal(grunt.file.isPathInCwd('/'), false, 'root is not in cwd (I hope)'); - // test.equal(grunt.file.isPathInCwd('nonexistent'), false, 'nonexistent path is not in cwd'); - // test.done(); - // }, + 'read': function(test) { + test.expect(6); + test.strictEqual(grunt.file.read('test/fixtures/utf8.txt'), this.string, 'file should be read as utf8 by default.'); + test.strictEqual(grunt.file.read('test/fixtures/iso-8859-1.txt', {encoding: 'iso-8859-1'}), this.string, 'file should be read using the specified encoding.'); + test.ok(compareBuffers(grunt.file.read('test/fixtures/octocat.png', {encoding: null}), fs.readFileSync('test/fixtures/octocat.png')), 'file should be read as a buffer if encoding is specified as null.'); + + test.strictEqual(grunt.file.read('test/fixtures/BOM.txt'), 'foo', 'file should have BOM stripped.'); + grunt.file.preserveBOM = true; + test.strictEqual(grunt.file.read('test/fixtures/BOM.txt'), '\ufeff' + 'foo', 'file should have BOM preserved.'); + grunt.file.preserveBOM = false; + + grunt.file.defaultEncoding = 'iso-8859-1'; + test.strictEqual(grunt.file.read('test/fixtures/iso-8859-1.txt'), this.string, 'changing the default encoding should work.'); + test.done(); + }, + 'readJSON': function(test) { + test.expect(3); + var obj; + obj = grunt.file.readJSON('test/fixtures/utf8.json'); + test.deepEqual(obj, this.object, 'file should be read as utf8 by default and parsed correctly.'); + + obj = grunt.file.readJSON('test/fixtures/iso-8859-1.json', {encoding: 'iso-8859-1'}); + test.deepEqual(obj, this.object, 'file should be read using the specified encoding.'); + + grunt.file.defaultEncoding = 'iso-8859-1'; + obj = grunt.file.readJSON('test/fixtures/iso-8859-1.json'); + test.deepEqual(obj, this.object, 'changing the default encoding should work.'); + test.done(); + }, + 'readYAML': function(test) { + test.expect(5); + var obj; + obj = grunt.file.readYAML('test/fixtures/utf8.yaml'); + test.deepEqual(obj, this.object, 'file should be safely read as utf8 by default and parsed correctly.'); + + obj = grunt.file.readYAML('test/fixtures/utf8.yaml', null, {unsafeLoad: true}); + test.deepEqual(obj, this.object, 'file should be unsafely read as utf8 by default and parsed correctly.'); + + obj = grunt.file.readYAML('test/fixtures/iso-8859-1.yaml', {encoding: 'iso-8859-1'}); + test.deepEqual(obj, this.object, 'file should be read using the specified encoding.'); + + test.throws(function() { + obj = grunt.file.readYAML('test/fixtures/error.yaml'); + }, function(err) { + return err.message.indexOf('undefined') === -1; + }, 'error thrown should not contain undefined.'); + + grunt.file.defaultEncoding = 'iso-8859-1'; + obj = grunt.file.readYAML('test/fixtures/iso-8859-1.yaml'); + test.deepEqual(obj, this.object, 'changing the default encoding should work.'); + test.done(); + }, + 'write': function(test) { + test.expect(6); + var tmpfile; + tmpfile = new Tempfile(); + grunt.file.write(tmpfile.path, this.string); + test.strictEqual(fs.readFileSync(tmpfile.path, 'utf8'), this.string, 'file should be written as utf8 by default.'); + tmpfile.unlinkSync(); + + tmpfile = new Tempfile(); + grunt.file.write(tmpfile.path, this.string, {encoding: 'iso-8859-1'}); + test.strictEqual(grunt.file.read(tmpfile.path, {encoding: 'iso-8859-1'}), this.string, 'file should be written using the specified encoding.'); + tmpfile.unlinkSync(); + + tmpfile = new Tempfile(); + tmpfile.unlinkSync(); + grunt.file.write(tmpfile.path, this.string, {mode: parseInt('0444', 8)}); + test.strictEqual(fs.statSync(tmpfile.path).mode & parseInt('0222', 8), 0, 'file should be read only.'); + fs.chmodSync(tmpfile.path, parseInt('0666', 8)); + tmpfile.unlinkSync(); + + grunt.file.defaultEncoding = 'iso-8859-1'; + tmpfile = new Tempfile(); + grunt.file.write(tmpfile.path, this.string); + grunt.file.defaultEncoding = 'utf8'; + test.strictEqual(grunt.file.read(tmpfile.path, {encoding: 'iso-8859-1'}), this.string, 'changing the default encoding should work.'); + tmpfile.unlinkSync(); + + tmpfile = new Tempfile(); + var octocat = fs.readFileSync('test/fixtures/octocat.png'); + grunt.file.write(tmpfile.path, octocat); + test.ok(compareBuffers(fs.readFileSync(tmpfile.path), octocat), 'buffers should always be written as-specified, with no attempt at re-encoding.'); + tmpfile.unlinkSync(); + + grunt.option('write', false); + var filepath = path.join(tmpdir.path, 'should-not-exist.txt'); + grunt.file.write(filepath, 'test'); + test.equal(grunt.file.exists(filepath), false, 'file should NOT be created if --no-write was specified.'); + test.done(); + }, + 'copy': function(test) { + test.expect(4); + var tmpfile; + tmpfile = new Tempfile(); + grunt.file.copy('test/fixtures/utf8.txt', tmpfile.path); + test.ok(compareFiles(tmpfile.path, 'test/fixtures/utf8.txt'), 'files should just be copied as encoding-agnostic by default.'); + tmpfile.unlinkSync(); + + tmpfile = new Tempfile(); + grunt.file.copy('test/fixtures/iso-8859-1.txt', tmpfile.path); + test.ok(compareFiles(tmpfile.path, 'test/fixtures/iso-8859-1.txt'), 'files should just be copied as encoding-agnostic by default.'); + tmpfile.unlinkSync(); + + tmpfile = new Tempfile(); + grunt.file.copy('test/fixtures/octocat.png', tmpfile.path); + test.ok(compareFiles(tmpfile.path, 'test/fixtures/octocat.png'), 'files should just be copied as encoding-agnostic by default.'); + tmpfile.unlinkSync(); + + grunt.option('write', false); + var filepath = path.join(tmpdir.path, 'should-not-exist.txt'); + grunt.file.copy('test/fixtures/utf8.txt', filepath); + test.equal(grunt.file.exists(filepath), false, 'file should NOT be created if --no-write was specified.'); + test.done(); + }, + 'copy and process': function(test) { + test.expect(14); + var tmpfile; + tmpfile = new Tempfile(); + grunt.file.copy('test/fixtures/utf8.txt', tmpfile.path, { + process: function(src, srcpath, destpath) { + test.equal(srcpath, 'test/fixtures/utf8.txt', 'srcpath should be passed in, as-specified.'); + test.equal(destpath, tmpfile.path, 'destpath should be passed in, as-specified.'); + test.equal(Buffer.isBuffer(src), false, 'when no encoding is specified, use default encoding and process src as a string'); + test.equal(typeof src, 'string', 'when no encoding is specified, use default encoding and process src as a string'); + return 'føø' + src + 'bår'; + } + }); + test.equal(grunt.file.read(tmpfile.path), 'føø' + this.string + 'bår', 'file should be saved as properly encoded processed string.'); + tmpfile.unlinkSync(); + + tmpfile = new Tempfile(); + grunt.file.copy('test/fixtures/iso-8859-1.txt', tmpfile.path, { + encoding: 'iso-8859-1', + process: function(src) { + test.equal(Buffer.isBuffer(src), false, 'use specified encoding and process src as a string'); + test.equal(typeof src, 'string', 'use specified encoding and process src as a string'); + return 'føø' + src + 'bår'; + } + }); + test.equal(grunt.file.read(tmpfile.path, {encoding: 'iso-8859-1'}), 'føø' + this.string + 'bår', 'file should be saved as properly encoded processed string.'); + tmpfile.unlinkSync(); + + tmpfile = new Tempfile(); + grunt.file.copy('test/fixtures/utf8.txt', tmpfile.path, { + encoding: null, + process: function(src) { + test.ok(Buffer.isBuffer(src), 'when encoding is specified as null, process src as a buffer'); + return Buffer.from('føø' + src.toString() + 'bår'); + } + }); + test.equal(grunt.file.read(tmpfile.path), 'føø' + this.string + 'bår', 'file should be saved as the buffer returned by process.'); + tmpfile.unlinkSync(); + + grunt.file.defaultEncoding = 'iso-8859-1'; + tmpfile = new Tempfile(); + grunt.file.copy('test/fixtures/iso-8859-1.txt', tmpfile.path, { + process: function(src) { + test.equal(Buffer.isBuffer(src), false, 'use non-utf8 default encoding and process src as a string'); + test.equal(typeof src, 'string', 'use non-utf8 default encoding and process src as a string'); + return 'føø' + src + 'bår'; + } + }); + test.equal(grunt.file.read(tmpfile.path), 'føø' + this.string + 'bår', 'file should be saved as properly encoded processed string.'); + tmpfile.unlinkSync(); + + var filepath = path.join(tmpdir.path, 'should-not-exist.txt'); + grunt.file.copy('test/fixtures/iso-8859-1.txt', filepath, { + process: function() { + return false; + } + }); + test.equal(grunt.file.exists(filepath), false, 'file should NOT be created if process returns false.'); + test.done(); + }, + 'copy and process, noprocess': function(test) { + test.expect(4); + var tmpfile; + tmpfile = new Tempfile(); + grunt.file.copy('test/fixtures/utf8.txt', tmpfile.path, { + noProcess: true, + process: function(src) { + return 'føø' + src + 'bår'; + } + }); + test.equal(grunt.file.read(tmpfile.path), this.string, 'file should not have been processed.'); + tmpfile.unlinkSync(); + + ['process', 'noprocess', 'othernoprocess'].forEach(function(filename) { + var filepath = path.join(tmpdir.path, filename); + grunt.file.copy('test/fixtures/utf8.txt', filepath); + var tmpfile = new Tempfile(); + grunt.file.copy(filepath, tmpfile.path, { + noProcess: ['**/*no*'], + process: function(src) { + return 'føø' + src + 'bår'; + } + }); + if (filename === 'process') { + test.equal(grunt.file.read(tmpfile.path), 'føø' + this.string + 'bår', 'file should have been processed.'); + } else { + test.equal(grunt.file.read(tmpfile.path), this.string, 'file should not have been processed.'); + } + tmpfile.unlinkSync(); + }, this); + + test.done(); + }, + 'copy directory recursively': function(test) { + test.expect(34); + var copyroot1 = path.join(tmpdir.path, 'copy-dir-1'); + var copyroot2 = path.join(tmpdir.path, 'copy-dir-2'); + grunt.file.copy('test/fixtures/expand/', copyroot1); + grunt.file.recurse('test/fixtures/expand/', function(srcpath, rootdir, subdir, filename) { + var destpath = path.join(copyroot1, subdir || '', filename); + test.ok(grunt.file.isFile(srcpath), 'file should have been copied.'); + test.equal(grunt.file.read(srcpath), grunt.file.read(destpath), 'file contents should be the same.'); + }); + grunt.file.mkdir(path.join(copyroot1, 'empty')); + grunt.file.mkdir(path.join(copyroot1, 'deep/deeper/empty')); + grunt.file.copy(copyroot1, copyroot2, { + process: function(contents) { + return '<' + contents + '>'; + }, + }); + test.ok(grunt.file.isDir(path.join(copyroot2, 'empty')), 'empty directory should have been created.'); + test.ok(grunt.file.isDir(path.join(copyroot2, 'deep/deeper/empty')), 'empty directory should have been created.'); + grunt.file.recurse('test/fixtures/expand/', function(srcpath, rootdir, subdir, filename) { + var destpath = path.join(copyroot2, subdir || '', filename); + test.ok(grunt.file.isFile(srcpath), 'file should have been copied.'); + test.equal('<' + grunt.file.read(srcpath) + '>', grunt.file.read(destpath), 'file contents should be processed correctly.'); + }); + test.done(); + }, + 'delete': function(test) { + test.expect(2); + var oldBase = process.cwd(); + var cwd = path.resolve(tmpdir.path, 'delete', 'folder'); + grunt.file.mkdir(cwd); + grunt.file.setBase(tmpdir.path); + + grunt.file.write(path.join(cwd, 'test.js'), 'var test;'); + test.ok(grunt.file.delete(cwd), 'should return true after deleting file.'); + test.equal(grunt.file.exists(cwd), false, 'file should have been deleted.'); + grunt.file.setBase(oldBase); + test.done(); + }, + 'delete nonexistent file': function(test) { + test.expect(2); + this.resetWarnCount(); + test.ok(!grunt.file.delete('nonexistent'), 'should return false if file does not exist.'); + test.ok(this.warnCount, 'should issue a warning when deleting non-existent file'); + test.done(); + }, + 'delete outside working directory': function(test) { + test.expect(4); + var oldBase = process.cwd(); + var cwd = path.resolve(tmpdir.path, 'delete', 'folder'); + var outsidecwd = path.resolve(tmpdir.path, 'delete', 'outsidecwd'); + grunt.file.mkdir(cwd); + grunt.file.mkdir(outsidecwd); + grunt.file.setBase(cwd); + + grunt.file.write(path.join(outsidecwd, 'test.js'), 'var test;'); + + this.resetWarnCount(); + test.equal(grunt.file.delete(path.join(outsidecwd, 'test.js')), false, 'should not delete anything outside the cwd.'); + test.ok(this.warnCount, 'should issue a warning when deleting outside working directory'); + + test.ok(grunt.file.delete(path.join(outsidecwd), {force: true}), 'should delete outside cwd when using the --force.'); + test.equal(grunt.file.exists(outsidecwd), false, 'file outside cwd should have been deleted when using the --force.'); + + grunt.file.setBase(oldBase); + test.done(); + }, + 'dont delete current working directory': function(test) { + test.expect(3); + var oldBase = process.cwd(); + var cwd = path.resolve(tmpdir.path, 'dontdelete', 'folder'); + grunt.file.mkdir(cwd); + grunt.file.setBase(cwd); + + this.resetWarnCount(); + test.equal(grunt.file.delete(cwd), false, 'should not delete the cwd.'); + test.ok(this.warnCount, 'should issue a warning when trying to delete cwd'); + + test.ok(grunt.file.exists(cwd), 'the cwd should exist.'); + + grunt.file.setBase(oldBase); + test.done(); + }, + 'dont actually delete with no-write option on': function(test) { + test.expect(2); + grunt.option('write', false); + + var oldBase = process.cwd(); + var cwd = path.resolve(tmpdir.path, 'dontdelete', 'folder'); + grunt.file.mkdir(cwd); + grunt.file.setBase(tmpdir.path); + + grunt.file.write(path.join(cwd, 'test.js'), 'var test;'); + test.ok(grunt.file.delete(cwd), 'should return true after not actually deleting file.'); + test.equal(grunt.file.exists(cwd), true, 'file should NOT be deleted if --no-write was specified.'); + grunt.file.setBase(oldBase); + + test.done(); + }, + 'mkdir': function(test) { + test.expect(5); + test.doesNotThrow(function() { + grunt.file.mkdir(tmpdir.path); + }, 'Should not explode if the directory already exists.'); + test.ok(fs.existsSync(tmpdir.path), 'path should still exist.'); + + test.doesNotThrow(function() { + grunt.file.mkdir(path.join(tmpdir.path, 'aa/bb/cc')); + }, 'Should also not explode, otherwise.'); + test.ok(path.join(tmpdir.path, 'aa/bb/cc'), 'path should have been created.'); + + fs.writeFileSync(path.join(tmpdir.path, 'aa/bb/xx'), 'test'); + test.throws(function() { + grunt.file.mkdir(path.join(tmpdir.path, 'aa/bb/xx/yy')); + }, 'Should throw if a path cannot be created (ENOTDIR).'); + + test.done(); + }, + 'recurse': function(test) { + test.expect(1); + var rootdir = 'test/fixtures/expand'; + var expected = {}; + expected[rootdir + '/css/baz.css'] = [rootdir, 'css', 'baz.css']; + expected[rootdir + '/css/qux.css'] = [rootdir, 'css', 'qux.css']; + expected[rootdir + '/deep/deep.txt'] = [rootdir, 'deep', 'deep.txt']; + expected[rootdir + '/deep/deeper/deeper.txt'] = [rootdir, 'deep/deeper', 'deeper.txt']; + expected[rootdir + '/deep/deeper/deepest/deepest.txt'] = [rootdir, 'deep/deeper/deepest', 'deepest.txt']; + expected[rootdir + '/js/bar.js'] = [rootdir, 'js', 'bar.js']; + expected[rootdir + '/js/foo.js'] = [rootdir, 'js', 'foo.js']; + expected[rootdir + '/README.md'] = [rootdir, undefined, 'README.md']; + + var actual = {}; + grunt.file.recurse(rootdir, function(abspath, rootdir, subdir, filename) { + actual[abspath] = [rootdir, subdir, filename]; + }); + + test.deepEqual(actual, expected, 'paths and arguments should match.'); + test.done(); + }, + 'exists': function(test) { + test.expect(6); + test.ok(grunt.file.exists('test/fixtures/octocat.png'), 'files exist.'); + test.ok(grunt.file.exists('test', 'fixtures', 'octocat.png'), 'should work for paths in parts.'); + test.ok(grunt.file.exists('test/fixtures'), 'directories exist.'); + test.ok(grunt.file.exists(path.join(tmpdir.path, 'octocat.png')), 'file links exist.'); + test.ok(grunt.file.exists(path.join(tmpdir.path, 'expand')), 'directory links exist.'); + test.equal(grunt.file.exists('test/fixtures/does/not/exist'), false, 'nonexistent files do not exist.'); + test.done(); + }, + 'isLink': function(test) { + test.expect(8); + test.equals(grunt.file.isLink('test/fixtures/octocat.png'), false, 'files are not links.'); + test.equals(grunt.file.isLink('test/fixtures'), false, 'directories are not links.'); + test.ok(grunt.file.isLink(path.join(tmpdir.path, 'octocat.png')), 'file links are links.'); + test.ok(grunt.file.isLink(path.join(tmpdir.path, 'expand')), 'directory links are links.'); + grunt.file.mkdir(path.join(tmpdir.path, 'relative-links')); + fs.symlinkSync('test/fixtures/octocat.png', path.join(tmpdir.path, 'relative-links/octocat.png'), 'file'); + fs.symlinkSync('test/fixtures/expand', path.join(tmpdir.path, 'relative-links/expand'), 'file'); + test.ok(grunt.file.isLink(path.join(tmpdir.path, 'relative-links/octocat.png')), 'relative file links are links.'); + test.ok(grunt.file.isLink(path.join(tmpdir.path, 'relative-links/expand')), 'relative directory links are links.'); + test.ok(grunt.file.isLink(tmpdir.path, 'octocat.png'), 'should work for paths in parts.'); + test.equals(grunt.file.isLink('test/fixtures/does/not/exist'), false, 'nonexistent files are not links.'); + test.done(); + }, + 'isDir': function(test) { + test.expect(6); + test.equals(grunt.file.isDir('test/fixtures/octocat.png'), false, 'files are not directories.'); + test.ok(grunt.file.isDir('test/fixtures'), 'directories are directories.'); + test.ok(grunt.file.isDir('test', 'fixtures'), 'should work for paths in parts.'); + test.equals(grunt.file.isDir(path.join(tmpdir.path, 'octocat.png')), false, 'file links are not directories.'); + test.ok(grunt.file.isDir(path.join(tmpdir.path, 'expand')), 'directory links are directories.'); + test.equals(grunt.file.isDir('test/fixtures/does/not/exist'), false, 'nonexistent files are not directories.'); + test.done(); + }, + 'isFile': function(test) { + test.expect(6); + test.ok(grunt.file.isFile('test/fixtures/octocat.png'), 'files are files.'); + test.ok(grunt.file.isFile('test', 'fixtures', 'octocat.png'), 'should work for paths in parts.'); + test.equals(grunt.file.isFile('test/fixtures'), false, 'directories are not files.'); + test.ok(grunt.file.isFile(path.join(tmpdir.path, 'octocat.png')), 'file links are files.'); + test.equals(grunt.file.isFile(path.join(tmpdir.path, 'expand')), false, 'directory links are not files.'); + test.equals(grunt.file.isFile('test/fixtures/does/not/exist'), false, 'nonexistent files are not files.'); + test.done(); + }, + 'isPathAbsolute': function(test) { + test.expect(6); + test.ok(grunt.file.isPathAbsolute(path.resolve('/foo')), 'should return true'); + test.ok(grunt.file.isPathAbsolute(path.resolve('/foo') + path.sep), 'should return true'); + test.equal(grunt.file.isPathAbsolute('foo'), false, 'should return false'); + test.ok(grunt.file.isPathAbsolute(path.resolve('test/fixtures/a.js')), 'should return true'); + test.equal(grunt.file.isPathAbsolute('test/fixtures/a.js'), false, 'should return false'); + if (win32) { + test.equal(grunt.file.isPathAbsolute('C:/Users/'), true, 'should return true'); + } else { + test.equal(grunt.file.isPathAbsolute('/'), true, 'should return true'); + } + test.done(); + }, + 'arePathsEquivalent': function(test) { + test.expect(5); + test.ok(grunt.file.arePathsEquivalent('/foo'), 'should return true'); + test.ok(grunt.file.arePathsEquivalent('/foo', '/foo/', '/foo/../foo/'), 'should return true'); + test.ok(grunt.file.arePathsEquivalent(process.cwd(), '.', './', 'test/..'), 'should return true'); + test.equal(grunt.file.arePathsEquivalent(process.cwd(), '..'), false, 'should return false'); + test.equal(grunt.file.arePathsEquivalent('.', '..'), false, 'should return false'); + test.done(); + }, + 'doesPathContain': function(test) { + test.expect(6); + test.ok(grunt.file.doesPathContain('/foo', '/foo/bar'), 'should return true'); + test.ok(grunt.file.doesPathContain('/foo/', '/foo/bar/baz', '/foo/bar', '/foo/whatever'), 'should return true'); + test.equal(grunt.file.doesPathContain('/foo', '/foo'), false, 'should return false'); + test.equal(grunt.file.doesPathContain('/foo/xyz', '/foo/xyz/123', '/foo/bar/baz'), false, 'should return false'); + test.equal(grunt.file.doesPathContain('/foo/xyz', '/foo'), false, 'should return false'); + test.ok(grunt.file.doesPathContain(process.cwd(), 'test', 'test/fixtures', 'lib'), 'should return true'); + test.done(); + }, + 'isPathCwd': function(test) { + test.expect(8); + test.ok(grunt.file.isPathCwd(process.cwd()), 'cwd is cwd'); + test.ok(grunt.file.isPathCwd('.'), 'cwd is cwd'); + test.equal(grunt.file.isPathCwd('test'), false, 'subdirectory is not cwd'); + test.equal(grunt.file.isPathCwd(path.resolve('test')), false, 'subdirectory is not cwd'); + test.equal(grunt.file.isPathCwd('..'), false, 'parent is not cwd'); + test.equal(grunt.file.isPathCwd(path.resolve('..')), false, 'parent is not cwd'); + test.equal(grunt.file.isPathCwd('/'), false, 'root is not cwd (I hope)'); + test.equal(grunt.file.isPathCwd('nonexistent'), false, 'nonexistent path is not cwd'); + test.done(); + }, + 'isPathInCwd': function(test) { + test.expect(8); + test.equal(grunt.file.isPathInCwd(process.cwd()), false, 'cwd is not IN cwd'); + test.equal(grunt.file.isPathInCwd('.'), false, 'cwd is not IN cwd'); + test.ok(grunt.file.isPathInCwd('test'), 'subdirectory is in cwd'); + test.ok(grunt.file.isPathInCwd(path.resolve('test')), 'subdirectory is in cwd'); + test.equal(grunt.file.isPathInCwd('..'), false, 'parent is not in cwd'); + test.equal(grunt.file.isPathInCwd(path.resolve('..')), false, 'parent is not in cwd'); + test.equal(grunt.file.isPathInCwd('/'), false, 'root is not in cwd (I hope)'); + test.equal(grunt.file.isPathInCwd('nonexistent'), false, 'nonexistent path is not in cwd'); + test.done(); + }, 'cwdUnderSymlink': { setUp: function(done) { this.cwd = process.cwd(); @@ -881,49 +881,49 @@ exports.file = { process.chdir(this.cwd); done(); }, - // 'isPathCwd': function(test) { - // test.expect(2); - // test.ok(grunt.file.isPathCwd(process.cwd()), 'cwd is cwd'); - // test.ok(grunt.file.isPathCwd('.'), 'cwd is cwd'); - // test.done(); - // }, - // 'isPathInCwd': function(test) { - // test.expect(2); - // test.ok(grunt.file.isPathInCwd('deep'), 'subdirectory is in cwd'); - // test.ok(grunt.file.isPathInCwd(path.resolve('deep')), 'subdirectory is in cwd'); - // test.done(); - // }, - // 'symbolicLinkCopy': function(test) { - // test.expect(4); - // var srcfile = new Tempdir(); - // fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(srcfile.path, 'octocat.png'), 'file'); - // // test symlink copy for files - // var destdir = new Tempdir(); - // grunt.file.copy(path.join(srcfile.path, 'octocat.png'), path.join(destdir.path, 'octocat.png')); - // test.ok(fs.lstatSync(path.join(srcfile.path, 'octocat.png')).isSymbolicLink()); - // test.ok(fs.lstatSync(path.join(destdir.path, 'octocat.png')).isSymbolicLink()); - - // // test symlink copy for directories - // var srcdir = new Tempdir(); - // var destdir = new Tempdir(); - // var fixtures = path.resolve('test/fixtures'); - // var symlinkSource = path.join(srcdir.path, path.basename(fixtures)); - // var destSource = path.join(destdir.path, path.basename(fixtures)); - // fs.symlinkSync(fixtures, symlinkSource, 'dir'); - - // grunt.file.copy(symlinkSource, destSource); - // test.ok(fs.lstatSync(symlinkSource).isSymbolicLink()); - // test.ok(fs.lstatSync(path.join(destdir.path, path.basename(fixtures))).isSymbolicLink()); - // test.done(); - // }, - 'symbolicLinkDestError': function(test) { - test.expect(1); - var tmpfile = new Tempdir(); - fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(tmpfile.path, 'octocat.png'), 'file'); - grunt.file.copy(path.resolve('../octocat.png'), path.join(tmpfile.path, 'octocat.png')); - console.log(tmpfile.path); - test.ok(fs.lstatSync(path.join(tmpfile.path, 'octocat.png')).isSymbolicLink()); + 'isPathCwd': function(test) { + test.expect(2); + test.ok(grunt.file.isPathCwd(process.cwd()), 'cwd is cwd'); + test.ok(grunt.file.isPathCwd('.'), 'cwd is cwd'); test.done(); }, - } + 'isPathInCwd': function(test) { + test.expect(2); + test.ok(grunt.file.isPathInCwd('deep'), 'subdirectory is in cwd'); + test.ok(grunt.file.isPathInCwd(path.resolve('deep')), 'subdirectory is in cwd'); + test.done(); + }, + 'symbolicLinkCopy': function(test) { + test.expect(4); + var srcfile = new Tempdir(); + fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(srcfile.path, 'octocat.png'), 'file'); + // test symlink copy for files + var destdir = new Tempdir(); + grunt.file.copy(path.join(srcfile.path, 'octocat.png'), path.join(destdir.path, 'octocat.png')); + test.ok(fs.lstatSync(path.join(srcfile.path, 'octocat.png')).isSymbolicLink()); + test.ok(fs.lstatSync(path.join(destdir.path, 'octocat.png')).isSymbolicLink()); + + // test symlink copy for directories + var srcdir = new Tempdir(); + var destdir = new Tempdir(); + var fixtures = path.resolve('test/fixtures'); + var symlinkSource = path.join(srcdir.path, path.basename(fixtures)); + var destSource = path.join(destdir.path, path.basename(fixtures)); + fs.symlinkSync(fixtures, symlinkSource, 'dir'); + + grunt.file.copy(symlinkSource, destSource); + test.ok(fs.lstatSync(symlinkSource).isSymbolicLink()); + test.ok(fs.lstatSync(path.join(destdir.path, path.basename(fixtures))).isSymbolicLink()); + test.done(); + }, + }, + 'symbolicLinkDestError': function(test) { + test.expect(1); + var tmpfile = new Tempdir(); + fs.symlinkSync(path.resolve('test/fixtures/octocat.png'), path.join(tmpfile.path, 'octocat.png'), 'file'); + grunt.file.copy(path.resolve('test/fixtures/octocat.png'), path.join(tmpfile.path, 'octocat.png')); + console.log(tmpfile.path); + test.ok(fs.lstatSync(path.join(tmpfile.path, 'octocat.png')).isSymbolicLink()); + test.done(); + }, };