Kcov 报告 100% 的 Rust 库,即使一些方法没有被覆盖
Kcov is reporting 100% for Rust lib even though some methods are not covered
我正在尝试将代码覆盖率添加到我的 Rust 库中。它报告说它已被 100% 覆盖,但是当我查看报告时,很多行都没有计算在内:https://codecov.io/gh/JelteF/defaultmap/src/c878e108c61f270718c909e1500c4c2e865a33d1/src/lib.rs#L93...106
这是什么原因,是否可以解决这个问题?我已经尝试按照此答案中的建议将 RUSTFLAGS 设置为“-C link-dead-code”:
然而,这并没有帮助。
这是一个已知问题(https://github.com/rust-lang/rust/issues/39293), with no solutions implemented yet. Generics in Rust are similar to templates in C++,如果您不使用通用函数,则根本不会生成任何代码。实际上这些函数不存在:
$ nm target/debug/defaultmap-2fd0c3085042f647 | grep DefaultHashMap | cargo demangle
000000000002c350 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::Index<KB>>::index::h14fb5e24128b7e47
000000000002c390 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::Index<KB>>::index::h5c00e602e45f6925
000000000002c3d0 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::Index<KB>>::index::hc5dfb7b3478d945a
000000000002c420 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::IndexMut<K>>::index_mut::h8b298bf16464a070
000000000002c470 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::IndexMut<K>>::index_mut::hcc509def35f89759
000000000002bfc0 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get::h6a0f4cb5c61c67e8
000000000002c060 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get::ha5fdb528b5dd94a5
000000000002c110 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get::hc1a5643986209ba6
000000000002c1b0 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get_mut::h14f0ded6ba3206f3
000000000002c2a0 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get_mut::h6ea36d917e778099
000000000002eaf0 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::fmt::Debug>::fmt::h2cefa624bd18fcfe
000000000002e9e0 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::default::Default>::default::h0b736edcd6ac228a
000000000002ea60 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::default::Default>::default::hd09b7abe1e63b94f
我认为,目前唯一可行的解决方案是手动检查覆盖率报告,并为忽略的功能添加缺失的测试。
我正在尝试将代码覆盖率添加到我的 Rust 库中。它报告说它已被 100% 覆盖,但是当我查看报告时,很多行都没有计算在内:https://codecov.io/gh/JelteF/defaultmap/src/c878e108c61f270718c909e1500c4c2e865a33d1/src/lib.rs#L93...106
这是什么原因,是否可以解决这个问题?我已经尝试按照此答案中的建议将 RUSTFLAGS 设置为“-C link-dead-code”:
这是一个已知问题(https://github.com/rust-lang/rust/issues/39293), with no solutions implemented yet. Generics in Rust are similar to templates in C++,如果您不使用通用函数,则根本不会生成任何代码。实际上这些函数不存在:
$ nm target/debug/defaultmap-2fd0c3085042f647 | grep DefaultHashMap | cargo demangle
000000000002c350 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::Index<KB>>::index::h14fb5e24128b7e47
000000000002c390 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::Index<KB>>::index::h5c00e602e45f6925
000000000002c3d0 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::Index<KB>>::index::hc5dfb7b3478d945a
000000000002c420 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::IndexMut<K>>::index_mut::h8b298bf16464a070
000000000002c470 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::ops::IndexMut<K>>::index_mut::hcc509def35f89759
000000000002bfc0 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get::h6a0f4cb5c61c67e8
000000000002c060 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get::ha5fdb528b5dd94a5
000000000002c110 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get::hc1a5643986209ba6
000000000002c1b0 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get_mut::h14f0ded6ba3206f3
000000000002c2a0 t <defaultmap::hashmap::DefaultHashMap<K, V>>::get_mut::h6ea36d917e778099
000000000002eaf0 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::fmt::Debug>::fmt::h2cefa624bd18fcfe
000000000002e9e0 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::default::Default>::default::h0b736edcd6ac228a
000000000002ea60 t <defaultmap::hashmap::DefaultHashMap<K, V> as core::default::Default>::default::hd09b7abe1e63b94f
我认为,目前唯一可行的解决方案是手动检查覆盖率报告,并为忽略的功能添加缺失的测试。