coverlet-coverage / coverlet

Cross platform code coverage for .NET
MIT License
2.98k stars 385 forks source link

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

Closed pkrukp closed 2 months ago

pkrukp commented 3 years ago

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

MarcoRossignoli commented 3 years ago

Thanks for reporting this

tonerdo commented 3 years ago

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

pkrukp commented 3 years ago

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

MarcoRossignoli commented 3 years ago

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?

pkrukp commented 3 years ago

Do you know when that next version will be available?

tonerdo commented 3 years ago

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

MarcoRossignoli commented 3 years ago

Moved to enhancement

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

github-actions[bot] commented 11 months ago

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

github-actions[bot] commented 2 months ago

This issue was closed because it has been inactive for 9 months since being marked as stale.