coverlet icon indicating copy to clipboard operation
coverlet copied to clipboard

coverlet.exe / application coverage: exception "application does not have a console or when console input has been redirected"

Open pkrukp opened this issue 4 years ago • 8 comments

Hello,

I tried to collect application coverage (coverlet.exe) from a simple .net core 3.1 console application which reads from standard input (Console.ReadKey()). I got an exception. It looks like coverlet.exe does not provide/pass/redirect standard input to the executed program.

The error I got was:

$ coverlet.exe bin/Debug/netcoreapp3.1/console2.exe --target bin/Debug/netcoreapp3.1/console2.exe --include-test-assembly
Hello World!
Press any key to continue...
Unhandled exception. System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected. Try Console.Read.
   at System.ConsolePal.ReadKey(Boolean intercept)
   at System.Console.ReadKey()
   at console2.Program.Main(String[] args) in C:\Users\pkruk\source\repos\console2\Program.cs:line 11

Calculating coverage result...
  Generating report 'C:\Users\pkruk\source\repos\console2\coverage.json'
+----------+------+--------+--------+
| Module   | Line | Branch | Method |
+----------+------+--------+--------+
| console2 | 0%   | 100%   | 0%     |
+----------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 0%   | 100%   | 0%     |
+---------+------+--------+--------+
| Average | 0%   | 100%   | 0%     |
+---------+------+--------+--------+

Attaching the console2 project for your convenience: console2.zip

I'm using coverlet.exe 1.7.0.0

pkrukp avatar Nov 26 '20 10:11 pkrukp

Thanks for reporting this

MarcoRossignoli avatar Nov 26 '20 12:11 MarcoRossignoli

I'm not sure if this is something we want to support. My expectation for a console test runner is that it runs to completion in a non-interactive way. I don't think I'll classify it as a bug

tonerdo avatar Dec 15 '20 17:12 tonerdo

I thought it simply collects coverage from executed application...

pkrukp avatar Dec 16 '20 08:12 pkrukp

I'm not sure if this is something we want to support. My expectation for a console test runner is that it runs to completion in a non-interactive way. I don't think I'll classify it as a bug

Since next version we allow e2e test coverage, so maybe also a console app that accepts input could be a use case, what do you think @tonerdo?

MarcoRossignoli avatar Dec 16 '20 08:12 MarcoRossignoli

Do you know when that next version will be available?

pkrukp avatar Dec 16 '20 15:12 pkrukp

Since next version we allow e2e test coverage, so maybe also a console app that accepts input could be a use case

I prefer to spend more time optimizing for the common case which is usually non-interactive runs in CI servers. Even when using the integration test feature

tonerdo avatar Dec 17 '20 15:12 tonerdo

Moved to enhancement

@pkruk2 the idea is to release within end of the year.

MarcoRossignoli avatar Dec 18 '20 07:12 MarcoRossignoli

This issue is stale because it has been open for 3 months with no activity.

github-actions[bot] avatar Oct 15 '23 01:10 github-actions[bot]