SteveGilham / altcover

Cross-platform coverage gathering and processing tool set for dotnet/.Net Framework and Mono
MIT License
498 stars 18 forks source link

Error in Threshold - The lists had different lengths. #181

Closed marlonbraga closed 1 year ago

marlonbraga commented 1 year ago

Hello,

In PowerShell, when I add a -t=9 parameter, it throws an error

ERROR *** Collection phase failed

The lists had different lengths. list1 is 6 elements shorter than list2 Parameter name: list1

What this means?

It is a dotnet framework 4.8 project Do I something wrong?

Here is the entire command used, return and log.


./packages/altcover.8.6.45/tools/net472/AltCover.exe Runner -x='packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe' -r='ConsoleApp.Test/__Instrumented' -t=9 -w . --summary=O --dropReturnCode -- "ConsoleApp.Test/bin/ConsoleApp.Test.dll"
Beginning run...
Command line : '"packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe" ConsoleApp.Test/bin/ConsoleApp.Test.dll'
xUnit.net Console Runner v2.4.2+f110e5bee5 (64-bit Desktop .NET 4.7.2, runtime: 4.0.30319.42000)
  Discovering: ConsoleApp.Test
  Discovered:  ConsoleApp.Test
  Starting:    ConsoleApp.Test
  Finished:    ConsoleApp.Test
=== TEST EXECUTION SUMMARY ===
   ConsoleApp.Test  Total: 2, Errors: 0, Failed: 0, Skipped: 0, Time: 0,329s
Getting results...
A total of 0 visits recorded
Coverage statistics flushing took 0,03 seconds

ERROR *** Collection phase failed

The lists had different lengths.
list1 is 6 elements shorter than list2
Parameter name: list1

Details written to C:\projetos\sonarqube-csharp-test\__Instrumented\AltCover-2023-04-03--17-02-49.log

Log file

System.ArgumentException: The lists had different lengths.
list1 is 6 elements shorter than list2
Parameter name: list1
   at Microsoft.FSharp.Core.DetailedExceptions.invalidArgDifferentListLength[?](String arg1, String arg2, Int32 diff) in D:\a\_work\1\s\src\FSharp.Core\local.fs:line 26
   at AltCover.Runner.I.possibles$cont@693(ReportFormat format, FSharpList`1 covered, FSharpOption`1 matchValue, Unit unitVar) in /_//AltCover.Engine/Runner.fs:line 733
   at AltCover.Runner.I.standardSummary(DocumentType reportDocument, ReportFormat format, Int32 result) in /_//AltCover.Engine/Runner.fs:line 691
   at AltCover.Runner.J.doSummaries@1419-1.Invoke(FSharpFunc`2 summary) in /_//AltCover.Engine/Runner.fs:line 1420
   at Microsoft.FSharp.Collections.ListModule.Fold[T,TState](FSharpFunc`2 folder, TState state, FSharpList`1 list) in D:\a\_work\1\s\src\FSharp.Core\list.fs:line 295
   at AltCover.Runner.J.doSummaries(DocumentType document, ReportFormat format, Int32 result) in /_//AltCover.Engine/Runner.fs:line 1417
   at AltCover.Runner.value@1458-4.Invoke(Unit unitVar0) in /_//AltCover.Engine/Runner.fs:line 1491
   at AltCover.PathOperation.DoPathOperation[TAny](FSharpFunc`2 operation, FSharpFunc`2 handle) in /_//AltCover.Engine/Output.fs:line 21
ParamName = 
"list1"
Data = 
seq []
InnerException = 
<null>
TargetSite = 
? invalidArgDifferentListLength[?](System.String, System.String, Int32)
HelpLink = 
<null>
Source = 
"FSharp.Core"
HResult = 
-2147024809
SteveGilham commented 1 year ago

It's saying that the list of summary values to be checked against thresholds is empty, which is a case that should not arise. What does the summary output look like without the threshold value?

SteveGilham commented 1 year ago

I can see a possible mechanism : an OpenCover format report that is effectively empty, thus generating no top-level <Summary> element would result in an empty list being processed, but without any other errors about missing file or malformed data stopping the process sooner.

marlonbraga commented 1 year ago
./packages/altcover.8.6.45/tools/net472/AltCover.exe Runner -x='packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe' -r='ConsoleApp.Test/__Instrumented' -w . --summary=O -- ConsoleApp.Test/bin/ConsoleApp.Test.dll
Beginning run...
Command line : '"packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe" ConsoleApp.Test/bin/ConsoleApp.Test.dll'
xUnit.net Console Runner v2.4.2+f110e5bee5 (64-bit Desktop .NET 4.7.2, runtime: 4.0.30319.42000)
  Discovering: ConsoleApp.Test
  Discovered:  ConsoleApp.Test
  Starting:    ConsoleApp.Test
  Finished:    ConsoleApp.Test
=== TEST EXECUTION SUMMARY ===
   ConsoleApp.Test  Total: 2, Errors: 0, Failed: 0, Skipped: 0, Time: 0,300s
Getting results...
A total of 0 visits recorded
Coverage statistics flushing took 0,03 seconds
SteveGilham commented 1 year ago

That looks plausible as you've managed to record 0 visits - here's a pre-release build with a tentative fix

altcover.8.6.48-pre-g3372b36fc7.nupkg.zip

and let's see how that does.

Than see what happens when you correct the runner command line to look like

AltCover.exe Runner -x='packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe' -r='ConsoleApp.Test/__Instrumented' -t=9 -w . --summary=O --dropReturnCode -- "ConsoleApp.Test/bin/__Instrumented/ConsoleApp.Test.dll"

where you actually test the instrumented code.

marlonbraga commented 1 year ago

This time there was no exception. The coverage file was not generated The threshold has been ignored

> ./packages/altcover.8.6.48-pre-g3372b36fc7/tools/net472/AltCover.exe Runner -x='packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe' -r='ConsoleApp.Test/__Instrumented' -t=9 -w . --summary=O -- ConsoleApp.Test/bin/__Instrumented/ConsoleApp.Test.dll
Beginning run...
Command line : '"packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe" ConsoleApp.Test/bin/__Instrumented/ConsoleApp.Test.dll'
Unhandled Exception: System.ArgumentException: file not found: ConsoleApp.Test/bin/__Instrumented/ConsoleApp.Test.dll
   at Xunit.ConsoleClient.CommandLine.Parse(Predicate`1 fileExists) in /_/src/xunit.console/CommandLine.cs:line 135
   at Xunit.ConsoleClient.CommandLine..ctor(String[] args, Predicate`1 fileExists) in /_/src/xunit.console/CommandLine.cs:line 21
   at Xunit.ConsoleClient.ConsoleRunner.EntryPoint(String[] args) in /_/src/xunit.console/ConsoleRunner.cs:line 31
   at Xunit.ConsoleClient.Program.Main(String[] args) in /_/src/xunit.console/Program.cs:line 17
Getting results...
A total of 0 visits recorded
Coverage statistics flushing took 0,03 seconds
SteveGilham commented 1 year ago

With the appearance and withdrawal of issue #182, I'm not sure now whether you've now got things working or have given up.

I'll leave this issue open until next release, marked Fix Prepared, even though it only gets provoked in situations like where the code hasn't been instrumented and there is no report file, as it is a fault in the code as released.

marlonbraga commented 1 year ago

I managed to make things work using other altcover mode. Thanks Steve! 🙂

SteveGilham commented 1 year ago

Fix for original issue now released in v8.6.61