Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DotNetCore command supports custom commands #6015

Merged
merged 1 commit into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Tasks/DotNetCoreCLI/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,72 @@ describe('DotNetCoreExe Suite', function () {
assert.equal(tr.errorIssues.length, 0, 'should have no errors');
done();
});

it('custom command fails when no project match found', (done: MochaDone) => {
process.env["__command__"] = "custom";
process.env["__custom__"] = "test";
process.env["__projects__"] = "*nomatch*/project.json";

let tp = path.join(__dirname, 'customInputs.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();

assert(tr.invokedToolCount == 0, 'should not have invoked tool');
assert(tr.failed, 'task should have failed');
assert.equal(tr.errorIssues.length, 1, "should have thrown an error");
done();
});

it('custom command executes without projects if none supplied', (done: MochaDone) => {
process.env["__command__"] = "custom";
process.env["__custom__"] = "vstest";
process.env["__projects__"] = "";
process.env["__arguments__"] = "supplied/in/arguments.dll --framework netcoreapp2.0"

let tp = path.join(__dirname, 'customInputs.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();

assert(tr.invokedToolCount == 1, 'should have invoked tool');
assert(tr.ran('c:\\path\\dotnet.exe vstest supplied/in/arguments.dll --framework netcoreapp2.0'), 'it should have run dotnet with expected arguments');
assert(tr.stdOutContained('vstest succeeded'), "should have dotnet output");
assert(tr.succeeded, 'should have succeeded');
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});

it('custom command fails if dotnet returns error', (done: MochaDone) => {
process.env["__command__"] = "custom";
process.env["__custom__"] = "test";
process.env["__projects__"] = "fails/project.json";
process.env["__arguments__"] = "--no-build --no-restore"

let tp = path.join(__dirname, 'customInputs.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();

assert(tr.invokedToolCount == 1, 'should have invoked tool');
assert(tr.ran('c:\\path\\dotnet.exe test fails/project.json --no-build --no-restore'), 'it should have run dotnet with expected arguments');
assert(tr.stdOutContained('test failed'), "should have dotnet output");
assert(tr.failed, 'task should have failed');
assert(tr.errorIssues.length > 0, "error reason should have been recorded");
done();
});

it('custom command runs once for each matched project', (done: MochaDone) => {
process.env["__command__"] = "custom";
process.env["__custom__"] = "test";
process.env["__projects__"] = "**/project.json";
process.env["__arguments__"] = ""

let tp = path.join(__dirname, 'customInputs.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();

assert(tr.invokedToolCount == 4, 'should not have invoked tool 4 times');
assert(tr.succeeded, 'task should have succeeded');
assert.equal(tr.errorIssues.length, 0, "should have no errors");
done();
});

});
61 changes: 61 additions & 0 deletions Tasks/DotNetCoreCLI/Tests/customInputs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import ma = require('vsts-task-lib/mock-answer');
import tmrm = require('vsts-task-lib/mock-run');
import path = require('path');

let taskPath = path.join(__dirname, '..', 'dotnetcore.js');
let tmr: tmrm.TaskMockRunner = new tmrm.TaskMockRunner(taskPath);

tmr.setInput('command', "custom");
tmr.setInput('custom', process.env["__custom__"]);
tmr.setInput('projects', process.env["__projects__"]);
tmr.setInput('arguments', process.env["__arguments__"] ? process.env["__arguments__"] : "");

let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"which": { "dotnet": "c:\\path\\dotnet.exe" },
"checkPath": { "c:\\path\\dotnet.exe": true },
"exec": {
"c:\\path\\dotnet.exe test web/project.json": {
"code": 0,
"stdout": "test succeeded",
"stderr": ""
},
"c:\\path\\dotnet.exe test web2/project.json": {
"code": 0,
"stdout": "test succeeded",
"stderr": ""
},
"c:\\path\\dotnet.exe test web.tests/project.json": {
"code": 0,
"stdout": "test succeeded",
"stderr": ""
},
"c:\\path\\dotnet.exe test lib/project.json": {
"code": 0,
"stdout": "test succeeded",
"stderr": ""
},
"c:\\path\\dotnet.exe test fails/project.json --no-build --no-restore": {
"code": 1,
"stdout": "test failed",
"stderr": ""
},
"c:\\path\\dotnet.exe vstest supplied/in/arguments.dll --framework netcoreapp2.0": {
"code": 0,
"stdout": "vstest succeeded",
"stderr": ""
}
},
"findMatch": {
"**/project.json": ["web/project.json", "web2/project.json", "web.tests/project.json", "lib/project.json"],
"**/project.json;**/*.csproj;**/*.vbproj": ["web/project.json", "web2/project.json", "web.tests/project.json", "lib/project.json"],
"*nomatch*/project.json": [],
"fails/project.json": ["fails/project.json"],
"withArguments/project.json": ["withArguments/project.json"],
"" : []
}
};

tmr.setAnswers(a);
tmr.registerMock('vsts-task-lib/toolrunner', require('vsts-task-lib/mock-toolrunner'));

tmr.run();
7 changes: 4 additions & 3 deletions Tasks/DotNetCoreCLI/dotnetcore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ export class dotNetExe {

public async execute() {
tl.setResourcePath(path.join(__dirname, "task.json"));
if (this.command === "custom") {
this.command = tl.getInput("custom", true);
}

switch (this.command) {
case "build":
case "publish":
case "run":
await this.executeBasicCommand();
break;
case "custom":
this.command = tl.getInput("custom", true);
await this.executeBasicCommand();
break;
case "test":
await this.executeTestCommand();
break;
Expand Down
4 changes: 2 additions & 2 deletions Tasks/DotNetCoreCLI/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vsts-tasks-dotnetcoreexe",
"version": "2.1.5",
"version": "2.129.4",
"description": "Dotnet core exe",
"main": "dotnetcore.js",
"scripts": {
Expand All @@ -23,4 +23,4 @@
"vso-node-api": "6.0.1-preview",
"vsts-task-lib": "2.0.6"
}
}
}
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLI/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 129,
"Patch": 3
"Patch": 4
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "dotnet $(command)",
Expand Down
2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLI/task.loc.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"version": {
"Major": 2,
"Minor": 129,
"Patch": 3
"Patch": 4
},
"minimumAgentVersion": "2.0.0",
"instanceNameFormat": "ms-resource:loc.instanceNameFormat",
Expand Down