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

Auto-generate F# program file #1664

Merged
merged 7 commits into from
Jul 10, 2018
Merged

Conversation

saul
Copy link
Contributor

@saul saul commented Jun 29, 2018

Description

Allows F# Program.fs to be autogenerated.

Todo:

  • Do not auto-generate a 'Program.fs' is already in Compile

Related issue

Fixes #1171. cc @enricosada

@@ -76,15 +76,26 @@
<Line Include="End Sub"/>
<Line Include="End Module"/>
</ItemGroup>

<ItemGroup Condition="'$(Language)'=='F#'">
<Line Include="module Program"/>
Copy link

Choose a reason for hiding this comment

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

This will fail if another module is named Program. It would probably be better to do something like

module ``VSTest-AutoGenerated-Program``

It can still have collisions, but way less likely. Also, both the C# and the VB version is decorated with TestSDKAutoGeneratedCodeAttribute which is probably a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch - I'll fix that.

@Alxandr
Copy link

Alxandr commented Jun 29, 2018

My "program" files are never called Program.fs, so having that as the way to turn off auto-generation of would be a bit too opinionated IMHO.

@saul
Copy link
Contributor Author

saul commented Jun 29, 2018

Yeah, but you still have the option to specify <GenerateProgramFile>false</GenerateProgramFile> as you do with C#/VB.

Copy link
Contributor

@smadala smadala left a comment

Choose a reason for hiding this comment

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

@saul Thanks a lot 👍 for PR.

<Compile Include="$(GeneratedProgramFile)"/>
</ItemGroup>

<ItemGroup Condition="'$(Language)'=='F#'">
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure runtimeconfig.*.json will gets generates because CompileAfter?
FYI dotnet/sdk#201 #287.

@saul did you test simple unit test project of F# with your changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I understood what is CompileAfter. Now it makes sense after reading issue one more time.

I have checked out your branch and verified E2E scenario. Below are the issue we need to address.

  • Newly created F# unit test project not getting compiled because of below compilation error.
PS C:\Users\samadala\tmp\fs-test-project> dotnet test
Build started, please wait...
C:\Users\samadala\tmp\fs-test-project\Program.fs(1,1): error FS0222: Files in libraries or multiple-file applications must begin with a namespace or module declaration. When using a module declaration at the start of a file the '=' sign is not allowed. If this is a top-level module, consider removing the = to resolve this error. [C:\Users\samadala\tmp\fs-test-project\fs-test-project.fsproj]

This can be fixed by removing <Compile Include="Program.fs" /> from template fsproj here and removing Program.fs, We can address this with separate https://github.com/dotnet/templating PR

  • Test project created with old templates fail to compile with above error on updating to latest Microsoft.NET.Test.Sdk package.

This can be fixed by adding check here that don't include GeneratedProgramFile in CompileAfter if Compile item group contains Program.fs.

@saul Can you please fix the seconds issue in this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @smadala - I've fixed the second problem.

I've added a warning: A 'Program.fs' file can be automatically generated for F# .NET Core test projects. To fix this warning, either delete the file from the project, or set the <GenerateProgramFile> property to 'false'.

This lets the user either remove their Program.fs, or disables <GenerateProgramFile> if they need a complex Program.fs for whatever reason.

Copy link
Contributor

Choose a reason for hiding this comment

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

@saul Adding warning is very good idea.

@saul
Copy link
Contributor Author

saul commented Jul 2, 2018

Hi @smadala - I tested the changes with a unit test project I had and the Program.fs file was generated as expected and the tests passed.

@smadala
Copy link
Contributor

smadala commented Jul 2, 2018

@saul Can you please test E2E?

Add Microsoft.NET.Test.Sdk.15.8.0-dev.nupkg (
Example path: C:\Users\samadala\src\vstest\artifacts\Debug\packages\Microsoft.NET.Test.Sdk.15.8.0-dev.nupkg, obtained by build.cmd) package to your test project and update nuget feed.

<CompileAfter Include="$(GeneratedProgramFile)" Condition="@(ProgramCompiles-&gt;Count()) == 0"/>
</ItemGroup>

<Warning Condition=" @(ProgramCompiles-&gt;Count()) != 0 " Text="A 'Program.fs' file can be automatically generated for F# .NET Core test projects. To fix this warning, either delete the file from the project, or set the &lt;GenerateProgramFile&gt; property to 'false'." />
Copy link
Contributor

Choose a reason for hiding this comment

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

This might need localization. We will take it in separate PR if required.

@smadala
Copy link
Contributor

smadala commented Jul 6, 2018

@dotnet-bot test this

@smadala
Copy link
Contributor

smadala commented Jul 7, 2018

@dotnet-bot test this

@mayankbansal018 mayankbansal018 merged commit 0c0270a into microsoft:master Jul 10, 2018
@ErikSchierboom
Copy link

Merged, great news! Will this be in the next VSTest release?

@mayankbansal018
Copy link
Contributor

Yes, this should be available in our next release of "Microsoft.NET.Test.Sdk" nuget. We will also insert the same in dotnet SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants