cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject cordova-lib git commit: Fix four failing tests on Windows.
Date Wed, 03 Jun 2015 01:04:29 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master dff78b077 -> 0b103f16c


Fix four failing tests on Windows.

Two tests fail in a non-admin command window because they rely on creating symlinks. Since
creating the symlinks isn't the purpose of the test but just setup for the test, if that fails
and the platform is win32, we now just bail on the test.

Another test failed because a folder unexpectedly exists when run from a non-admin prompt.
I'm not 100% sure why the folder exists, but the test was actually bogus... the test was actually
ends up testing that we throw if src does not exist (something that we verify in an earlier
test), while the intent was to verify we throw if dest *already* exists. It is copyNewFile()
that throws in that scenario, so I updated the test to check for that.

Finally, a fourth test failed on Windows (admin or non-admin) because of different line endings.
Changed that to handle any line ending.


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/0b103f16
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/0b103f16
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/0b103f16

Branch: refs/heads/master
Commit: 0b103f16c4d301611a3cfd6fea967effe880f652
Parents: dff78b0
Author: Tim Barham <tim.barham@microsoft.com>
Authored: Tue Jun 2 16:22:11 2015 -0700
Committer: Tim Barham <tim.barham@microsoft.com>
Committed: Tue Jun 2 17:36:52 2015 -0700

----------------------------------------------------------------------
 .../spec-plugman/platforms/android.spec.js      |  2 +-
 .../spec-plugman/platforms/common.spec.js       | 42 ++++++++++++++++----
 2 files changed, 35 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/0b103f16/cordova-lib/spec-plugman/platforms/android.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/platforms/android.spec.js b/cordova-lib/spec-plugman/platforms/android.spec.js
index 4fabc80..2af8fc5 100644
--- a/cordova-lib/spec-plugman/platforms/android.spec.js
+++ b/cordova-lib/spec-plugman/platforms/android.spec.js
@@ -137,7 +137,7 @@ describe('android project handler', function() {
             var finalProjectProperties = fs.readFileSync(mainProjectPropsFile, 'utf8');
             expect(finalProjectProperties).toMatch('\nandroid.library.reference.3='+dummy_id+'/'+packageIdSuffix+'-plugin-lib',
'Reference to library not added');
             var subProjectProperties = fs.readFileSync(subProjectPropsFile, 'utf8');
-            expect(subProjectProperties).toMatch(/\btarget=android-19\n/, 'target SDK version
not copied to library');
+            expect(subProjectProperties).toMatch(/\btarget=android-19$/m, 'target SDK version
not copied to library');
             expect(exec).toHaveBeenCalledWith('android update lib-project --path "' + subDir
+ '"');
 
             // Now test uninstall

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/0b103f16/cordova-lib/spec-plugman/platforms/common.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-plugman/platforms/common.spec.js b/cordova-lib/spec-plugman/platforms/common.spec.js
index 408f070..8b8ed18 100644
--- a/cordova-lib/spec-plugman/platforms/common.spec.js
+++ b/cordova-lib/spec-plugman/platforms/common.spec.js
@@ -72,7 +72,12 @@ describe('common platform handler', function() {
         it('should allow symlink src, if inside plugin', function(){
             shell.mkdir('-p', java_dir);
             fs.writeFileSync(java_file, 'contents', 'utf-8');
-            fs.symlinkSync(java_file, symlink_file);
+
+            // This will fail on windows if not admin - ignore the error in that case.
+            if (ignoreEPERMonWin32(java_file, symlink_file)) {
+                return;
+            }
+
             common.copyFile(test_dir, symlink_file, project_dir, dest);
             shell.rm('-rf', project_dir);
         });
@@ -80,18 +85,17 @@ describe('common platform handler', function() {
         it('should throw if symlink is linked to a file outside the plugin', function(){
             shell.mkdir('-p', java_dir);
             fs.writeFileSync(non_plugin_file, 'contents', 'utf-8');
-            fs.symlinkSync(non_plugin_file, symlink_file);
+
+            // This will fail on windows if not admin - ignore the error in that case.
+            if (ignoreEPERMonWin32(non_plugin_file, symlink_file)) {
+                return;
+            }
+
             expect(function(){common.copyFile(test_dir, symlink_file, project_dir, dest);}).
                 toThrow(new Error('"' + symlink_file + '" not located within plugin!'));
             shell.rm('-rf', project_dir);
         });
 
-        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 throw if dest is outside the project directory', function(){
             shell.mkdir('-p', java_dir);
             fs.writeFileSync(java_file, 'contents', 'utf-8');
@@ -131,6 +135,16 @@ describe('common platform handler', function() {
 
     });
 
+    describe('copyNewFile', function () {
+        it('should throw if target path exists', function(){
+            shell.mkdir('-p', dest);
+            expect(function(){common.copyNewFile(test_dir, src, project_dir, dest);}).
+                toThrow(new Error('"' + dest + '" already exists!'));
+            shell.rm('-rf', dest);
+        });
+
+    });
+
     describe('deleteJava', function() {
         it('should call fs.unlinkSync on the provided paths', function(){
             shell.mkdir('-p', java_dir);
@@ -167,3 +181,15 @@ describe('common platform handler', function() {
         });
     });
 });
+
+function ignoreEPERMonWin32(symlink_src, symlink_dest) {
+    try {
+        fs.symlinkSync(symlink_src, symlink_dest);
+    } catch (e) {
+        if (process.platform === 'win32' && e.message.indexOf('Error: EPERM, operation
not permitted' > -1)) {
+            return true;
+        }
+        throw e;
+    }
+    return false;
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message