From 3b0abdb22051af9e4a32218212be2055dfc763f4 Mon Sep 17 00:00:00 2001 From: Nicolas Chevrier Date: Tue, 3 Dec 2024 13:03:53 +0100 Subject: [PATCH] support lcov files without TN Some lcov files don't have a `TN:` field. The parser currently crashes in this case. Just set `current_test_name` to empty at the beginning to handle this case. The documentation https://manpages.ubuntu.com/manpages/noble/man1/geninfo.1.html seems to say that the testname is indeed optional: ``` If available, a tracefile begins with the testname which is stored in the following format: TN: ``` --- fastcov.py | 1 + .../expected_results/combine5.expected.info | 29 +++++++++++++++++++ .../expected_results/test1.no_tn.info | 27 +++++++++++++++++ test/functional/run_all.sh | 4 +++ 4 files changed, 61 insertions(+) create mode 100644 test/functional/expected_results/combine5.expected.info create mode 100644 test/functional/expected_results/test1.no_tn.info diff --git a/fastcov.py b/fastcov.py index b8202bc..d3b38c0 100755 --- a/fastcov.py +++ b/fastcov.py @@ -792,6 +792,7 @@ def parseInfo(path): } with open(path) as f: + current_test_name = "" for line in f: if line.startswith("TN:"): current_test_name = line[3:].strip() diff --git a/test/functional/expected_results/combine5.expected.info b/test/functional/expected_results/combine5.expected.info new file mode 100644 index 0000000..9813142 --- /dev/null +++ b/test/functional/expected_results/combine5.expected.info @@ -0,0 +1,29 @@ +TN: +SF:/mnt/workspace/test/functional/cmake_project/src/source1.cpp +FN:3,_Z3foob +FNDA:1,_Z3foob +FNF:1 +FNH:1 +DA:3,1 +DA:5,1 +DA:7,1001 +DA:8,1000 +DA:10,1000 +DA:11,0 +DA:14,1 +LF:7 +LH:6 +end_of_record +TN: +SF:/mnt/workspace/test/functional/cmake_project/src/source2.cpp +FN:3,_Z3barbii +FNDA:10,_Z3barbii +FNF:1 +FNH:1 +DA:3,10 +DA:5,10 +DA:6,10 +DA:8,0 +LF:4 +LH:3 +end_of_record diff --git a/test/functional/expected_results/test1.no_tn.info b/test/functional/expected_results/test1.no_tn.info new file mode 100644 index 0000000..d92dbea --- /dev/null +++ b/test/functional/expected_results/test1.no_tn.info @@ -0,0 +1,27 @@ +SF:/mnt/workspace/test/functional/cmake_project/src/source1.cpp +FN:3,_Z3foob +FNDA:1,_Z3foob +FNF:1 +FNH:1 +DA:3,1 +DA:5,1 +DA:7,1001 +DA:8,1000 +DA:10,1000 +DA:11,0 +DA:14,1 +LF:7 +LH:6 +end_of_record +SF:/mnt/workspace/test/functional/cmake_project/src/source2.cpp +FN:3,_Z3barbii +FNDA:10,_Z3barbii +FNF:1 +FNH:1 +DA:3,10 +DA:5,10 +DA:6,10 +DA:8,0 +LF:4 +LH:3 +end_of_record diff --git a/test/functional/run_all.sh b/test/functional/run_all.sh index c992ed2..16f81f3 100755 --- a/test/functional/run_all.sh +++ b/test/functional/run_all.sh @@ -129,6 +129,10 @@ cmp combine3.actual.info ${TEST_DIR}/expected_results/combine3.expected.info coverage run -a ${TEST_DIR}/fastcov.py -C ${TEST_DIR}/expected_results/combine4a.info ${TEST_DIR}/expected_results/combine4b.info ${TEST_DIR}/expected_results/combine4c.info --lcov -o combine4.actual.info cmp combine4.actual.info ${TEST_DIR}/expected_results/combine4.expected.info +# Combine operation - Missing TN +coverage run -a ${TEST_DIR}/fastcov.py -C ${TEST_DIR}/expected_results/test1.no_tn.info --lcov -o test1.no_tn.actual.info +cmp test1.no_tn.actual.info ${TEST_DIR}/expected_results/combine5.expected.info + # Run ctest_2 ${TEST_DIR}/fastcov.py --gcov gcov-9 --zerocounters # Clear previous test coverage ctest -R ctest_2