Merge pull request #870 from AndrewGaspar/moduletests

tests now run with module flag set to commonjs
This commit is contained in:
Diullei Gomes
2013-08-16 19:21:40 -07:00
4 changed files with 95 additions and 19 deletions
+50 -4
View File
@@ -1,4 +1,18 @@
var ExecResult = (function () {
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// 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 ExecResult = (function () {
function ExecResult() {
this.stdout = "";
this.stderr = "";
@@ -63,8 +77,23 @@ var Exec = (function () {
return new NodeExec();
}
})();
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// 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 IOUtils;
(function (IOUtils) {
// Creates the directory including its parent if not already present
function createDirectoryStructure(ioHost, dirName) {
if (ioHost.directoryExists(dirName)) {
return;
@@ -77,6 +106,7 @@ var IOUtils;
ioHost.createDirectory(dirName);
}
// Creates a file including its directory structure if not already present
function createFileAndFolderStructure(ioHost, fileName, useUTF8) {
var path = ioHost.resolvePath(fileName);
var dirName = ioHost.dirName(path);
@@ -96,6 +126,8 @@ var IOUtils;
})(IOUtils || (IOUtils = {}));
var IO = (function () {
// Create an IO object for use inside WindowsScriptHost hosts
// Depends on WSCript and FileSystemObject
function getWindowsScriptHostIO() {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var streamObjectPool = [];
@@ -133,6 +165,7 @@ var IO = (function () {
streamObj.Charset = 'utf-8';
}
// Read the whole file
var str = streamObj.ReadText(-1);
streamObj.Close();
releaseStreamObject(streamObj);
@@ -164,6 +197,7 @@ var IO = (function () {
var content = this.readFile(path);
return { content: content, path: path };
} catch (err) {
//Tools.CompilerDiagnostics.debugPrint("Could not find " + path + ", trying parent");
}
} else {
rootPath = fso.GetParentFolderName(fso.GetAbsolutePathName(rootPath));
@@ -287,6 +321,8 @@ var IO = (function () {
}
;
// Create an IO object for use inside Node.js hosts
// Depends on 'fs' and 'path' modules
function getNodeIO() {
var _fs = require('fs');
var _path = require('path');
@@ -299,6 +335,8 @@ var IO = (function () {
switch (buffer[0]) {
case 0xFE:
if (buffer[1] == 0xFF) {
// utf16-be. Reading the buffer as big endian is not supported, so convert it to
// Little Endian first
var i = 0;
while ((i + 1) < buffer.length) {
var temp = buffer[i];
@@ -311,15 +349,18 @@ var IO = (function () {
break;
case 0xFF:
if (buffer[1] == 0xFE) {
// utf16-le
return buffer.toString("ucs2", 2);
}
break;
case 0xEF:
if (buffer[1] == 0xBB) {
// utf-8
return buffer.toString("utf8", 3);
}
}
// Default behaviour
return buffer.toString();
} catch (e) {
IOUtils.throwIOError("Error reading file \"" + file + "\".", e);
@@ -419,6 +460,7 @@ var IO = (function () {
var content = this.readFile(path);
return { content: content, path: path };
} catch (err) {
//Tools.CompilerDiagnostics.debugPrint(("Could not find " + path) + ", trying parent");
}
} else {
var parentPath = _path.resolve(rootPath, "..");
@@ -504,10 +546,14 @@ var IO = (function () {
;
if (typeof ActiveXObject === "function")
return getWindowsScriptHostIO(); else if (typeof require === "function")
return getNodeIO(); else
return getWindowsScriptHostIO();
else if (typeof require === "function")
return getNodeIO();
else
return null;
})();
/// <reference path='src/exec.ts' />
/// <reference path='src/io.ts' />
var DefinitelyTyped;
(function (DefinitelyTyped) {
(function (TestManager) {
@@ -537,7 +583,7 @@ var DefinitelyTyped;
function Tsc() {
}
Tsc.run = function (tsfile, callback) {
Exec.exec('node ./_infrastructure/tests/typescript/tsc.js ', [tsfile], function (ExecResult) {
Exec.exec('node ./_infrastructure/tests/typescript/tsc.js --module commonjs ', [tsfile], function (ExecResult) {
callback(ExecResult);
});
};
+1 -1
View File
@@ -28,7 +28,7 @@ module DefinitelyTyped {
class Tsc {
public static run(tsfile: string, callback: Function) {
Exec.exec('node ./_infrastructure/tests/typescript/tsc.js ', [tsfile], (ExecResult) => {
Exec.exec('node ./_infrastructure/tests/typescript/tsc.js --module commonjs ', [tsfile], (ExecResult) => {
callback(ExecResult);
});
}
+33 -3
View File
@@ -1,5 +1,20 @@
var IOUtils;
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// 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 IOUtils;
(function (IOUtils) {
// Creates the directory including its parent if not already present
function createDirectoryStructure(ioHost, dirName) {
if (ioHost.directoryExists(dirName)) {
return;
@@ -12,6 +27,7 @@
ioHost.createDirectory(dirName);
}
// Creates a file including its directory structure if not already present
function createFileAndFolderStructure(ioHost, fileName, useUTF8) {
var path = ioHost.resolvePath(fileName);
var dirName = ioHost.dirName(path);
@@ -31,6 +47,8 @@
})(IOUtils || (IOUtils = {}));
var IO = (function () {
// Create an IO object for use inside WindowsScriptHost hosts
// Depends on WSCript and FileSystemObject
function getWindowsScriptHostIO() {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var streamObjectPool = [];
@@ -68,6 +86,7 @@ var IO = (function () {
streamObj.Charset = 'utf-8';
}
// Read the whole file
var str = streamObj.ReadText(-1);
streamObj.Close();
releaseStreamObject(streamObj);
@@ -99,6 +118,7 @@ var IO = (function () {
var content = this.readFile(path);
return { content: content, path: path };
} catch (err) {
//Tools.CompilerDiagnostics.debugPrint("Could not find " + path + ", trying parent");
}
} else {
rootPath = fso.GetParentFolderName(fso.GetAbsolutePathName(rootPath));
@@ -222,6 +242,8 @@ var IO = (function () {
}
;
// Create an IO object for use inside Node.js hosts
// Depends on 'fs' and 'path' modules
function getNodeIO() {
var _fs = require('fs');
var _path = require('path');
@@ -234,6 +256,8 @@ var IO = (function () {
switch (buffer[0]) {
case 0xFE:
if (buffer[1] == 0xFF) {
// utf16-be. Reading the buffer as big endian is not supported, so convert it to
// Little Endian first
var i = 0;
while ((i + 1) < buffer.length) {
var temp = buffer[i];
@@ -246,15 +270,18 @@ var IO = (function () {
break;
case 0xFF:
if (buffer[1] == 0xFE) {
// utf16-le
return buffer.toString("ucs2", 2);
}
break;
case 0xEF:
if (buffer[1] == 0xBB) {
// utf-8
return buffer.toString("utf8", 3);
}
}
// Default behaviour
return buffer.toString();
} catch (e) {
IOUtils.throwIOError("Error reading file \"" + file + "\".", e);
@@ -354,6 +381,7 @@ var IO = (function () {
var content = this.readFile(path);
return { content: content, path: path };
} catch (err) {
//Tools.CompilerDiagnostics.debugPrint(("Could not find " + path) + ", trying parent");
}
} else {
var parentPath = _path.resolve(rootPath, "..");
@@ -439,7 +467,9 @@ var IO = (function () {
;
if (typeof ActiveXObject === "function")
return getWindowsScriptHostIO(); else if (typeof require === "function")
return getNodeIO(); else
return getWindowsScriptHostIO();
else if (typeof require === "function")
return getNodeIO();
else
return null;
})();
+11 -11
View File
@@ -25,11 +25,11 @@ interface IFileWatcher {
interface IIO {
readFile(path: string): string;
writeFile(path: string, contents: string): void;
createFile(path: string, useUTF8?: bool): ITextWriter;
createFile(path: string, useUTF8?: boolean): ITextWriter;
deleteFile(path: string): void;
dir(path: string, re?: RegExp, options?: { recursive?: bool; deep?: number; }): string[];
fileExists(path: string): bool;
directoryExists(path: string): bool;
dir(path: string, re?: RegExp, options?: { recursive?: boolean; deep?: number; }): string[];
fileExists(path: string): boolean;
directoryExists(path: string): boolean;
createDirectory(path: string): void;
resolvePath(path: string): string;
dirName(path: string): string;
@@ -60,7 +60,7 @@ module IOUtils {
}
// Creates a file including its directory structure if not already present
export function createFileAndFolderStructure(ioHost: IIO, fileName: string, useUTF8?: bool) {
export function createFileAndFolderStructure(ioHost: IIO, fileName: string, useUTF8?: boolean) {
var path = ioHost.resolvePath(fileName);
var dirName = ioHost.dirName(path);
createDirectoryStructure(ioHost, dirName);
@@ -78,7 +78,7 @@ module IOUtils {
// Declare dependencies needed for all supported hosts
declare class Enumerator {
public atEnd(): bool;
public atEnd(): boolean;
public moveNext();
public item(): any;
constructor (o: any);
@@ -160,7 +160,7 @@ var IO = (function() {
file.Close();
},
fileExists: function(path: string): bool {
fileExists: function(path: string): boolean {
return fso.FileExists(path);
},
@@ -250,7 +250,7 @@ var IO = (function() {
},
dir: function(path, spec?, options?) {
options = options || <{ recursive?: bool; deep?: number; }>{};
options = options || <{ recursive?: boolean; deep?: number; }>{};
function filesInFolder(folder, root): string[]{
var paths = [];
var fc: Enumerator;
@@ -365,7 +365,7 @@ var IO = (function() {
IOUtils.throwIOError("Couldn't delete file '" + path + "'.", e);
}
},
fileExists: function(path): bool {
fileExists: function(path): boolean {
return _fs.existsSync(path);
},
createFile: function(path, useUTF8?) {
@@ -395,7 +395,7 @@ var IO = (function() {
};
},
dir: function dir(path, spec?, options?) {
options = options || <{ recursive?: bool; deep?: number; }>{};
options = options || <{ recursive?: boolean; deep?: number; }>{};
function filesInFolder(folder: string, deep?: number): string[]{
var paths = [];
@@ -427,7 +427,7 @@ var IO = (function() {
}
},
directoryExists: function(path: string): bool {
directoryExists: function(path: string): boolean {
return _fs.existsSync(path) && _fs.lstatSync(path).isDirectory();
},
resolvePath: function(path: string): string {