You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2013/04/25 00:28:39 UTC
git commit: merged changes to common tests and common.js
Updated Branches:
refs/heads/master 372b0a3a2 -> da57c83a1
merged changes to common tests and common.js
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugman/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugman/commit/da57c83a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugman/tree/da57c83a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugman/diff/da57c83a
Branch: refs/heads/master
Commit: da57c83a14871bd8a0ff546fe62e95f7aad20a9a
Parents: 372b0a3
Author: Tim Kim <ti...@adobe.com>
Authored: Wed Apr 24 15:18:16 2013 -0700
Committer: Tim Kim <ti...@adobe.com>
Committed: Wed Apr 24 15:28:32 2013 -0700
----------------------------------------------------------------------
spec/platforms/common.spec.js | 130 ++++++++++++++++++++++++++++++++----
src/platforms/common.js | 6 +-
2 files changed, 121 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/da57c83a/spec/platforms/common.spec.js
----------------------------------------------------------------------
diff --git a/spec/platforms/common.spec.js b/spec/platforms/common.spec.js
index 65f8077..2f54458 100644
--- a/spec/platforms/common.spec.js
+++ b/spec/platforms/common.spec.js
@@ -1,26 +1,130 @@
-var common = require('../../src/platforms/common');
+/*
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+var common = require('../../src/platforms/common')
+ , path = require('path')
+ , fs = require('fs')
+ , osenv = require('osenv')
+ , shell = require('shelljs')
+ , test_dir = path.join(osenv.tmpdir(), 'test_plugman')
+ , project_dir = path.join(test_dir, 'project')
+ , src = path.join(project_dir, 'src')
+ , dest = path.join(project_dir, 'dest')
+ , java_dir = path.join(src, 'one', 'two', 'three')
+ , java_file = path.join(java_dir, 'test.java');
describe('common platform handler', function() {
describe('resolveSrcPath', function() {
- it('should throw if path cannot be resolved');
- it('should not throw if path exists');
+ it('should throw if path cannot be resolved', function(){
+ expect(function(){common.resolveSrcPath(test_dir, 'I_dont_exist')}).toThrow();
+ });
+ it('should not throw if path exists', function(){
+ shell.mkdir('-p', test_dir);
+ expect(function(){common.resolveSrcPath(test_dir)}).not.toThrow();
+ shell.rm('-rf', test_dir);
+ });
});
describe('resolveTargetPath', function() {
- it('should throw if path exists');
- it('should not throw if path cannot be resolved');
+ it('should throw if path exists', function(){
+ shell.mkdir('-p', test_dir);
+ expect(function(){common.resolveTargetPath(test_dir)}).toThrow();
+ shell.rm('-rf', test_dir);
+ });
+ it('should not throw if path cannot be resolved', function(){
+ expect(function(){common.resolveTargetPath(test_dir)}).not.toThrow();
+ });
});
- describe('copyFile', function() {
- it('should throw if source path cannot be resolved');
- it('should throw if target path exists');
- it('should call mkdir -p on target path');
- it('should call cp with source/dest paths');
+ describe('copyFile', function() {
+ it('should throw if source path cannot be resolved', function(){
+ expect(function(){common.copyFile(test_dir, src, project_dir, dest)}).toThrow();
+ });
+
+ it('should throw if target path exists', function(){
+ shell.mkdir('-p', dest);
+ expect(function(){common.copyFile(test_dir, src, project_dir, dest)}).toThrow();
+ shell.rm('-rf', dest);
+ });
+
+ it('should call mkdir -p on target path', function(){
+ shell.mkdir('-p', java_dir);
+ fs.writeFileSync(java_file, 'contents', 'utf-8');
+
+ var s = spyOn(shell, 'mkdir').andCallThrough();
+ var resolvedDest = common.resolveTargetPath(project_dir, dest);
+
+ common.copyFile(test_dir, java_file, project_dir, dest);
+
+ expect(s).toHaveBeenCalled();
+ expect(s).toHaveBeenCalledWith('-p', path.dirname(resolvedDest));
+ shell.rm('-rf', project_dir);
+ });
+
+ it('should call cp -f source/dest paths', function(){
+ shell.mkdir('-p', java_dir);
+ fs.writeFileSync(java_file, 'contents', 'utf-8');
+
+ var s = spyOn(shell, 'cp').andCallThrough();
+ var resolvedDest = common.resolveTargetPath(project_dir, dest);
+
+ common.copyFile(test_dir, java_file, project_dir, dest);
+
+ expect(s).toHaveBeenCalled();
+ expect(s).toHaveBeenCalledWith(java_file, resolvedDest);
+
+ shell.rm('-rf', project_dir);
+ });
+
});
describe('deleteJava', function() {
- it('should call fs.unlinkSync on the provided paths');
- it('should delete empty directories after removing source code in a java src path heirarchy');
- it('should never delete the top-level src directory, even if all plugins added were removed');
+ it('should call fs.unlinkSync on the provided paths', function(){
+ shell.mkdir('-p', java_dir);
+ fs.writeFileSync(java_file, 'contents', 'utf-8');
+
+ var s = spyOn(fs, 'unlinkSync').andCallThrough();
+ common.deleteJava(project_dir, java_file);
+ expect(s).toHaveBeenCalled();
+ expect(s).toHaveBeenCalledWith(path.resolve(project_dir, java_file));
+
+ shell.rm('-rf', java_dir);
+ });
+
+ it('should delete empty directories after removing source code in a java src path heirarchy', function(){
+ shell.mkdir('-p', java_dir);
+ fs.writeFileSync(java_file, 'contents', 'utf-8');
+
+ common.deleteJava(project_dir, java_file);
+ expect(fs.existsSync(java_file)).not.toBe(true);
+ expect(fs.existsSync(java_dir)).not.toBe(true);
+ expect(fs.existsSync(path.join(src,'one'))).not.toBe(true);
+
+ shell.rm('-rf', java_dir);
+ });
+
+ it('should never delete the top-level src directory, even if all plugins added were removed', function(){
+ shell.mkdir('-p', java_dir);
+ fs.writeFileSync(java_file, 'contents', 'utf-8');
+
+ common.deleteJava(project_dir, java_file);
+ expect(fs.existsSync(src)).toBe(true);
+
+ shell.rm('-rf', java_dir);
+ });
});
});
http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/da57c83a/src/platforms/common.js
----------------------------------------------------------------------
diff --git a/src/platforms/common.js b/src/platforms/common.js
index fe2bc4f..8c1897c 100644
--- a/src/platforms/common.js
+++ b/src/platforms/common.js
@@ -28,8 +28,10 @@ module.exports = {
deleteJava:function(project_dir, destFile) {
fs.unlinkSync(path.resolve(project_dir,destFile));
// check if directory is empty
- var curDir = path.resolve(project_dir, path.basename(destFile));
+
+ var curDir = path.resolve(project_dir, path.dirname(destFile));
while(curDir !== path.resolve(project_dir, 'src')) {
+ //console.log('curDir ' + curDir);
if(fs.readdirSync(curDir).length == 0) {
fs.rmdirSync(curDir);
curDir = path.resolve(curDir, '..');
@@ -37,6 +39,6 @@ module.exports = {
// directory not empty...do nothing
break;
}
- }
+ }
}
};