eriwen / lcov-to-cobertura-xml

Converts lcov output to Cobertura-compatible XML for CI
https://eriwen.github.io/lcov-to-cobertura-xml/
Apache License 2.0
187 stars 73 forks source link

fix ValueError #35

Closed epi052 closed 2 years ago

epi052 commented 3 years ago

when an entry such as

['FN', '108,tokio::runtime::task::harness::Harness<T,S>::try_read_output']                                                     

is encountered and processed using line_parts[-1].strip().split(','), an exception is thrown:

Traceback (most recent call last):
  File "lcov_cobertura.py", line 418, in <module>                                                                                                                                                                                                             
    main()                       
  File "lcov_cobertura.py", line 411, in main                                                                                                                                                                                                                 
    cobertura_xml = lcov_cobertura.convert()
  File "lcov_cobertura.py", line 87, in convert                                                                                                                                                                                                               
    coverage_data = self.parse() 
  File "lcov_cobertura.py", line 203, in parse                                                                                                                                                                                                                
    (function_hits, function_name) = line_parts[-1].strip().split(',')
ValueError: too many values to unpack (expected 2)                                                                                                                                                                                                            

Added the maxsplit option to two split calls that solved the problem for my project.

robertgroh commented 3 years ago

I also have this issue with an lcov file generated by grcov of a rust program.

The following extracted lcov lines contain multiple occurence of the comma , character:

FN:132,<std::sync::mutex::Mutex<std::collections::hash::map::HashMap<alloc::string::String, gecse_rust::dispatcher::GECSEAppDefinition>> as gecse_rust::workflow_controller::TryInsert<alloc::string::String, gecse_rust::dispatcher::GECSEAppDefinition>>::try_insert::<<gecse_rust::workflow_controller::WorkflowController>::register_workflow::{closure#0}>

FNDA:1,<std::sync::mutex::Mutex<std::collections::hash::map::HashMap<alloc::string::String, gecse_rust::dispatcher::GECSEAppDefinition>> as gecse_rust::workflow_controller::TryInsert<alloc::string::String, gecse_rust::dispatcher::GECSEAppDefinition>>::try_insert::<<gecse_rust::workflow_controller::WorkflowController>::register_workflow::{closure#0}>

EDIT: This PR fixes my issue and I can use the created cobertura xml file for the Gitlab Test Coverage Visualization :+1: . Thank you, @epi052. :bow:

vipera commented 2 years ago

I just ran into the exact same problem (grcov-generated lcov file with extra commas due to Rust generics), this patch fixed it for me.

It would be cleaner to use a released version, though - any chance you might look at this and merge it, @eriwen? Thanks.

eriwen commented 2 years ago

Fixed by 2026dfa

Thanks all for the examples and the fix.