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

Code coverage extensions fails in single file application #3758

Closed
thomhurst opened this issue Sep 4, 2024 · 6 comments
Closed

Code coverage extensions fails in single file application #3758

thomhurst opened this issue Sep 4, 2024 · 6 comments

Comments

@thomhurst
Copy link
Contributor

thomhurst commented Sep 4, 2024

I'm testing/trialing my framework in AOT / SingleFile modes.

I've noticed that the code coverage extension breaks running your test suite in single file mode with the following exception:

Unhandled exception. System.Exception: Failed to get directory of 
     at 
  Microsoft.CodeCoverage.Core.Utils.ProfilersLocationProvider.GetCurrentAssemblyLo
  cation()
     at 
  Microsoft.CodeCoverage.Core.Utils.ProfilersLocationProvider.GetDefaultVanguardDi
  rectory()
     at Microsoft.CodeCoverage.Core.Utils.ProfilersLocationProvider..ctor(String 
  vsInstallPath, IFileHelper fileHelper, IDirectoryHelper directoryHelper, 
  IEnvironment environment)
     at 
  Microsoft.CodeCoverage.Core.Utils.ProfilersLocationProvider..ctor(IFileHelper 
  fileHelper, IDirectoryHelper directoryHelper, IEnvironment environment)
     at 
  Microsoft.Testing.Extensions.TestingPlatformCoverageExtensions.BuildProfilersLoc
  ationProvider(IServiceProvider serviceProvider, IEnvironment environment, 
  IFileHelper fileHelper, IDirectoryHelper directoryHelper)
     at 
  Microsoft.Testing.Extensions.TestingPlatformCoverageExtensions.BuildTestingPlatf
  ormCoverageEnvironmentVariableProvider(IServiceProvider server, 
  ITestingPlatformSessionContext sessionContext, IEnvironment environment, 
  IFileHelper fileHelper, IDirectoryHelper directoryHelper, 
  ITestingPlatformRawConfigurationProvider rawConfigurationProvider, 
  ITestingPlatformRawConfigurationProvider rawRunSettingsConfigurationProvider, 
  ITestingPlatformConfigurationHolder testingPlatformConfigurationHolder)
     at 
  Microsoft.Testing.Extensions.TestingPlatformCoverageExtensions.<>c__DisplayClass
  1_0.<InitializeExternalProcessMode>b__0(IServiceProvider s)
     at 
  Microsoft.Testing.Platform.TestHostControllers.TestHostControllersManager.BuildA
  sync(ServiceProvider serviceProvider) in 
  /_/src/Platform/Microsoft.Testing.Platform/TestHostControllers/TestHostControlle
  rsManager.cs:line 102
     at 
  Microsoft.Testing.Platform.Hosts.TestHostBuilder.BuildAsync(ApplicationLoggingSt
  ate loggingState, TestApplicationOptions testApplicationOptions, 
  IUnhandledExceptionsHandler unhandledExceptionsHandler, DateTimeOffset 
  createBuilderStart) in 
  /_/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostBuilder.cs:line 398
     at Microsoft.Testing.Platform.Builder.TestApplicationBuilder.BuildAsync() in 
  /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplicationBuilder.cs:lin
  e 110
     at TestingPlatformEntryPoint.Main(String[] args) in 
  /_/TUnit.TestProject/obj/Release/net8.0/osx-x64/TestPlatformEntryPoint.cs:line 
  14
     at TestingPlatformEntryPoint.<Main>(String[] args)

I'm also not actively using an coverage CLI flags, so just having the package installed seems to break things.

Command:

  [12:08:30 Info] ---Executing Command---
  /home/runner/work/TUnit/TUnit/TUnit.Pipeline> 
  /home/runner/work/TUnit/TUnit/TUnit.Pipeline/TESTPROJECT_SINGLEFILE/TUnit.TestPr
  oject --treenode-filter /*/*/CustomFilteringTests/*[one=*] --report-trx 
  --report-trx-filename 3a487f013fc74050ba92115e56724520.trx --timeout 5m

When I'm building as a Single File application, these are the properties I'm setting:

  <PropertyGroup Condition="'$(SingleFile)' == true">
    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>true</SelfContained>
  </PropertyGroup>

AB#2242022

@MarcoRossignoli
Copy link
Contributor

@jakubch1 I suppose this is not supported at the moment right?

@MarcoRossignoli
Copy link
Contributor

Anyway for AOT you can try this one https://github.com/microsoft/codecoverage/blob/main/samples/Algorithms/scenarios/scenario05/README.md we need to do instrumentation at build time in that case.

@thomhurst
Copy link
Contributor Author

@jakubch1 I suppose this is not supported at the moment right?

If not supported maybe it can just write a warning and not run? At the moment it completely crashes the test run, and I'm not even using any coverage flags. Just by referencing the package it breaks things.

@jakubch1
Copy link
Member

jakubch1 commented Sep 5, 2024

@thomhurst could you please provide simple project with this issue and commands you run? I was not able to reproduce.

@thomhurst
Copy link
Contributor Author

@jakubch1
Copy link
Member

Issue was fixed in version 17.12.3. If you additionally reference https://www.nuget.org/packages/Microsoft.CodeCoverage.MSBuild/17.12.3 and publish with flag: /p:SingleFileMsCodeCoverageInstrumentation="true" you can get code coverage in single file mode (not Native AOT).

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

No branches or pull requests

4 participants