Skip to content

Commit

Permalink
Merge pull request #4373 from Microsoft/users/praga/pathResolve
Browse files Browse the repository at this point in the history
Fix for ..\directory type entries for search folder
  • Loading branch information
prawalagarwal authored May 24, 2017
2 parents b78c2b0 + 99e3a9e commit b798d68
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 24 deletions.
7 changes: 7 additions & 0 deletions Tasks/VsTest/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export class Helper {
return obj === null || obj === '' || obj === undefined;
}

public static isNullOrWhitespace(input) {
if (typeof input === 'undefined' || input === null) {
return true;
}
return input.replace(/\s/g, '').length < 1;
}

public static pathExistsAsFile(path: string) {
return tl.exist(path) && tl.stats(path).isFile();
}
Expand Down
2 changes: 1 addition & 1 deletion Tasks/VsTest/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 49
"Patch": 50
},
"demands": [
"vstest"
Expand Down
2 changes: 1 addition & 1 deletion Tasks/VsTest/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 0,
"Patch": 49
"Patch": 50
},
"demands": [
"vstest"
Expand Down
12 changes: 12 additions & 0 deletions Tasks/VsTest/taskinputparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,20 @@ function initTestConfigurations(testConfiguration: models.TestConfigurations) {
tl._writeLine(tl.loc('testSelectorInput', testConfiguration.testSelection));

testConfiguration.testDropLocation = tl.getInput('searchFolder');
if (!utils.Helper.isNullOrWhitespace(testConfiguration.testDropLocation))
{
testConfiguration.testDropLocation = path.resolve(testConfiguration.testDropLocation);
}
tl._writeLine(tl.loc('searchFolderInput', testConfiguration.testDropLocation));

testConfiguration.testcaseFilter = tl.getInput('testFiltercriteria');
tl._writeLine(tl.loc('testFilterCriteriaInput', testConfiguration.testcaseFilter));

testConfiguration.settingsFile = tl.getPathInput('runSettingsFile');
if (!utils.Helper.isNullOrWhitespace(testConfiguration.settingsFile))
{
testConfiguration.settingsFile = path.resolve(testConfiguration.settingsFile);
}
tl._writeLine(tl.loc('runSettingsFileInput', testConfiguration.settingsFile));

testConfiguration.overrideTestrunParameters = tl.getInput('overrideTestrunParameters');
Expand All @@ -116,6 +124,10 @@ function initTestConfigurations(testConfiguration: models.TestConfigurations) {
testConfiguration.tiaConfig = getTiaConfiguration();

testConfiguration.pathtoCustomTestAdapters = tl.getInput('pathtoCustomTestAdapters');
if (!utils.Helper.isNullOrWhitespace(testConfiguration.pathtoCustomTestAdapters))
{
testConfiguration.pathtoCustomTestAdapters = path.resolve(testConfiguration.pathtoCustomTestAdapters);
}
if (testConfiguration.pathtoCustomTestAdapters &&
!utils.Helper.pathExistsAsDirectory(testConfiguration.pathtoCustomTestAdapters)) {
throw new Error(tl.loc('pathToCustomAdaptersInvalid', testConfiguration.pathtoCustomTestAdapters));
Expand Down
13 changes: 3 additions & 10 deletions Tasks/VsTest/vstest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function startTest() {
}

function getTestAssemblies(): string[] {
if (isNullOrWhitespace(vstestConfig.testDropLocation)) {
if (utils.Helper.isNullOrWhitespace(vstestConfig.testDropLocation)) {
vstestConfig.testDropLocation = systemDefaultWorkingDirectory;
tl.debug('Search directory empty, defaulting to ' + vstestConfig.testDropLocation);
}
Expand Down Expand Up @@ -131,7 +131,7 @@ function getVstestArguments(settingsFile: string, tiaEnabled: boolean): string[]
}

argsArray.push('/logger:trx');
if (isNullOrWhitespace(vstestConfig.pathtoCustomTestAdapters)) {
if (utils.Helper.isNullOrWhitespace(vstestConfig.pathtoCustomTestAdapters)) {
if (systemDefaultWorkingDirectory && isTestAdapterPresent(vstestConfig.testDropLocation)) {
argsArray.push('/TestAdapterPath:\"' + systemDefaultWorkingDirectory + '\"');
}
Expand Down Expand Up @@ -193,7 +193,7 @@ function uploadTestResults(testResultsDirectory: string): Q.Promise<string> {
let resultFile: string;
const defer = Q.defer<string>();
let resultFiles;
if (!isNullOrWhitespace(testResultsDirectory)) {
if (!utils.Helper.isNullOrWhitespace(testResultsDirectory)) {
resultFiles = tl.findMatch(testResultsDirectory, path.join(testResultsDirectory, '*.trx'));
}

Expand Down Expand Up @@ -923,11 +923,4 @@ function responseContainsNoTests(filePath: string): Q.Promise<boolean> {
return false;
}
});
}

function isNullOrWhitespace(input) {
if (typeof input === 'undefined' || input === null) {
return true;
}
return input.replace(/\s/g, '').length < 1;
}
167 changes: 158 additions & 9 deletions Tests-Legacy/L0/VsTest/_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,15 @@ describe('VsTest Suite', function () {

it('Vstest task with settings file', (done) => {

const vstestCmd = [sysVstestLocation, '/source/dir/someFile1', '/Settings:settings.runsettings', '/logger:trx'].join(' ');
const vstestCmd = [sysVstestLocation, '/source/dir/someFile1', '/Settings:E:\\settings.runsettings', '/logger:trx'].join(' ');
setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/someFile1');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('runSettingsFile', 'settings.runsettings');
tr.setInput('runSettingsFile', 'E:\\settings.runsettings');

tr.run()
.then(() => {
Expand Down Expand Up @@ -544,15 +544,15 @@ describe('VsTest Suite', function () {

it('Vstest task with custom adapter path', (done) => {

const vstestCmd = [sysVstestLocation, '/source/dir/someFile1', '/logger:trx', '/TestAdapterPath:path/to/customadapters'].join(' ');
const vstestCmd = [sysVstestLocation, '/source/dir/someFile1', '/logger:trx', '/TestAdapterPath:E:\\path\\to\\customadapters'].join(' ');
setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/someFile1');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('pathtoCustomTestAdapters', 'path/to/customadapters');
tr.setInput('pathtoCustomTestAdapters', 'E:/path/to/customadapters');

tr.run()
.then(() => {
Expand Down Expand Up @@ -597,15 +597,15 @@ describe('VsTest Suite', function () {

it('Vstest task with runsettings file and tia.enabled set to false', (done) => {

const vstestCmd = [sysVstestLocation, '/source/dir/someFile1', '/Settings:settings.runsettings', '/logger:trx'].join(' ');
const vstestCmd = [sysVstestLocation, '/source/dir/someFile1', '/Settings:E:\\settings.runsettings', '/logger:trx'].join(' ');
setResponseFile('vstestGoodWithTiaDisabled.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/someFile1');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('runSettingsFile', 'settings.runsettings');
tr.setInput('runSettingsFile', 'E:\\settings.runsettings');

tr.run()
.then(() => {
Expand All @@ -624,15 +624,15 @@ describe('VsTest Suite', function () {

it('Vstest task with runsettings file and tia.enabled undefined', (done) => {

const vstestCmd = [sysVstestLocation, '/source/dir/someFile1', '/Settings:settings.runsettings', '/logger:trx'].join(' ');
const vstestCmd = [sysVstestLocation, '/source/dir/someFile1', '/Settings:E:\\settings.runsettings', '/logger:trx'].join(' ');
setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/someFile1');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('runSettingsFile', 'settings.runsettings');
tr.setInput('runSettingsFile', 'E:\\settings.runsettings');

tr.run()
.then(() => {
Expand Down Expand Up @@ -744,7 +744,7 @@ describe('VsTest Suite', function () {
.fail((err) => {
done(err);
});
});
});

it('Vstest task should not use diag option when system.debug is not set', (done) => {

Expand Down Expand Up @@ -1069,4 +1069,153 @@ describe('VsTest Suite', function () {
done(err);
});
});

it('Vstest search folder field supports double dots', (done) => {
const vstestCmd = [sysVstestLocation, '/source/dir/someFile2 /source/dir/someFile1', '/logger:trx'].join(' ');
setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/some/*pattern');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('searchFolder','E:\\source\\dir\\..');

tr.run()
.then(() => {
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length === 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.ran(vstestCmd), 'should have run vstest');
assert(tr.stdout.search(/Search folder : E:\\source/) >= 0, 'searching in the wrong path with double dots');
done();
})
.fail((err) => {
console.log(tr.stdout);
done(err);
});
});

it('Vstest search folder field supports single dots', (done) => {
const vstestCmd = [sysVstestLocation, '/source/dir/someFile2 /source/dir/someFile1', '/logger:trx'].join(' ');
setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/some/*pattern');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('searchFolder','E:\\source\\.\\dir');

tr.run()
.then(() => {
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length === 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.ran(vstestCmd), 'should have run vstest');
assert(tr.stdout.search(/Search folder : E:\\source\\dir/) >= 0, 'searching in the wrong path with single dots');
done();
})
.fail((err) => {
console.log(tr.stdout);
done(err);
});
});

it('Vstest task with settings file path with double dots is supported', (done) => {

setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/someFile1');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('runSettingsFile', 'E:\\source\\dir\\..\\settings.runsettings');

tr.run()
.then(() => {
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length === 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.search(/Run settings file : E:\\source\\settings.runsettings/) >= 0, 'wrong path for settings file with double dots');
done();
})
.fail((err) => {
done(err);
});
});

it('Vstest task with settings file path with single dots is supported', (done) => {
setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/someFile1');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('runSettingsFile', 'E:\\source\\dir\\.\\settings.runsettings');

tr.run()
.then(() => {
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length === 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.search(/Run settings file : E:\\source\\dir\\settings.runsettings/) >= 0, 'wrong path for settings file with single dots');
done();
})
.fail((err) => {
done(err);
});
});

it('Vstest task with custom adapter path with double dots is supported', (done) => {

setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/someFile1');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('pathtoCustomTestAdapters', 'E:/path/to/../customadapters');

tr.run()
.then(() => {
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length === 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.search(/Path to custom adapters : E:\\path\\customadapters/) >= 0, 'wrong path for custom adapters with double dots');
done();
})
.fail((err) => {
console.log(tr.stdout);
done(err);
});
});

it('Vstest task with custom adapter path with single dots is supported', (done) => {

setResponseFile('vstestGood.json');

const tr = new trm.TaskRunner('VSTest');
tr.setInput('testSelector', 'testAssemblies');
tr.setInput('testAssemblyVer2', '/source/dir/someFile1');
tr.setInput('vstestLocationMethod', 'version');
tr.setInput('vsTestVersion', '14.0');
tr.setInput('pathtoCustomTestAdapters', 'E:/path/to/./customadapters');

tr.run()
.then(() => {
assert(tr.resultWasSet, 'task should have set a result');
assert(tr.stderr.length === 0, 'should not have written to stderr. error: ' + tr.stderr);
assert(tr.succeeded, 'task should have succeeded');
assert(tr.stdout.search(/Path to custom adapters : E:\\path\\to\\customadapters/) >= 0, 'wrong path for custom adapters with single dots');
done();
})
.fail((err) => {
console.log(tr.stdout);
done(err);
});
});
});
Loading

0 comments on commit b798d68

Please sign in to comment.