Skip to content

Conversation

@asik
Copy link
Contributor

@asik asik commented Nov 20, 2020

Unused open declaration seemed broken on open type:

module MyModule =
    type Thingy = 
        static member Thing = ()

// These will be marked as unused even though they have usages below
open type System.Console
open type MyModule.Thingy

[<EntryPoint>]
let main argv =
    WriteLine("Hello World!")
    printfn "%A" Thing
    0

The original code only considered modules and namespaces opened via regular "open"; the fix is to add the types opened via "open type" to the list when determining what open statements are used.

I am trying to add unit tests in vsintegration\tests\UnitTests\UnusedOpensTests.fs, but I'm running into an error trying to run them:

build.cmd -testvs
(...)

test C:\git\fsharp\vsintegration\tests\GetTypesVS.UnitTests\GetTypesVS.UnitTests.fsproj -c Debug -f net472 -v n --test-adapter-path C:\git\fsharp\artifacts\bin\GetTypesVS.UnitTests --logger "nunit;LogFilePath=C:\git\fsharp\artifacts\TestResults\Debug\GetTypesVS.UnitTests_net472.xml" /bl:C:\git\fsharp\artifacts\log\Debug\GetTypesVS.UnitTests_net472.binlog --no-restore --no-build --filter TestCategory!=PullRequest
C:\Program Files\dotnet\sdk\3.1.302\MSBuild.dll -nologo -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\3.1.302\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\3.1.302\dotnet.dll -maxcpucount -nodereuse:false -property:Configuration=Debug -property:TargetFramework=net472 -property:VSTestTestAdapterPath=C:\git\fsharp\artifacts\bin\GetTypesVS.UnitTests -property:VSTestLogger=nunit%3bLogFilePath=C:\git\fsharp\artifacts\TestResults\Debug\GetTypesVS.UnitTests_net472.xml -property:VSTestNoBuild=true -property:VSTestTestCaseFilter=TestCategory!=PullRequest -property:VSTestVerbosity=n -target:VSTest -verbosity:m -verbosity:quiet -verbosity:n /bl:C:\git\fsharp\artifacts\log\Debug\GetTypesVS.UnitTests_net472.binlog C:\git\fsharp\vsintegration\tests\GetTypesVS.UnitTests\GetTypesVS.UnitTests.fsproj
Build started 2020-11-19 19:18:20.
Test run for C:\git\fsharp\artifacts\bin\GetTypesVS.UnitTests\Debug\net472\GetTypesVS.UnitTests.dll(.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 16.6.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.
NUnit Adapter 3.11.2.0: Test execution started
Running all tests in C:\git\fsharp\artifacts\bin\GetTypesVS.UnitTests\Debug\net472\GetTypesVS.UnitTests.dll
   NUnit3TestExecutor converted 1 of 1 NUnit test cases
NUnit Adapter 3.11.2.0: Test execution complete
  X GetTypesForVSUnitTests [334ms]
  Error Message:
   TypeLoad failure: Could not load file or assembly 'VSLangProj, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

  Stack Trace:
     at GetTypesVSUnitTests.VerifyUnitTests.GetTypesForVSUnitTests() in C:\git\fsharp\vsintegration\tests\GetTypesVS.UnitTests\GetTypesVS.UnitTests.fs:line 17

Results File: C:\git\fsharp\artifacts\TestResults\Debug\GetTypesVS.UnitTests_net472.xml

Test Run Failed.
Total tests: 1
     Failed: 1
 Total time: 1,4182 Seconds

@dnfadmin
Copy link

dnfadmin commented Nov 20, 2020

CLA assistant check
All CLA requirements met.

@cartermp
Copy link
Contributor

Looks like there's a test failure.

@asik
Copy link
Contributor Author

asik commented Nov 20, 2020

Looks like there's a test failure.

Oh I see, that's the test I was trying to add (and it's clearly wrong). I want to run it locally and add more, but I'm kinda stuck with the error I described above.

Edit:
I can workaround this by running dotnet test VisualFSharp.UnitTests.dll since that's the only one I'm modifying.

@asik
Copy link
Contributor Author

asik commented Nov 20, 2020

The tests are passing now. I didn't add an open type test for every open test that there was, assuming much of the logic is shared between the two. Let me know if I can improve this PR still.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@cartermp cartermp added this to the 16.9 milestone Nov 20, 2020
@cartermp cartermp merged commit aec399c into dotnet:main Nov 20, 2020
auduchinok added a commit to JetBrains/resharper-fsharp that referenced this pull request Nov 23, 2020
An FCS update would allow to enable it back again: dotnet/fsharp#10510
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
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.

3 participants