Skip to content

Commit

Permalink
Merge pull request #3570 from Microsoft/users/kavipriya/inputparser
Browse files Browse the repository at this point in the history
Users/kavipriya/inputparser
  • Loading branch information
kaadhina authored Feb 9, 2017
2 parents eff617c + 02091ef commit 861fe24
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@
"loc.messages.ErrorWhileUpdatingSettings": "Error occurred while updating the settings file. Using the specified settings file.",
"loc.messages.VideoCollectorNotSupportedWithRunSettings": "Video collector is not supported with run settings.",
"loc.messages.runTestInIsolationNotSupported": "Running tests in isolation is not supported when using the multi-agent phase setting. This option will be ignored.",
"loc.messages.tiaNotSupportedInDta": "Running only impacted tests is not supported when using the multi-agent phase setting. This option will be ignored."
"loc.messages.tiaNotSupportedInDta": "Running only impacted tests is not supported when using the multi-agent phase setting. This option will be ignored.",
"loc.messages.overrideNotSupported": "Overriding test run parameters is supported only with runsettings file. This option will be ignored."
}
4 changes: 3 additions & 1 deletion Tasks/VsTest/distributedTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ export class DistributedTest {
//Modify settings file to enable configurations and data collectors.
var settingsFile = this.dtaTestConfig.settingsFile;
try {
settingsFile = await settingsHelper.updateSettingsFileAsRequired(this.dtaTestConfig.settingsFile, this.dtaTestConfig.runInParallel, this.dtaTestConfig.tiaConfig, null, false);
settingsFile = await settingsHelper.updateSettingsFileAsRequired(this.dtaTestConfig.settingsFile, this.dtaTestConfig.runInParallel, this.dtaTestConfig.tiaConfig, null, false, this.dtaTestConfig.overrideTestrunParameters);
//Reset override option so that it becomes a no-op in TaskExecutionHost
this.dtaTestConfig.overrideTestrunParameters = null;
} catch (error) {
tl.warning(tl.loc('ErrorWhileUpdatingSettings'));
tl.debug(error);
Expand Down
2 changes: 1 addition & 1 deletion Tasks/VsTest/make.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dest": "./"
},
{
"url": "https://testexecution.blob.core.windows.net/version1/TestExecution.zip",
"url": "https://testexecution.blob.core.windows.net/testexecution/3618674/TestExecution.zip",
"dest": "./Modules"
}
]
Expand Down
126 changes: 126 additions & 0 deletions Tasks/VsTest/parameterParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//Resusing from https://github.com/Microsoft/vsts-tasks/tree/04293a25f9ecc7d91cecd2c4f130904bdbf3544d/Tasks/AzureResourceGroupDeployment

export function parse(input: string) {
var result = {};
var index = 0;
var obj = { name: "", value: "" };
while (index < input.length) {
var literalData = findLiteral(input, index);
var nextIndex = literalData.currentPosition;
var specialCharacterFlag = literalData.specialCharacterFlag
var literal = input.substr(index, nextIndex - index).trim();
if (isName(literal, specialCharacterFlag)) {
if (obj.name) {
result[obj.name] = { value: obj.value };
obj = { name: "", value: "" };
}
obj.name = literal.substr(1, literal.length);
}
else {
obj.value = literal;
result[obj.name] = { value: obj.value };
obj = { name: "", value: "" };
}
index = nextIndex + 1;
}
if (obj.name) {
result[obj.name] = { value: obj.value };
}
for (var name in result) {
result[name].value = result[name].value.replace(/^"(.*)"$/, '$1');
}
return result;
}

function isName(literal: string, specialCharacterFlag: boolean): boolean {
return literal[0] === '-' && !specialCharacterFlag;
}

function findLiteral(input, currentPosition) {
var specialCharacterFlag = false;
for (; currentPosition < input.length; currentPosition++) {
if (input[currentPosition] == " " || input[currentPosition] == "\t") {
for (; currentPosition < input.length; currentPosition++) {
if (input[currentPosition + 1] != " " || input[currentPosition + 1] != "\t") {
break;
}
}
break;
}
else if (input[currentPosition] == "(") {
currentPosition = findClosingBracketIndex(input, currentPosition + 1, ")");
specialCharacterFlag = true;
}
else if (input[currentPosition] == "[") {
currentPosition = findClosingBracketIndex(input, currentPosition + 1, "]");
specialCharacterFlag = true;
}
else if (input[currentPosition] == "{") {
currentPosition = findClosingBracketIndex(input, currentPosition + 1, "}");
specialCharacterFlag = true;
}
else if (input[currentPosition] == "\"") {
//keep going till this one closes
currentPosition = findClosingQuoteIndex(input, currentPosition + 1, "\"");
specialCharacterFlag = true;
}
else if (input[currentPosition] == "'") {
//keep going till this one closes
currentPosition = findClosingQuoteIndex(input, currentPosition + 1, "'");
specialCharacterFlag = true;
}
else if (input[currentPosition] == "`") {
currentPosition++;
specialCharacterFlag = true;
if (currentPosition >= input.length) {
break;
}
}
}
return { currentPosition: currentPosition, specialCharacterFlag: specialCharacterFlag };
}

