Skip to content

Instantly share code, notes, and snippets.

@oravecz
Created November 22, 2010 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oravecz/709432 to your computer and use it in GitHub Desktop.
Save oravecz/709432 to your computer and use it in GitHub Desktop.
Patch to fix all but one test on Windows.
Index: test/ringo/utils/files_test.js
===================================================================
--- test/ringo/utils/files_test.js (revision c20dd50ab9e7fd0d6ce3bf53136f22eb13cda60b)
+++ test/ringo/utils/files_test.js (revision )
@@ -8,29 +8,35 @@
const FOO = 'foo';
exports.testResolveUri = function () {
- assert.strictEqual(PARENT + INVALID_CHILD, files.resolveUri(PARENT,
- INVALID_CHILD)); // Should work for both child notations.
- assert.strictEqual(PARENT + INVALID_CHILD, files.resolveUri(PARENT,
- VALID_CHILD));
- assert.strictEqual(PARENT + FOO, files.resolveUri(PARENT, VALID_CHILD, FOO));
+ // Should work for both child notations.
+ assert.strictEqual(files.normalizePathSeparator(PARENT + INVALID_CHILD),
+ files.normalizePathSeparator(files.resolveUri(PARENT, INVALID_CHILD)));
+ assert.strictEqual(files.normalizePathSeparator(PARENT + INVALID_CHILD),
+ files.normalizePathSeparator(files.resolveUri(PARENT, VALID_CHILD)));
+ assert.strictEqual(files.normalizePathSeparator(PARENT + FOO),
+ files.normalizePathSeparator(files.resolveUri(PARENT, VALID_CHILD, FOO)));
};
exports.testResolveId = function () {
- assert.strictEqual(fs.resolve(PARENT, VALID_CHILD), files.resolveId(
- PARENT, VALID_CHILD)); // Child must start w/ ".".
- assert.notStrictEqual(fs.resolve(PARENT, INVALID_CHILD), files.
- resolveId(PARENT, INVALID_CHILD));
- assert.strictEqual(INVALID_CHILD, files.resolveId(PARENT,
- INVALID_CHILD)); // Otherwise return child (unchanged).
+ // Child must start w/ ".".
+ assert.strictEqual(files.normalizePathSeparator(fs.resolve(PARENT, VALID_CHILD)),
+ files.normalizePathSeparator(files.resolveId(PARENT, VALID_CHILD)));
+ assert.notStrictEqual(files.normalizePathSeparator(fs.resolve(PARENT, INVALID_CHILD)),
+ files.normalizePathSeparator(files.resolveId(PARENT, INVALID_CHILD)));
+ // Otherwise return child (unchanged).
+ assert.strictEqual(files.normalizePathSeparator(INVALID_CHILD),
+ files.normalizePathSeparator(files.resolveId(PARENT, INVALID_CHILD)));
};
exports.testCreateTempFile = function () {
var tempFile = files.createTempFile('ringo');
assert.isNotNull(tempFile); // Creation w/ prefix only.
+ tempFile = files.normalizePathSeparator(tempFile);
assert.isTrue(/^.*\/ringo.*$/.test(tempFile));
fs.remove(tempFile);
tempFile = files.createTempFile('ringo', '.js');
assert.isNotNull(tempFile); // Creation incl. suffix.
+ tempFile = files.normalizePathSeparator(tempFile);
assert.isTrue(/^.*\/ringo.*\.js$/.test(tempFile));
fs.remove(tempFile);
assert.throws(function () files.createTempFile('ri'), java.lang.
Index: test/file/relative.js
===================================================================
--- test/file/relative.js (revision c20dd50ab9e7fd0d6ce3bf53136f22eb13cda60b)
+++ test/file/relative.js (revision )
@@ -1,4 +1,5 @@
var assert = require("assert");
+var files = require('ringo/utils/files');
var fs = require('fs');
var tests = [
@@ -20,7 +21,7 @@
var name = '"' + source + '" -> "' + target + '" = "' + expected + '"';
exports['test ' + name] = function () {
var actual = fs.relative(source, target);
- assert.strictEqual(expected, actual);
+ assert.strictEqual(expected, files.normalizePathSeparator(actual));
};
});
Index: modules/ringo/utils/files.js
===================================================================
--- modules/ringo/utils/files.js (revision c20dd50ab9e7fd0d6ce3bf53136f22eb13cda60b)
+++ modules/ringo/utils/files.js (revision )
@@ -5,7 +5,7 @@
var arrays = require('ringo/utils/arrays');
var fs = require('fs');
-export ('resolveUri', 'resolveId', 'isHidden', 'createTempFile', 'roots', 'separator');
+export ('resolveUri', 'resolveId', 'isHidden', 'createTempFile', 'roots', 'separator', 'normalizePathSeparator');
var File = java.io.File;
@@ -122,3 +122,6 @@
*/
var separator = File.separator;
+function normalizePathSeparator(path) {
+ return path.replace('\\', '/', 'g');
+}
\ No newline at end of file
Index: test/repository/common.js
===================================================================
--- test/repository/common.js (revision c20dd50ab9e7fd0d6ce3bf53136f22eb13cda60b)
+++ test/repository/common.js (revision )
@@ -1,4 +1,5 @@
var assert = require("assert");
+var files = require('ringo/utils/files');
var {absolute, join} = require("fs");
var strings = require("ringo/utils/strings");
@@ -9,7 +10,8 @@
assert.strictEqual(res.name, "test.txt");
assert.isTrue(res.exists());
assert.strictEqual(res.baseName, "test");
- assert.strictEqual(res.path, absolute(join(path, "test.txt")));
+ assert.strictEqual(files.normalizePathSeparator(res.path),
+ files.normalizePathSeparator(absolute(join(path, "test.txt"))));
assert.strictEqual(res.content, "hello world!");
};
@@ -18,9 +20,11 @@
assert.strictEqual(res.name, "nested.txt");
assert.isTrue(res.exists());
assert.strictEqual(res.baseName, "nested");
- assert.strictEqual(res.path, absolute(join(path, "nested", "nested.txt")));
- assert.strictEqual(res.length, 2240);
- assert.strictEqual(res.content.length, 2240);
+ assert.strictEqual(files.normalizePathSeparator(res.path),
+ files.normalizePathSeparator(absolute(join(path, "nested", "nested.txt"))));
+ // The number of characters varies on Windows because of two EOL characters
+ assert.isTrue(res.length === 2240 || res.length === 2274);
+ assert.isTrue(res.content.length === 2240 || res.content.length === 2274);
assert.isTrue(strings.startsWith(res.content, "Lorem ipsum dolor sit amet"));
assert.isTrue(strings.endsWith(res.content.trim(), "id est laborum."));
};
@@ -57,10 +61,12 @@
res = res.sort(function(a, b) a.length > b.length);
assert.strictEqual(res[0].name, "test.txt");
assert.strictEqual(res[0].relativePath, "test.txt");
- assert.strictEqual(res[0].path, absolute(join(path, "test.txt")));
+ assert.strictEqual(files.normalizePathSeparator(res[0].path),
+ files.normalizePathSeparator(absolute(join(path, "test.txt"))));
assert.strictEqual(res[1].name, "nested.txt");
assert.strictEqual(res[1].relativePath, "nested/nested.txt");
- assert.strictEqual(res[1].path, absolute(join(path, "nested/nested.txt")));
+ assert.strictEqual(files.normalizePathSeparator(res[1].path),
+ files.normalizePathSeparator(absolute(join(path, "nested/nested.txt"))));
}
exports.testGetNestedResources = function() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment