diff --git a/_infrastructure/tests/_ref.d.ts b/_infrastructure/tests/_ref.d.ts
new file mode 100644
index 000000000..1743cad05
--- /dev/null
+++ b/_infrastructure/tests/_ref.d.ts
@@ -0,0 +1 @@
+///
diff --git a/_infrastructure/tests/runner.js b/_infrastructure/tests/runner.js
index f73c72a39..ee80513a2 100644
--- a/_infrastructure/tests/runner.js
+++ b/_infrastructure/tests/runner.js
@@ -44,6 +44,7 @@ var NodeExec = (function () {
var Exec = function () {
return new NodeExec();
}();
+///
var DT;
(function (DT) {
var path = require('path');
@@ -85,9 +86,9 @@ var DT;
})();
DT.File = File;
})(DT || (DT = {}));
-///
-///
-///
+///
+///
+///
var DT;
(function (DT) {
var fs = require('fs');
@@ -127,8 +128,8 @@ var DT;
})();
DT.Tsc = Tsc;
})(DT || (DT = {}));
-///
-///
+///
+///
var DT;
(function (DT) {
/////////////////////////////////
@@ -167,6 +168,7 @@ var DT;
})();
DT.Timer = Timer;
})(DT || (DT = {}));
+///
var DT;
(function (DT) {
var referenceTagExp = //g;
@@ -194,19 +196,19 @@ var DT;
}
DT.extractReferenceTags = extractReferenceTags;
})(DT || (DT = {}));
-///
-///
-///
+///
+///
+///
var DT;
(function (DT) {
var fs = require('fs');
var path = require('path');
- var ReferenceIndex = (function () {
- function ReferenceIndex(options) {
+ var FileIndex = (function () {
+ function FileIndex(options) {
this.options = options;
}
- ReferenceIndex.prototype.collectReferences = function (files, callback) {
+ FileIndex.prototype.parseFiles = function (files, callback) {
var _this = this;
this.fileMap = Object.create(null);
files.forEach(function (file) {
@@ -217,7 +219,7 @@ var DT;
});
};
- ReferenceIndex.prototype.loadReferences = function (files, callback) {
+ FileIndex.prototype.loadReferences = function (files, callback) {
var _this = this;
var queue = files.slice(0);
var active = [];
@@ -240,7 +242,7 @@ var DT;
process.nextTick(next);
};
- ReferenceIndex.prototype.parseFile = function (file, callback) {
+ FileIndex.prototype.parseFile = function (file, callback) {
var _this = this;
fs.readFile(file.filePathWithName, {
encoding: 'utf8',
@@ -267,12 +269,49 @@ var DT;
callback(file);
});
};
- return ReferenceIndex;
+ return FileIndex;
})();
- DT.ReferenceIndex = ReferenceIndex;
+ DT.FileIndex = FileIndex;
})(DT || (DT = {}));
-///
-///
+///
+var DT;
+(function (DT) {
+ var fs = require('fs');
+ var path = require('path');
+ var Git = require('git-wrapper');
+
+ var GitChanges = (function () {
+ function GitChanges(baseDir) {
+ this.baseDir = baseDir;
+ this.options = [];
+ var dir = path.join(baseDir, '.git');
+ if (!fs.existsSync(dir)) {
+ throw new Error('cannot locate git-dir: ' + dir);
+ }
+ this.options['git-dir'] = dir;
+ }
+ GitChanges.prototype.getChanges = function (callback) {
+ //git diff --name-only HEAD~1
+ var git = new Git(this.options);
+ var opts = {};
+ var args = ['--name-only HEAD~1'];
+ git.exec('diff', opts, args, function (err, msg) {
+ if (err) {
+ callback(err, null);
+ return;
+ }
+ var paths = msg.replace(/^\s+/, '').replace(/\s+$/, '').split(/\r?\n/g);
+
+ // console.log(paths);
+ callback(null, paths);
+ });
+ };
+ return GitChanges;
+ })();
+ DT.GitChanges = GitChanges;
+})(DT || (DT = {}));
+///
+///
var DT;
(function (DT) {
/////////////////////////////////
@@ -387,6 +426,8 @@ var DT;
})();
DT.Print = Print;
})(DT || (DT = {}));
+///
+///
var DT;
(function (DT) {
@@ -608,27 +649,41 @@ var DT;
})(DT.TestSuiteBase);
DT.FindNotRequiredTscparams = FindNotRequiredTscparams;
})(DT || (DT = {}));
-///
-///
-///
-///
-///
+///
+///
+///
+///
+///
///
-///
-///
-///
-///
-///
-///
-///
+///
+///
+///
+///
+///
+///
+///
+///
var DT;
(function (DT) {
- require('source-map-support');
+ require('source-map-support').install();
var fs = require('fs');
var path = require('path');
var glob = require('glob');
+ var tsExp = /\.ts$/;
+
+ // TOD0 remove this after dev!
+ var testNames = [
+ 'async/',
+ 'jquery/jquery.d',
+ 'angularjs/angular.d',
+ 'pixi/'
+ ];
+
+ /* if (process.env.TRAVIS) {
+ testNames = null;
+ } */
DT.DEFAULT_TSC_VERSION = "0.9.1.1";
var Test = (function () {
@@ -679,39 +734,36 @@ var DT;
var TestRunner = (function () {
function TestRunner(dtPath, options) {
if (typeof options === "undefined") { options = { tscVersion: DT.DEFAULT_TSC_VERSION }; }
+ var _this = this;
+ this.dtPath = dtPath;
this.options = options;
this.suites = [];
this.options.findNotRequiredTscparams = !!this.options.findNotRequiredTscparams;
- // TOD0 remove this after dev!
- var testNames = [
- 'async/',
- 'jquery/jquery.d',
- 'angularjs/angular.d',
- 'pixi/'
- ];
- if (process.env.TRAVIS) {
- testNames = null;
- }
+ this.index = new DT.FileIndex(this.options);
// should be async
// only includes .d.ts or -tests.ts or -test.ts or .ts
var filesName = glob.sync('**/*.ts', { cwd: dtPath });
this.files = filesName.filter(function (fileName) {
- return fileName.indexOf('_infrastructure') < 0;
- }).filter(function (fileName) {
- return fileName.indexOf('node_modules/') < 0;
- }).filter(function (fileName) {
- // TOD0 remove this after dev!
- return !testNames || testNames.some(function (pattern) {
- return fileName.indexOf(pattern) > -1;
- });
- }).filter(function (fileName) {
- return /^[a-z]/i.test(fileName);
+ return _this.checkAcceptFile(fileName);
}).sort().map(function (fileName) {
return new DT.File(dtPath, fileName);
});
}
+ TestRunner.prototype.checkAcceptFile = function (fileName) {
+ var ok = tsExp.test(fileName);
+ ok = ok && fileName.indexOf('_infrastructure') < 0;
+ ok = ok && fileName.indexOf('node_modules/') < 0;
+ ok = ok && /^[a-z]/i.test(fileName);
+
+ //TODO remove this dev code
+ ok = ok && (!testNames || testNames.some(function (pattern) {
+ return fileName.indexOf(pattern) > -1;
+ }));
+ return ok;
+ };
+
TestRunner.prototype.addSuite = function (suite) {
this.suites.push(suite);
};
@@ -721,17 +773,38 @@ var DT;
this.timer = new DT.Timer();
this.timer.start();
- var index = new DT.ReferenceIndex(this.options);
- index.collectReferences(this.files, function () {
+ this.index.parseFiles(this.files, function () {
+ console.log('files:');
+ console.log('---');
_this.files.forEach(function (file) {
console.log(file.filePathWithName);
file.references.forEach(function (file) {
console.log(' - %s', file.filePathWithName);
});
});
+ console.log('---');
+ _this.getChanges();
+ });
+ };
+
+ TestRunner.prototype.getChanges = function () {
+ var _this = this;
+ var changes = new DT.GitChanges(this.dtPath);
+ changes.getChanges(function (err, changes) {
+ if (err) {
+ throw err;
+ }
+ console.log('changes:');
+ console.log('---');
+ changes.forEach(function (file) {
+ console.log(file);
+ });
+ console.log('---');
+
_this.runTests();
});
};
+
TestRunner.prototype.runTests = function () {
var _this = this;
var syntaxChecking = new DT.SyntaxChecking(this.options);
diff --git a/_infrastructure/tests/runner.ts b/_infrastructure/tests/runner.ts
index bf0502526..555ec54ab 100644
--- a/_infrastructure/tests/runner.ts
+++ b/_infrastructure/tests/runner.ts
@@ -1,28 +1,43 @@
-///
+///
-///
+///
-///
-///
-///
+///
+///
+///
///
-///
-///
-///
+///
+///
-///
-///
-///
-///
+///
+///
+
+///
+///
+///
+///
module DT {
- require('source-map-support');
+ require('source-map-support').install();
var fs = require('fs');
var path = require('path');
var glob = require('glob');
+ var tsExp = /\.ts$/;
+
+ // TOD0 remove this after dev!
+ var testNames = [
+ 'async/',
+ 'jquery/jquery.d',
+ 'angularjs/angular.d',
+ 'pixi/'
+ ];
+ /* if (process.env.TRAVIS) {
+ testNames = null;
+ } */
+
export var DEFAULT_TSC_VERSION = "0.9.1.1";
export class Test {
@@ -72,40 +87,21 @@ module DT {
files: File[];
timer: Timer;
suites: ITestSuite[] = [];
+ private index: FileIndex;
private print: Print;
- constructor(dtPath: string, public options: ITestRunnerOptions = {tscVersion: DT.DEFAULT_TSC_VERSION}) {
+ constructor(public dtPath: string, public options: ITestRunnerOptions = {tscVersion: DT.DEFAULT_TSC_VERSION}) {
this.options.findNotRequiredTscparams = !!this.options.findNotRequiredTscparams;
- // TOD0 remove this after dev!
- var testNames = [
- 'async/',
- 'jquery/jquery.d',
- 'angularjs/angular.d',
- 'pixi/'
- ];
- if (process.env.TRAVIS) {
- testNames = null;
- }
+
+ this.index = new FileIndex(this.options);
// should be async
// only includes .d.ts or -tests.ts or -test.ts or .ts
var filesName = glob.sync('**/*.ts', { cwd: dtPath });
this.files = filesName
.filter((fileName) => {
- return fileName.indexOf('_infrastructure') < 0;
- })
- .filter((fileName) => {
- return fileName.indexOf('node_modules/') < 0;
- })
- .filter((fileName) => {
- // TOD0 remove this after dev!
- return !testNames || testNames.some((pattern) => {
- return fileName.indexOf(pattern) > -1;
- });
- })
- .filter((fileName) => {
- return /^[a-z]/i.test(fileName);
+ return this.checkAcceptFile(fileName);
})
.sort()
.map((fileName) => {
@@ -113,26 +109,59 @@ module DT {
});
}
- public addSuite(suite: ITestSuite) {
+ public checkAcceptFile(fileName: string): boolean {
+ var ok = tsExp.test(fileName);
+ ok = ok && fileName.indexOf('_infrastructure') < 0;
+ ok = ok && fileName.indexOf('node_modules/') < 0;
+ ok = ok && /^[a-z]/i.test(fileName);
+
+ //TODO remove this dev code
+ ok = ok && (!testNames || testNames.some((pattern) => {
+ return fileName.indexOf(pattern) > -1;
+ }));
+ return ok;
+ }
+
+ public addSuite(suite: ITestSuite):void {
this.suites.push(suite);
}
- public run() {
+ public run():void {
this.timer = new Timer();
this.timer.start();
- var index = new ReferenceIndex(this.options);
- index.collectReferences(this.files, () => {
+ this.index.parseFiles(this.files, () => {
+ console.log('files:');
+ console.log('---');
this.files.forEach((file) => {
console.log(file.filePathWithName);
file.references.forEach((file) => {
- console.log(' - %s', file.filePathWithName);
+ console.log(' - %s', file.filePathWithName);
});
});
+ console.log('---');
+ this.getChanges();
+ });
+ }
+
+ public getChanges():void {
+ var changes = new GitChanges(this.dtPath);
+ changes.getChanges((err, changes: string[]) => {
+ if (err) {
+ throw err;
+ }
+ console.log('changes:');
+ console.log('---');
+ changes.forEach((file) => {
+ console.log(file);
+ });
+ console.log('---');
+
this.runTests();
});
}
- public runTests() {
+
+ public runTests():void {
var syntaxChecking = new SyntaxChecking(this.options);
var testEval = new TestEval(this.options);
diff --git a/_infrastructure/tests/src/changes.ts b/_infrastructure/tests/src/changes.ts
index e69de29bb..5f28f24c5 100644
--- a/_infrastructure/tests/src/changes.ts
+++ b/_infrastructure/tests/src/changes.ts
@@ -0,0 +1,37 @@
+///
+
+module DT {
+
+ var fs = require('fs');
+ var path = require('path');
+ var Git = require('git-wrapper');
+
+ export class GitChanges {
+
+ options = [];
+
+ constructor(public baseDir: string) {
+ var dir = path.join(baseDir, '.git');
+ if (!fs.existsSync(dir)) {
+ throw new Error('cannot locate git-dir: ' + dir);
+ }
+ this.options['git-dir'] = dir;
+ }
+
+ getChanges(callback: (err, paths: string[]) => void): void {
+ //git diff --name-only HEAD~1
+ var git = new Git(this.options);
+ var opts = {};
+ var args = ['--name-only HEAD~1'];
+ git.exec('diff', opts, args, (err, msg: string) => {
+ if (err) {
+ callback(err, null);
+ return;
+ }
+ var paths = msg.replace(/^\s+/, '').replace(/\s+$/, '').split(/\r?\n/g);
+ // console.log(paths);
+ callback(null, paths);
+ });
+ }
+ }
+}
diff --git a/_infrastructure/tests/src/file.ts b/_infrastructure/tests/src/file.ts
index c1a8d1f51..bd7f62dc8 100644
--- a/_infrastructure/tests/src/file.ts
+++ b/_infrastructure/tests/src/file.ts
@@ -1,3 +1,5 @@
+///
+
module DT {
var path = require('path');
diff --git a/_infrastructure/tests/src/references.ts b/_infrastructure/tests/src/index.ts
similarity index 90%
rename from _infrastructure/tests/src/references.ts
rename to _infrastructure/tests/src/index.ts
index c98f947c3..4a40f35d4 100644
--- a/_infrastructure/tests/src/references.ts
+++ b/_infrastructure/tests/src/index.ts
@@ -1,13 +1,12 @@
-///
-///
-
-///
+///
+///
+///
module DT {
var fs = require('fs');
var path = require('path');
- export class ReferenceIndex {
+ export class FileIndex {
fileMap: {[path:string]:File};
@@ -15,7 +14,7 @@ module DT {
}
- collectReferences(files: File[], callback: () => void): void {
+ parseFiles(files: File[], callback: () => void): void {
this.fileMap = Object.create(null);
files.forEach((file) => {
this.fileMap[file.fullPath] = file;
diff --git a/_infrastructure/tests/src/printer.ts b/_infrastructure/tests/src/printer.ts
index d1f0f952e..53274587a 100644
--- a/_infrastructure/tests/src/printer.ts
+++ b/_infrastructure/tests/src/printer.ts
@@ -1,5 +1,5 @@
-///
-///
+///
+///
module DT {
/////////////////////////////////
diff --git a/_infrastructure/tests/src/reporter/reporter.ts b/_infrastructure/tests/src/reporter/reporter.ts
index d4556e0cc..5f01c43ab 100644
--- a/_infrastructure/tests/src/reporter/reporter.ts
+++ b/_infrastructure/tests/src/reporter/reporter.ts
@@ -1,3 +1,6 @@
+///
+///
+
module DT {
/////////////////////////////////
// Test reporter interface
diff --git a/_infrastructure/tests/src/timer.ts b/_infrastructure/tests/src/timer.ts
index e03a94166..446ea1b34 100644
--- a/_infrastructure/tests/src/timer.ts
+++ b/_infrastructure/tests/src/timer.ts
@@ -1,5 +1,5 @@
-///
-///
+///
+///
module DT {
/////////////////////////////////
diff --git a/_infrastructure/tests/src/tsc.ts b/_infrastructure/tests/src/tsc.ts
index 5a2c803c8..6bd3fb259 100644
--- a/_infrastructure/tests/src/tsc.ts
+++ b/_infrastructure/tests/src/tsc.ts
@@ -1,7 +1,6 @@
-///
-///
-
-///
+///
+///
+///
module DT {
var fs = require('fs');
diff --git a/_infrastructure/tests/src/util.ts b/_infrastructure/tests/src/util.ts
index 3b441991f..3d63ce142 100644
--- a/_infrastructure/tests/src/util.ts
+++ b/_infrastructure/tests/src/util.ts
@@ -1,3 +1,5 @@
+///
+
module DT {
var referenceTagExp = //g;
diff --git a/package.json b/package.json
index 0119109e9..bb4c816f6 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,13 @@
{
- "private": true,
- "name": "DefinitelyTyped",
- "version": "0.0.0",
- "scripts": {
- "test": "node ./_infrastructure/tests/runner.js --tsc-version 0.9.7"
- }
+ "private": true,
+ "name": "DefinitelyTyped",
+ "version": "0.0.0",
+ "scripts": {
+ "test": "node ./_infrastructure/tests/runner.js --tsc-version 0.9.7"
+ },
+ "dependencies": {
+ "git-wrapper": "~0.1.1",
+ "glob": "~3.2.9",
+ "source-map-support": "~0.2.5"
+ }
}