Skip to content

Commit

Permalink
Fixed issue with unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Jan 28, 2016
1 parent 9535c91 commit cf8fc04
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/client/common/childProc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import * as path from 'path';
import * as fs from 'fs';
import * as child_process from 'child_process';

export function sendCommand(commandLine: string, cwd: string): Promise<string> {
export function sendCommand(commandLine: string, cwd: string, includeErrorAsResponse:boolean = false): Promise<string> {
return new Promise<string>((resolve, reject) => {

child_process.exec(commandLine, { cwd: cwd }, (error, stdout, stderr) => {
if (includeErrorAsResponse){
return resolve(stdout.toString('utf-8') + '\n' + stderr.toString('utf-8'));
}

var hasErrors = (error && error.message.length > 0) || (stderr && stderr.length > 0);
if (hasErrors && (typeof stdout !== "string" || stdout.length === 0)) {
var errorMsg = (error && error.message) ? error.message : (stderr && stderr.length > 0 ? stderr.toString("utf-8") : "");
Expand Down
6 changes: 4 additions & 2 deletions src/client/unittest/baseTestRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export abstract class BaseTestRunner {
public Id: string;
protected pythonSettings: settings.IPythonSettings;
protected outputChannel: OutputChannel;
constructor(id: string, pythonSettings: settings.IPythonSettings, outputChannel: OutputChannel) {
private includeErrorAsResponse: boolean;
constructor(id: string, pythonSettings: settings.IPythonSettings, outputChannel: OutputChannel, includeErrorAsResponse: boolean = false) {
this.Id = id;
this.pythonSettings = pythonSettings;
this.outputChannel = outputChannel;
this.includeErrorAsResponse = includeErrorAsResponse;
}

public runTests(filePath: string): Promise<any> {
Expand All @@ -25,7 +27,7 @@ export abstract class BaseTestRunner {
var linterId = this.Id;

return new Promise<any>((resolve, reject) => {
sendCommand(commandLine, workspace.rootPath).then(data => {
sendCommand(commandLine, workspace.rootPath, this.includeErrorAsResponse).then(data => {
outputChannel.append(data);
outputChannel.show();
}, error=> {
Expand Down
2 changes: 1 addition & 1 deletion src/client/unittest/nosetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {OutputChannel} from 'vscode';

export class NoseTests extends baseTestRunner.BaseTestRunner {
constructor(pythonSettings: settings.IPythonSettings, outputChannel: OutputChannel) {
super("nosetests", pythonSettings, outputChannel);
super("nosetests", pythonSettings, outputChannel, true);
}

public runTests(filePath: string = ""): Promise<any> {
Expand Down
2 changes: 1 addition & 1 deletion src/client/unittest/unittest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {OutputChannel} from 'vscode';

export class PythonUnitTest extends baseTestRunner.BaseTestRunner {
constructor(pythonSettings: settings.IPythonSettings, outputChannel: OutputChannel) {
super("unittest", pythonSettings, outputChannel);
super("unittest", pythonSettings, outputChannel, true);
}

public runTests(filePath: string = ""): Promise<any> {
Expand Down

0 comments on commit cf8fc04

Please sign in to comment.