function findClosingBracketIndex(input, currentPosition, closingBracket): number {
for (; currentPosition < input.length; currentPosition++) {
if (input[currentPosition] == closingBracket) {
break;
}
else if (input[currentPosition] == "(") {
currentPosition = findClosingBracketIndex(input, currentPosition + 1, ")");
}
else if (input[currentPosition] == "[") {
currentPosition = findClosingBracketIndex(input, currentPosition + 1, "]");
}
else if (input[currentPosition] == "{") {
currentPosition = findClosingBracketIndex(input, currentPosition + 1, "}");
}
else if (input[currentPosition] == "\"") {
currentPosition = findClosingQuoteIndex(input, currentPosition + 1, "\"");
}
else if (input[currentPosition] == "'") {
currentPosition = findClosingQuoteIndex(input, currentPosition + 1, "'");
}
else if (input[currentPosition] == "`") {
currentPosition++;
if (currentPosition >= input.length) {
break;
}
}
}
return currentPosition;
}

function findClosingQuoteIndex(input, currentPosition, closingQuote) {
for (; currentPosition < input.length; currentPosition++) {
if (input[currentPosition] == closingQuote) {
break;
}
else if (input[currentPosition] == "`") {
currentPosition++;
if (currentPosition >= input.length) {
break;
}
}
}
return currentPosition;
}
31 changes: 28 additions & 3 deletions Tasks/VsTest/settingsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path = require('path');
import Q = require('q');
import models = require('./models')
import * as utils from './helpers';
import * as parameterParser from './parameterParser'

var os = require('os');
var uuid = require('node-uuid');
Expand Down Expand Up @@ -49,12 +50,12 @@ const runSettingsTemplate = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"</DataCollectionRunSettings>" +
"</RunSettings>";

export async function updateSettingsFileAsRequired(settingsFile: string, isParallelRun: boolean, tiaConfig: models.TiaConfiguration, vsVersion: any, videoCollector: boolean) : Promise<string>
{
export async function updateSettingsFileAsRequired(settingsFile: string, isParallelRun: boolean, tiaConfig: models.TiaConfiguration, vsVersion: any, videoCollector: boolean, overrideParametersString: string) : Promise<string>
{
var defer=Q.defer<string>();
var result: any;

if(!isParallelRun && !videoCollector && !tiaConfig.tiaEnabled) {
if(!isParallelRun && !videoCollector && !tiaConfig.tiaEnabled && !overrideParametersString) {
defer.resolve(settingsFile);
return defer.promise;
}
Expand All @@ -77,6 +78,14 @@ export async function updateSettingsFileAsRequired(settingsFile: string, isParal
}
}

if (overrideParametersString) {
if(settingsExt === runSettingsExt) {
result = updateRunSettingsWithParameters(result, overrideParametersString);
} else {
tl.warning(tl.loc('overrideNotSupported'));
}
}

if (isParallelRun) {
if (settingsExt === testSettingsExt) {
tl.warning(tl.loc('RunInParallelNotSupported'));
Expand Down Expand Up @@ -164,6 +173,22 @@ export async function updateSettingsFileAsRequired(settingsFile: string, isParal
return defer.promise;
}

function updateRunSettingsWithParameters(result: any, overrideParametersString: string) {
var overrideParameters = parameterParser.parse(overrideParametersString);
if (result.RunSettings && result.RunSettings.TestRunParameters && result.RunSettings.TestRunParameters[0] &&
result.RunSettings.TestRunParameters[0].Parameter) {
tl.debug("Overriding test run parameters.");
var parametersArray = result.RunSettings.TestRunParameters[0].Parameter;
parametersArray.forEach(function (parameter) {
var key = parameter.$.name;
if (overrideParameters[key] && overrideParameters[key].value) {
parameter.$.value = overrideParameters[key].value;
}
});
}
return result;
}

function updateRunSettingsWithDataCollector(result: any, dataCollectorFriendlyName: string, dataCollectorNodeToAdd) {
if (!result.RunSettings) {
tl.debug("Updating runsettings file from RunSettings node");
Expand Down
3 changes: 2 additions & 1 deletion Tasks/VsTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
"ErrorWhileUpdatingSettings": "Error occurred while updating the settings file. Using the specified settings file.",
"VideoCollectorNotSupportedWithRunSettings": "Video collector is not supported with run settings.",
"runTestInIsolationNotSupported": "Running tests in isolation is not supported when using the multi-agent phase setting. This option will be ignored.",
"tiaNotSupportedInDta": "Running only impacted tests is not supported when using the multi-agent phase setting. This option will be ignored."
"tiaNotSupportedInDta": "Running only impacted tests is not supported when using the multi-agent phase setting. This option will be ignored.",
"overrideNotSupported": "Overriding test run parameters is supported only with runsettings file. This option will be ignored."
}
}
3 changes: 2 additions & 1 deletion Tasks/VsTest/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@
"ErrorWhileUpdatingSettings": "ms-resource:loc.messages.ErrorWhileUpdatingSettings",
"VideoCollectorNotSupportedWithRunSettings": "ms-resource:loc.messages.VideoCollectorNotSupportedWithRunSettings",
"runTestInIsolationNotSupported": "ms-resource:loc.messages.runTestInIsolationNotSupported",
"tiaNotSupportedInDta": "ms-resource:loc.messages.tiaNotSupportedInDta"
"tiaNotSupportedInDta": "ms-resource:loc.messages.tiaNotSupportedInDta",
"overrideNotSupported": "ms-resource:loc.messages.overrideNotSupported"
}
}
Loading

0 comments on commit 861fe24

Please sign in to comment.