forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added tests with 'travis-ci' integration
- Loading branch information
Showing
9 changed files
with
9,638 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,6 @@ Properties | |
|
||
# VIM backup files | ||
*~ | ||
|
||
# test folder | ||
!_tests/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- 0.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// 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. | ||
// | ||
|
||
// Allows for executing a program with command-line arguments and reading the result | ||
interface IExec { | ||
exec: (filename: string, cmdLineArgs: string[], handleResult: (ExecResult) => void) => void; | ||
} | ||
|
||
declare var require; | ||
|
||
class ExecResult { | ||
public stdout = ""; | ||
public stderr = ""; | ||
public exitCode: number; | ||
} | ||
|
||
class WindowsScriptHostExec implements IExec { | ||
public exec(filename: string, cmdLineArgs: string[], handleResult: (ExecResult) => void) : void { | ||
var result = new ExecResult(); | ||
var shell = new ActiveXObject('WScript.Shell'); | ||
try { | ||
var process = shell.Exec(filename + ' ' + cmdLineArgs.join(' ')); | ||
} catch(e) { | ||
result.stderr = e.message; | ||
result.exitCode = 1 | ||
handleResult(result); | ||
return; | ||
} | ||
// Wait for it to finish running | ||
while (process.Status != 0) { /* todo: sleep? */ } | ||
|
||
|
||
result.exitCode = process.ExitCode; | ||
if(!process.StdOut.AtEndOfStream) result.stdout = process.StdOut.ReadAll(); | ||
if(!process.StdErr.AtEndOfStream) result.stderr = process.StdErr.ReadAll(); | ||
|
||
handleResult(result); | ||
} | ||
} | ||
|
||
class NodeExec implements IExec { | ||
public exec(filename: string, cmdLineArgs: string[], handleResult: (ExecResult) => void) : void { | ||
var nodeExec = require('child_process').exec; | ||
|
||
var result = new ExecResult(); | ||
result.exitCode = null; | ||
var cmdLine = filename + ' ' + cmdLineArgs.join(' '); | ||
|
||
var process = nodeExec(cmdLine, function (error, stdout, stderr) { | ||
result.stdout = stdout; | ||
result.stderr = stderr; | ||
result.exitCode = error ? error.code : 0; | ||
handleResult(result); | ||
}); | ||
} | ||
} | ||
|
||
var Exec: IExec = function() : IExec { | ||
var global = <any>Function("return this;").call(null); | ||
if(typeof global.ActiveXObject !== "undefined") { | ||
return new WindowsScriptHostExec(); | ||
} else { | ||
return new NodeExec(); | ||
} | ||
}(); |
Oops, something went wrong.