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

Add vscode tasks to run tests in current file/project #43434

Merged
merged 11 commits into from
Apr 20, 2020

Conversation

RikkiGibson
Copy link
Contributor

This PR adds a couple of vscode tasks to improve developer productivity.

  • run tests in current file
  • run tests in current project

(running all tests is still best handled by Test.cmd)

The task will also write the test results to an html file in TestResults. This should be useful for keeping track of which tests were failing or sifting through test runs with many failures.

I didn't make the task try to search for .vbproj files because VB doesn't work that well in vscode. You are better off going to full VS if you need to work in VB.

Here's a demo:
demo-test-task-3

@RikkiGibson RikkiGibson added Area-Infrastructure Test Test failures in roslyn-CI labels Apr 17, 2020
@RikkiGibson RikkiGibson requested a review from a team as a code owner April 17, 2020 00:15
Copy link
Contributor

@jmarolf jmarolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@jmarolf
Copy link
Contributor

jmarolf commented Apr 17, 2020

What is the recommendation for tasks like these if we want them to run on mac and linux? Is there a way to call the bash versions of these in those cases?

@RikkiGibson
Copy link
Contributor Author

vscode does have an answer for this: https://code.visualstudio.com/Docs/editor/tasks#_operating-system-specific-properties.

however that seems to imply writing the script again in bash. is that the right thing to do? any chance of using cross platform powershell for this?

Set-Location $fileInfo.Directory

try
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Powershell coding style puts braces on same line

if ($files)
{
Pop-Location
$dotnetPath = Resolve-Path "$PSScriptRoot/../.dotnet/dotnet.exe" -Relative
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did u consider importing the build-utils script which has our definitive way of grabbing the dotnet binary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do this so I can use this on Linux.

@333fred
Copy link
Member

333fred commented Apr 17, 2020

however that seems to imply writing the script again in bash.

pwsh is available for linux, and is how I generate compiler code. Can you add using that for Linux and I'll give it a try?

@RikkiGibson
Copy link
Contributor Author

Thanks for the feedback. I'll pull it down on my Mac and make sure it works nicely on there.

This test failure is a new one to me: Microsoft.CodeAnalysis.CSharp.UnitTests.Symbols.GenericConstraintTests.DefaultT(): System.BadImageFormatException : Operation did not complete successfully because the file contains a virus or potentially unwanted software. (0x800700E1)

@RikkiGibson
Copy link
Contributor Author

RikkiGibson commented Apr 17, 2020

I opted for a solution that uses a local 'dotnet tool' install of PowerShell. It requires running dotnet tool restore in the repo root before the commands will work. See what you think.

@333fred
Copy link
Member

333fred commented Apr 17, 2020

I opted for a solution that uses a local 'dotnet tool' install of PowerShell. It requires running dotnet tool restore in the repo root before the commands will work. See what you think.

Personally I already have pwsh installed, but that's really w/e, I only have it installed for this repo.

@RikkiGibson
Copy link
Contributor Author

solved 2 lingering issues:

  1. tasks no longer use the globally installed dotnet cli, instead use the dotnet cli installed as part of restore. this works on windows and mac and presumably on linux.
  2. dotnet tools are restored upon .\Restore.cmd or ./restore.sh. so if you just clone the repo, run a restore, pop open vscode, you should be able to start running tasks to your heart's content.

I think this is in a pretty good place now. The test running scripts in particular I am finding invaluable when working in vscode. I also extracted out the bit that finds the project file and modified the "build directory" task to just build the "current project" based on what file you have open. /cc @jaredpar

"commands": [
"dotnet-format"
]
},
"powershell": {
"version": "6.2.4",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7.0 has been out for a month, we should probably use that.

@RikkiGibson RikkiGibson merged commit 1c2f0a0 into dotnet:master Apr 20, 2020
@ghost ghost added this to the Next milestone Apr 20, 2020
@RikkiGibson RikkiGibson deleted the add-vscode-task branch April 20, 2020 17:22
@sharwell sharwell modified the milestones: Next, temp, 16.7.P1 Apr 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure Test Test failures in roslyn-CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants