Skip to content

Expecto + FSharp: Error FS0433 : A function labeled with the 'EntryPointAttribute' attribute must be the last declaration in the last file in the compilation sequence. #5148

Open
@marcingolenia

Description

@marcingolenia

Describe the bug

Hi there! Thank you for working on this. I jumped to try this stuff right away once I read the article here: https://devblogs.microsoft.com/dotnet/mtp-adoption-frameworks/. Unfortunately it looks it doesn't work. I have "'EntryPointAttribute' attribute must be the last declaration in the last file ".

Steps To Reproduce

  1. mkdir tests
  2. cd tests
  3. dotnet new console -lang "F#"
  4. Paste fsproj stuff from the article. Here it is;
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <EnableExpectoTestingPlatformIntegration>true</EnableExpectoTestingPlatformIntegration>
    <OutputType>Exe</OutputType>
    <TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="YoloDev.Expecto.TestSdk" Version="0.15.0" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Test.fs" />
  </ItemGroup>
</Project>
  1. Adjust the file name that was generated, here I have Test.fs.
  2. Run dotnet build.
  3. Experience the error Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. 'namespace SomeNamespace.SubNamespace' or 'module SomeNamespace.SomeModule'. Only the last source file of an application may omit such a declaration.
  4. It is the last source file but fine. Let's add the module. So we have sth like this:
module Tests

open Expecto

let tests =
    testList "Calculator Tests" [
        test "Add function returns sum" {
            let result = 4
            Expect.equal result 3 "Expected sum to be 3"
        }
    ]

[<EntryPoint>]
let main argv =
    runTestsWithArgs defaultConfig argv tests
  1. Experience the The value or constructor 'runTestsWithArgs' is not defined. Maybe you want one of the following: runTestsWithCLIArgs runTestsWithCLIArgsAndCancel error.
  2. change
    runTestsWithArgs defaultConfig argv tests

to

    runTestsWithCLIArgs [] argv tests
  1. Experience A function labeled with the 'EntryPointAttribute' attribute must be the last declaration in the last file in the compilation sequence.

Expected behavior

It works.

Actual behavior

Errors.

Additional context

I am using Ubuntu. Also If you will remove EnableExpectoTestingPlatformIntegration attribute then it compiles. When I type dotnet run, it actually runs the tests. All in all Rider doesn't detect the tests, so the test explorer is empty.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions